ReadCmdline.c 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328
  1. /*
  2. * Main.c
  3. *
  4. * Created on: 2019年8月6日
  5. * Author: 7564
  6. */
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/socket.h>
  14. #include <sys/ipc.h>
  15. #include <sys/shm.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/wireless.h>
  19. #include <arpa/inet.h>
  20. #include <netinet/in.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h> /*標準輸入輸出定義*/
  24. #include <stdlib.h> /*標準函數庫定義*/
  25. #include <unistd.h> /*Unix 標準函數定義*/
  26. #include <fcntl.h> /*檔控制定義*/
  27. #include <termios.h> /*PPSIX 終端控制定義*/
  28. #include <errno.h> /*錯誤號定義*/
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33. #include <ifaddrs.h>
  34. #include <math.h>
  35. #include <stdbool.h>
  36. #include "../../define.h"
  37. #include "Config.h"
  38. #include "Module_EvComm.h"
  39. #include "Common.h"
  40. typedef unsigned char byte;
  41. #define NO_DEFINE 255
  42. #define OPTION_CNT 3
  43. #define STR_OPTION '-'
  44. #define OPTION_REFLASH 0x00000001
  45. #define OPTION_LOOP 0x00000002
  46. #define OPTION_TIME 0x00000004
  47. #define MAX_SUB_CMD_QUANTITY 16
  48. #define MAX_SUB_CMD_LENGTH 128
  49. #define STR_OPT_REFLASH 'f'
  50. #define STR_OPT_LOOP 'l'
  51. #define STR_OPT_TIME 't'
  52. #define TTY_PATH "/dev/tty"
  53. #define STTY_US "stty raw -echo -F "
  54. #define STTY_DEF "stty -raw echo -F "
  55. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  56. struct StatusCodeData *ShmStatusCodeData;
  57. struct PrimaryMcuData *ShmPrimaryMcuData;
  58. struct CHAdeMOData *ShmCHAdeMOData;
  59. struct CcsData *ShmCcsData;
  60. struct GBTData *ShmGBTData;
  61. struct FanModuleData *ShmFanModuleData;
  62. struct RelayModuleData *ShmRelayModuleData;
  63. struct LedModuleData *ShmLedModuleData;
  64. struct PsuData *ShmPsuData;
  65. ChargerInfoData *ShmChargerInfo;
  66. PsuPositionInfoData *ShmPsuPosition;
  67. PsuGroupingInfoData *ShmPsuGrouping;
  68. struct OCPP16Data *ShmOCPP16Data;
  69. struct OCPP20Data *ShmOCPP20Data;
  70. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  71. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  72. char MultiSubCmd[MAX_SUB_CMD_QUANTITY][MAX_SUB_CMD_LENGTH];
  73. int totalSubCnt = 0;
  74. char *msg = "state : get gun state (index) \n"
  75. "card : scanning card (x) : \n"
  76. "gun : get gun plugit state (index) \n"
  77. "lock : get gun locked state (index) \n"
  78. "self : self test state (x) \n"
  79. "ver : ver of board (407 or index or rb or fan) \n"
  80. "ac : get ac relay state (x) \n"
  81. "gunchg: set gun start charging \n"
  82. "gunstp: set gun stop charging \n"
  83. "gunext: extend gun capability \n";
  84. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  85. {
  86. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  87. {
  88. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  89. {
  90. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  91. return true;
  92. }
  93. }
  94. for (byte index = 0; index < CCS_QUANTITY; index++)
  95. {
  96. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  97. {
  98. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  99. return true;
  100. }
  101. }
  102. for (byte index = 0; index < GB_QUANTITY; index++)
  103. {
  104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  105. {
  106. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  107. return true;
  108. }
  109. }
  110. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  111. {
  112. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  113. return true;
  114. }
  115. return false;
  116. }
  117. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  118. {
  119. if (target < AC_QUANTITY)
  120. {
  121. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  122. return true;
  123. }
  124. return false;
  125. }
  126. int InitShareMemory()
  127. {
  128. int result = PASS;
  129. int MeterSMId;
  130. //initial ShmSysConfigAndInfo
  131. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  132. {
  133. result = FAIL;
  134. }
  135. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  136. {
  137. result = FAIL;
  138. }
  139. else
  140. {}
  141. //initial ShmStatusCodeData
  142. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  143. {
  144. result = FAIL;
  145. }
  146. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  147. {
  148. result = FAIL;
  149. }
  150. else
  151. {}
  152. if (CHAdeMO_QUANTITY > 0) {
  153. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  154. IPC_CREAT | 0777)) < 0) {
  155. result = FAIL;
  156. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  157. == (void *) -1) {
  158. result = FAIL;
  159. } else {
  160. }
  161. }
  162. if (CCS_QUANTITY > 0) {
  163. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  164. IPC_CREAT | 0777)) < 0) {
  165. result = FAIL;
  166. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  167. result = FAIL;
  168. } else {
  169. }
  170. }
  171. if (GB_QUANTITY > 0) {
  172. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  173. IPC_CREAT | 0777)) < 0) {
  174. return 0;
  175. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  176. return 0;
  177. }
  178. memset(ShmGBTData, 0, sizeof(struct GBTData));
  179. }
  180. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  181. {
  182. result = FAIL;
  183. }
  184. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  185. {
  186. result = FAIL;
  187. }
  188. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  189. {
  190. result = FAIL;
  191. }
  192. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  193. {
  194. result = FAIL;
  195. }
  196. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  197. {
  198. result = FAIL;
  199. }
  200. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  201. {
  202. result = FAIL;
  203. }
  204. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  205. {
  206. result = FAIL;
  207. }
  208. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  209. {
  210. result = FAIL;
  211. }
  212. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  213. {
  214. result = FAIL;
  215. }
  216. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  217. {
  218. result = FAIL;
  219. }
  220. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  221. {
  222. result = FAIL;
  223. }
  224. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  225. {
  226. result = FAIL;
  227. }
  228. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  229. {
  230. result = FAIL;
  231. }
  232. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  233. {
  234. result = FAIL;
  235. }
  236. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  237. {
  238. result = FAIL;
  239. }
  240. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  241. {
  242. result = FAIL;
  243. }
  244. if(result == PASS)
  245. {
  246. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  247. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  248. }
  249. return result;
  250. }
  251. void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
  252. {
  253. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  254. {
  255. sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  256. return;
  257. }
  258. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  259. {
  260. strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
  261. return;
  262. }
  263. sprintf(transactionId, "%d", 0);
  264. }
  265. static void get_char(char *word)
  266. {
  267. fd_set rfds;
  268. struct timeval tv;
  269. FD_ZERO(&rfds);
  270. FD_SET(0, &rfds);
  271. tv.tv_sec = 0;
  272. tv.tv_usec = 10; //wait input timout time
  273. //if input
  274. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  275. {
  276. fgets(word, 128, stdin);
  277. }
  278. }
  279. // return command length
  280. int ParsingCmd(char *inputString, char *outputString)
  281. {
  282. bool valid = false, done = false;
  283. int len = 0, start = 0;
  284. for(int i = 0; i < strlen(inputString); i++)
  285. {
  286. if(!valid)
  287. {
  288. if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
  289. {
  290. valid = true;
  291. start = i;
  292. }
  293. }
  294. else
  295. {
  296. if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= MAX_SUB_CMD_LENGTH)
  297. {
  298. done = true;
  299. break;
  300. }
  301. }
  302. len = (valid && !done) ? len + 1 : len;
  303. }
  304. if(valid)
  305. {
  306. memcpy(outputString, &inputString[start], len);
  307. outputString[len] = '\0';
  308. }
  309. return len;
  310. }
  311. bool IsOption(char *strCmd, unsigned int *opt)
  312. {
  313. int len = 0;
  314. char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_TIME};
  315. unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_TIME};
  316. len = strlen(strCmd);
  317. if(len == 2)
  318. {
  319. if(strCmd[0] == STR_OPTION)
  320. {
  321. for(int i = 0; i < OPTION_CNT; i++)
  322. {
  323. if(strCmd[1] == str_opt[i])
  324. {
  325. *opt |= opt_value[i];
  326. return true;
  327. }
  328. }
  329. }
  330. }
  331. return false;
  332. }
  333. // inputCmdString: console input string
  334. // outputCmdString: input string parsed
  335. // return command quantity
  336. int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
  337. {
  338. int len = 0, cnt = 0, start = 0;
  339. int cmdLen = 0, totalLen = 0;
  340. len = strlen(inputCmdString);
  341. *opt = 0;
  342. if(len > 0)
  343. {
  344. while(start < len)
  345. {
  346. if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0' &&
  347. inputCmdString[start] != '\r' && inputCmdString[start] != '\n')
  348. {
  349. cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
  350. if(cmdLen > 0)
  351. {
  352. //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
  353. if(!IsOption(&outputCmdString[totalLen], opt))
  354. {
  355. outputCmdString[totalLen + cmdLen] = ' ';
  356. cnt++;
  357. totalLen += cmdLen + 1;
  358. }
  359. start += cmdLen;
  360. }
  361. }
  362. else
  363. {
  364. start++;
  365. }
  366. }
  367. outputCmdString[totalLen - 1] = '\0';
  368. }
  369. return cnt;
  370. }
  371. int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
  372. {
  373. int len = 0, totalLen = 0;
  374. int quantity = 0;
  375. strcpy(mainCmd, "");
  376. strcpy(subCmd, "");
  377. totalLen = strlen(normalCmd);
  378. if(totalLen > 0)
  379. {
  380. len = ParsingCmd(normalCmd, mainCmd);
  381. //printf("Find MainCmd: %s\r\n", mainCmd);
  382. quantity = len > 0 ? (quantity + 1) : quantity;
  383. if(len > 0 && totalLen > len)
  384. {
  385. strcpy(subCmd, &normalCmd[len + 1]);
  386. //printf("Find SubCmd: %s\r\n", subCmd);
  387. len = strlen(subCmd);
  388. quantity = len > 0 ? (quantity + 1) : quantity;
  389. }
  390. }
  391. return quantity;
  392. }
  393. int GetCommandSring(char *outputCmdString)
  394. {
  395. int len = 0, cnt = 0;
  396. int cmdLen = 0, totalLen = 0;
  397. char word[128];
  398. memset(word, 0x00, sizeof(word));
  399. get_char(word);
  400. len = strlen(word);
  401. if(len == 0)
  402. {
  403. return -1;
  404. }
  405. int start = 0;
  406. while(start < len - 1)
  407. {
  408. if(word[start] != ' ' && word[start] != '\0')
  409. {
  410. cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
  411. char newCmd[MAX_SUB_CMD_LENGTH];
  412. memset(newCmd, 0x00, MAX_SUB_CMD_LENGTH);
  413. memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
  414. cnt = cmdLen > 0 ? cnt + 1 : cnt;
  415. totalLen += cmdLen + 1;
  416. start += cmdLen;
  417. }
  418. else
  419. {
  420. start++;
  421. }
  422. }
  423. return cnt;
  424. }
  425. bool IsLoopStopCmd(void)
  426. {
  427. bool stop = false;
  428. int cnt = 0;
  429. char cmd[256];
  430. char totalCmd[256];
  431. memset(cmd, 0x00, 256);
  432. memset(totalCmd, 0x00, 256);
  433. cnt = GetCommandSring(totalCmd);
  434. if(cnt > 0)
  435. {
  436. strcpy(&cmd[0], totalCmd);
  437. if(strcmp(&cmd[0], "c") == 0)
  438. {
  439. stop = true;
  440. }
  441. }
  442. return stop;
  443. }
  444. void ConsoleReflash(int groupCnt, int lineCnt)
  445. {
  446. for(int i = 0; i < groupCnt; i++)
  447. {
  448. for(int i = 0; i < lineCnt; i++)
  449. {
  450. printf("\033[1A");
  451. printf("\033[K");
  452. }
  453. }
  454. printf("\r");
  455. }
  456. int GetSubCommand(char *inputCmd)
  457. {
  458. unsigned int paraOpt = 0;
  459. int loopLimit = 0;
  460. char normalString[128];
  461. totalSubCnt = InputStringNormalize(inputCmd, normalString, &paraOpt);
  462. if(totalSubCnt > MAX_SUB_CMD_QUANTITY)
  463. {
  464. totalSubCnt = MAX_SUB_CMD_QUANTITY;
  465. }
  466. if(totalSubCnt > 0)
  467. {
  468. loopLimit = totalSubCnt > 1 ? totalSubCnt - 1 : 1;
  469. for(int i = 0; i < loopLimit; i++)
  470. {
  471. memset(&MultiSubCmd[i][0], 0x00, MAX_SUB_CMD_LENGTH);
  472. memset(&MultiSubCmd[i + 1][0], 0x00, MAX_SUB_CMD_LENGTH);
  473. MainAndSubCommandParsing(normalString, &MultiSubCmd[i][0], &MultiSubCmd[i + 1][0]);
  474. strcpy(normalString, &MultiSubCmd[i + 1][0]);
  475. }
  476. }
  477. return totalSubCnt;
  478. }
  479. void RunStatusProc(char *v1, char *v2)
  480. {
  481. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  482. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  483. if (strcmp(v1, "ac") == 0)
  484. {
  485. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  486. {
  487. printf("FindChargingInfoData (AC) false \n");
  488. }
  489. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  490. return;
  491. }
  492. int _index = atoi(v1);
  493. if (_index <= 3)
  494. {
  495. if (!FindChargingInfoData(_index, &_chargingData[0]))
  496. {
  497. printf ("FindChargingInfoData error\n");
  498. return;
  499. }
  500. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  501. {
  502. // get
  503. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  504. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  505. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  506. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  507. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  508. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  509. }
  510. else
  511. {
  512. // set
  513. _chargingData[_index]->SystemStatus = atoi(v2);
  514. }
  515. }
  516. else
  517. {
  518. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  519. {
  520. printf("FindChargingInfoData (AC) false \n");
  521. }
  522. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  523. {
  524. // get
  525. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  526. }
  527. else
  528. {
  529. // set
  530. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  531. }
  532. }
  533. }
  534. void RunCardProc(char *v1, char *v2)
  535. {
  536. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  537. {
  538. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  539. {
  540. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  541. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  542. }
  543. else
  544. {
  545. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  546. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  547. }
  548. }
  549. else
  550. {
  551. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  552. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  553. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  554. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  555. }
  556. }
  557. void RunGunPlugitProc(char *v1, char *v2)
  558. {
  559. if (strcmp(v1, "ac") == 0)
  560. {
  561. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  562. {
  563. printf("FindChargingInfoData (AC) false \n");
  564. }
  565. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  566. {
  567. // get
  568. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  569. }
  570. else
  571. {
  572. // set
  573. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  574. }
  575. return;
  576. }
  577. int _index = atoi(v1);
  578. if (!FindChargingInfoData(_index, &_chargingData[0]))
  579. {
  580. printf("FindChargingInfoData error\n");
  581. return;
  582. }
  583. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  584. {
  585. // get
  586. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  587. }
  588. else
  589. {
  590. // set
  591. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  592. }
  593. }
  594. void GetGunLockStatusProc(char *v1, char *v2)
  595. {
  596. int _index = atoi(v1);
  597. if (!FindChargingInfoData(_index, &_chargingData[0]))
  598. {
  599. printf("FindChargingInfoData error\n");
  600. return;
  601. }
  602. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  603. {
  604. _chargingData[_index]->GunLocked = atoi(v2);
  605. }
  606. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  607. }
  608. void SetSystemIDProc()
  609. {
  610. char *systemId = "Alston_Test";
  611. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  612. }
  613. void RunSelfProc()
  614. {
  615. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  616. }
  617. void ShowFwVer(void)
  618. {
  619. printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  620. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  621. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
  622. printf("\r\n Csu Kernel: ");
  623. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  624. {
  625. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  626. {
  627. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  628. }
  629. }
  630. printf("\r\n Csu Root Fs: %s [%s]", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ShmChargerInfo->SysMisc.SubVersion);
  631. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  632. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  633. printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  634. printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  635. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  636. {
  637. printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  638. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  639. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  640. {
  641. printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
  642. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
  643. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
  644. printf("\r\n Csu Kernel: ");
  645. for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
  646. {
  647. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
  648. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
  649. {
  650. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
  651. }
  652. }
  653. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
  654. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
  655. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
  656. printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
  657. printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
  658. printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
  659. printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
  660. }
  661. }
  662. printf("\r\n\r\n");
  663. }
  664. void GetFwVerProc(char *v1)
  665. {
  666. if (strcmp(v1, "407") == 0)
  667. {
  668. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  669. }
  670. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  671. {
  672. int _index = atoi(v1);
  673. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  674. {
  675. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  676. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  677. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  678. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  679. {
  680. if(ParentIndex == 0)
  681. {
  682. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  683. }
  684. else
  685. {
  686. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  687. }
  688. }
  689. }
  690. else
  691. {
  692. printf("Gun %d is disable\r\n", _index);
  693. }
  694. }
  695. else if (strcmp(v1, "rb") == 0)
  696. {
  697. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  698. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  699. }
  700. else if (strcmp(v1, "fan") == 0)
  701. {
  702. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  703. }
  704. else if (strcmp(v1, "dc") == 0)
  705. {
  706. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  707. }
  708. else if (strcmp(v1, "led") == 0)
  709. {
  710. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  711. }
  712. }
  713. void CreateOneError(char *v1)
  714. {
  715. int value = atoi(v1);
  716. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  717. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  718. }
  719. void GetAuthorizeFlag(char *v1)
  720. {
  721. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  722. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  723. else
  724. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  725. }
  726. void GetOrClearId(char *v1)
  727. {
  728. int _index = atoi(v1);
  729. if (!FindChargingInfoData(_index, &_chargingData[0]))
  730. {
  731. printf("FindChargingInfoData error\n");
  732. return;
  733. }
  734. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  735. }
  736. void FwUpdateFlagProc()
  737. {
  738. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  739. }
  740. void CheckAcStatus(char *v1)
  741. {
  742. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  743. {
  744. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  745. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  746. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  747. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  748. }
  749. else
  750. {
  751. if(system("pidof -s main > /dev/null") != 0)
  752. {
  753. if(strcmp(v1, "0") == 0)
  754. {
  755. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  756. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  757. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  758. printf("Set AC Contactor Off\r\n");
  759. }
  760. else
  761. {
  762. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  763. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  764. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  765. printf("Set AC Contactor On\r\n");
  766. }
  767. }
  768. else
  769. {
  770. printf("main task is running\r\n");
  771. }
  772. }
  773. }
  774. void SetCableChkStatus(char *v1, char *v2)
  775. {
  776. int _index = atoi(v1);
  777. if (!FindChargingInfoData(_index, &_chargingData[0]))
  778. {
  779. printf ("FindChargingInfoData error\n");
  780. return;
  781. }
  782. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  783. }
  784. void SetPowerValue(char *v1, char *v2)
  785. {
  786. int _index = atoi(v1);
  787. float _Current = atof(v2);
  788. // 盲沖的時候才允許使用~
  789. if (_chargingData[_index]->Type != 9)
  790. return;
  791. if (!FindChargingInfoData(_index, &_chargingData[0]))
  792. {
  793. printf ("FindChargingInfoData error\n");
  794. return;
  795. }
  796. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  797. }
  798. void GetSystemInfo(void)
  799. {
  800. printf ("Power Cabinet\r\n");
  801. printf (" -System ID: [%s]\r\n", (char *)&ShmSysConfigAndInfo->SysConfig.SystemId);
  802. printf (" -ModelName: [%s], SerialNumber: [%s]\r\n",
  803. (char *)&ShmSysConfigAndInfo->SysConfig.ModelName,
  804. (char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber);
  805. printf (" -CSURootFs: %s [%s]\r\n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, ShmChargerInfo->SysMisc.SubVersion);
  806. }
  807. bool SetModelName(char *modelName);
  808. void ModelNameCmd(char *inputCmd, unsigned int opt)
  809. {
  810. int totalCnt = 0, maxPara = 0;
  811. maxPara = 2;
  812. totalCnt = GetSubCommand(inputCmd);
  813. printf("\r\n");
  814. if(totalCnt == 0)
  815. {
  816. GetSystemInfo();
  817. printf("\r\n");
  818. return;
  819. }
  820. if(totalCnt != maxPara || strcmp(&MultiSubCmd[0][0], "set") != EQUAL)
  821. {
  822. printf("Input cmd fail ------ model [set] [model name]\r\n\r\n");
  823. return;
  824. }
  825. if(SetModelName(&MultiSubCmd[0][0]))
  826. {
  827. printf("\r\n");
  828. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  829. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  830. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  831. }
  832. }
  833. bool SetSerialNumber(char *serialNumber);
  834. void SerialNumberCmd(char *inputCmd, unsigned int opt)
  835. {
  836. int totalCnt = 0, maxPara = 0;
  837. maxPara = 2;
  838. totalCnt = GetSubCommand(inputCmd);
  839. printf("\r\n");
  840. if(totalCnt != maxPara)
  841. {
  842. printf("Input cmd fail ------ model [set] [serial number]\r\n\r\n");
  843. return;
  844. }
  845. if(SetSerialNumber(&MultiSubCmd[1][0]))
  846. {
  847. printf("\r\n");
  848. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  849. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  850. }
  851. }
  852. void SetFanSpeed(char *v1)
  853. {
  854. int speed = atoi(v1);
  855. ShmFanModuleData->TestFanSpeed = speed;
  856. }
  857. void GetFanSpeed()
  858. {
  859. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  860. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  861. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  862. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  863. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  864. }
  865. void SetDebugMode(char *v1)
  866. {
  867. int mode = atoi(v1);
  868. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  869. }
  870. void SetGFDMode(char *v1)
  871. {
  872. int mode = atoi(v1);
  873. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  874. }
  875. // PSU 0 PSU 1 PSU 2 ...
  876. // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
  877. // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
  878. void GetTemperature(char *inputCmd, unsigned int opt)
  879. {
  880. bool keepRun = false;
  881. bool reflash = false;
  882. int time = 0;
  883. struct timespec _Loop_time;
  884. char strGunTemp[16], strChillerTemp[16];
  885. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  886. {
  887. keepRun = true;
  888. }
  889. printf("\r\n");
  890. printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
  891. printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
  892. do
  893. {
  894. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  895. if(time >= 1000)
  896. {
  897. if(reflash)
  898. {
  899. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  900. }
  901. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  902. {
  903. sprintf(strGunTemp, "N/A");
  904. sprintf(strChillerTemp, "N/A");
  905. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  906. {
  907. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  908. }
  909. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  910. {
  911. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  912. }
  913. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  914. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  915. {
  916. printf(" %3d/%3d/%3d",
  917. ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
  918. ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
  919. ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
  920. }
  921. printf("\r\n");
  922. }
  923. GetClockTime(&_Loop_time);
  924. if((opt & OPTION_REFLASH) > 0)
  925. {
  926. reflash = true;
  927. }
  928. }
  929. if(keepRun)
  930. {
  931. keepRun = IsLoopStopCmd() ? false : true;
  932. usleep(10000);
  933. }
  934. }while(keepRun);
  935. }
  936. void GetInputVol(char *inputCmd, unsigned int opt)
  937. {
  938. bool keepRun = false;
  939. bool reflash = false;
  940. int time = 0;
  941. struct timespec _Loop_time;
  942. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  943. {
  944. keepRun = true;
  945. }
  946. printf("\r\n");
  947. do
  948. {
  949. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  950. if(time >= 1000)
  951. {
  952. if(reflash)
  953. {
  954. ConsoleReflash(1, 1);
  955. }
  956. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  957. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  958. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  959. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  960. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  961. GetClockTime(&_Loop_time);
  962. if((opt & OPTION_REFLASH) > 0)
  963. {
  964. reflash = true;
  965. }
  966. }
  967. if(keepRun)
  968. {
  969. keepRun = IsLoopStopCmd() ? false : true;
  970. usleep(10000);
  971. }
  972. }while(keepRun);
  973. printf("\r\n");
  974. }
  975. void GetPsuInformation(char *v1, char *v2, char *v3)
  976. {
  977. printf("**********************AC Contact needed*************************\n");
  978. if(strcmp(v1, "count") == 0)
  979. {
  980. for (int i = 0; i < 4; i++)
  981. {
  982. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  983. }
  984. }
  985. else if(strcmp(v1, "ver") == 0)
  986. {
  987. for (int i = 0; i < ShmPsuData->SystemInitialPsuQuantity; i++)
  988. {
  989. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  990. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  991. }
  992. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  993. {
  994. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  995. {
  996. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  997. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  998. }
  999. }
  1000. }
  1001. else if(strcmp(v1, "cap") == 0)
  1002. {
  1003. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1004. {
  1005. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  1006. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  1007. }
  1008. }
  1009. else if(strcmp(v1, "input") == 0)
  1010. {
  1011. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1012. {
  1013. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  1014. {
  1015. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  1016. i, count,
  1017. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  1018. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  1019. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  1020. }
  1021. }
  1022. }
  1023. else if (strcmp(v1, "output") == 0)
  1024. {
  1025. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  1026. {
  1027. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  1028. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  1029. }
  1030. }
  1031. else if (strcmp(v1, "test") == 0)
  1032. {
  1033. int mode = atoi(v2);
  1034. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  1035. {
  1036. ShmPsuData->Work_Step = mode;
  1037. }
  1038. }
  1039. else if (strcmp(v1, "out") == 0)
  1040. {
  1041. float vol = atof(v2);
  1042. float cur = atof(v3);
  1043. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  1044. {
  1045. if (!FindChargingInfoData(0, &_chargingData[0]))
  1046. {
  1047. printf ("FindChargingInfoData error\n");
  1048. return;
  1049. }
  1050. _chargingData[0]->EvBatterytargetVoltage = vol;
  1051. _chargingData[0]->EvBatterytargetCurrent = cur;
  1052. }
  1053. }
  1054. printf("*************************************************\n");
  1055. }
  1056. void GetConnectorCapInfo(char *v1)
  1057. {
  1058. int _GunIndex = atoi(v1);
  1059. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1060. {
  1061. printf ("FindChargingInfoData error\n");
  1062. return;
  1063. }
  1064. printf ("Charger Max Current = %d, Max Power = %d \n",
  1065. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  1066. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  1067. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  1068. _GunIndex,
  1069. _chargingData[_GunIndex]->RealMaxPower,
  1070. _chargingData[_GunIndex]->RealMaxVoltage,
  1071. _chargingData[_GunIndex]->RealMaxCurrent);
  1072. }
  1073. void SetWiringInfo(char *v1, char *v2)
  1074. {
  1075. int dispenser = atoi(v1);
  1076. int connector = atoi(v2);
  1077. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1078. {
  1079. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1080. {
  1081. printf("\r\n");
  1082. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1083. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1084. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1085. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1086. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1087. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1088. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1089. }
  1090. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1091. {
  1092. printf("\r\n");
  1093. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1094. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1095. int quantity = 0;
  1096. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1097. {
  1098. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1099. }
  1100. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1101. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1102. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1103. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1104. }
  1105. }
  1106. }
  1107. void ShowWiringInfo(void)
  1108. {
  1109. printf("\r\n");
  1110. printf("********** Wiring Info **********\r\n");
  1111. printf("Dispenser = %d, Connector = %d\r\n",
  1112. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1113. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1114. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1115. {
  1116. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1117. {
  1118. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1119. }
  1120. }
  1121. printf("\r\n");
  1122. }
  1123. void CleanWiringInfo(void)
  1124. {
  1125. printf("\r\n");
  1126. printf("******* Clean Wiring Info *******\r\n");
  1127. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1128. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  1129. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  1130. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = true;
  1131. printf("\r\n");
  1132. }
  1133. void SetSystemSoftRest(void)
  1134. {
  1135. printf("\r\n");
  1136. printf("********* Set Soft Reset ********\r\n\r\n");
  1137. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1138. }
  1139. void SetSystemHardReboot(void)
  1140. {
  1141. printf("\r\n");
  1142. printf("******** Set Hard Reboot ********\r\n\r\n");
  1143. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1144. }
  1145. void SetGroupRole(byte group, byte role)
  1146. {
  1147. if(group < GENERAL_GUN_QUANTITY)
  1148. {
  1149. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1150. {
  1151. //printf("\r\nSet Group %d Role = %d", group, role);
  1152. }
  1153. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1154. }
  1155. }
  1156. void SetGroupToIdle(byte group)
  1157. {
  1158. if(group < GENERAL_GUN_QUANTITY)
  1159. {
  1160. SetGroupRole(group, _GROLE_IDLE);
  1161. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1162. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1163. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1164. //printf("\r\n Reset Group %02X To Idle", group);
  1165. }
  1166. }
  1167. void SetGroupToMaster(byte group)
  1168. {
  1169. if(group < GENERAL_GUN_QUANTITY)
  1170. {
  1171. SetGroupRole(group, _GROLE_MASTER);
  1172. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1173. //printf("\r\n Set Group %02X As Master", group);
  1174. }
  1175. }
  1176. void SetGroupToSlave(byte group, byte target)
  1177. {
  1178. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1179. {
  1180. SetGroupRole(group, _GROLE_SLAVE);
  1181. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1182. //printf("\r\n Set Group %02X As Slave", group);
  1183. }
  1184. }
  1185. // group: group index, target: target index
  1186. // add group to target's member
  1187. void AddGroupCollection(byte group, byte target)
  1188. {
  1189. int ParallelConfig = 0;
  1190. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1191. {
  1192. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1193. {
  1194. return;
  1195. }
  1196. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1197. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1198. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1199. {
  1200. return;
  1201. }
  1202. SetGroupToSlave(group, target);
  1203. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1204. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1205. if(ParallelConfig != 0)
  1206. {
  1207. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1208. }
  1209. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1210. }
  1211. }
  1212. // group: group index, target: target index
  1213. // remove group out of target's member
  1214. void RemoveGroupCollection(byte group, byte target)
  1215. {
  1216. int location = 0, slave = 0;
  1217. bool find = false;
  1218. int ParallelConfig = 0;
  1219. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1220. {
  1221. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1222. {
  1223. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1224. {
  1225. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1226. location = i;
  1227. find = true;
  1228. break;
  1229. }
  1230. }
  1231. if(find)
  1232. {
  1233. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1234. {
  1235. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1236. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1237. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1238. }
  1239. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1240. SetGroupToIdle(group);
  1241. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1242. if(ParallelConfig != 0)
  1243. {
  1244. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1245. }
  1246. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1247. }
  1248. }
  1249. }
  1250. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1251. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1252. void ShowGroupingInfo(void)
  1253. {
  1254. byte target = 0;
  1255. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1256. for(int i = 0; i < 4; i++)
  1257. {
  1258. target = ShmPsuGrouping->Layout[i];
  1259. printf("\r\n %d (%2d) %2d %d %02X ",
  1260. target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
  1261. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
  1262. for(int j = 0; j < 3; j++)
  1263. {
  1264. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
  1265. {
  1266. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
  1267. }
  1268. else
  1269. {
  1270. printf(" ");
  1271. }
  1272. }
  1273. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1274. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1275. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1276. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1277. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1278. }
  1279. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1280. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1281. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1282. printf("\r\n\r\n");
  1283. }
  1284. void PsuGroupSwitchToIdle(byte group)
  1285. {
  1286. int master = 0, quantity = 0, location = 0, total = 0;
  1287. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1288. {
  1289. return;
  1290. }
  1291. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1292. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1293. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1294. for(int i = 0; i < quantity; i++)
  1295. {
  1296. if(total == 0)
  1297. {
  1298. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1299. {
  1300. location = i;
  1301. total++;
  1302. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1303. }
  1304. }
  1305. else
  1306. {
  1307. // find other group in the same direction
  1308. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1309. {
  1310. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1311. {
  1312. total++;
  1313. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1314. }
  1315. }
  1316. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1317. {
  1318. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1319. {
  1320. total++;
  1321. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1322. }
  1323. }
  1324. }
  1325. }
  1326. if(total > 0)
  1327. {
  1328. unsigned char collection[GENERAL_GUN_QUANTITY];
  1329. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1330. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1331. for(int i = 0; i < total; i++)
  1332. {
  1333. //printf(" %02X", collection[i + location]);
  1334. }
  1335. for(int i = 0; i < total; i++)
  1336. {
  1337. RemoveGroupCollection(collection[i + location], master);
  1338. }
  1339. }
  1340. }
  1341. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1342. {
  1343. int slave = 0, location = 0;
  1344. PsuGroupPartner partner;
  1345. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1346. // search from left
  1347. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1348. for(int i = location; i >= 0; i--)
  1349. {
  1350. if(partner.Quantity >= quantity)
  1351. {
  1352. break;
  1353. }
  1354. slave = ShmPsuGrouping->Layout[i];
  1355. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1356. {
  1357. //printf("\r\n Find Group %02X From Left", slave);
  1358. partner.Member[partner.Quantity++] = slave;
  1359. }
  1360. else
  1361. {
  1362. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1363. {
  1364. continue;
  1365. }
  1366. break;
  1367. }
  1368. }
  1369. // search from right
  1370. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1371. for(int i = location; i < 4; i++)
  1372. {
  1373. if(partner.Quantity >= quantity)
  1374. {
  1375. break;
  1376. }
  1377. slave = ShmPsuGrouping->Layout[i];
  1378. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1379. {
  1380. //printf("\r\n Find Group %02X From Right", slave);
  1381. partner.Member[partner.Quantity++] = slave;
  1382. }
  1383. else
  1384. {
  1385. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1386. {
  1387. continue;
  1388. }
  1389. break;
  1390. }
  1391. }
  1392. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1393. }
  1394. int GetPsuGroupAvailable(byte group)
  1395. {
  1396. //int slave = 0, location = 0, available = 0;
  1397. PsuGroupPartner partner;
  1398. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1399. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1400. return partner.Quantity;
  1401. #if 0
  1402. // search from left
  1403. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1404. for(int i = location; i >= 0; i--)
  1405. {
  1406. slave = ShmPsuGrouping->Layout[i];
  1407. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1408. {
  1409. available++;
  1410. }
  1411. else
  1412. {
  1413. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1414. {
  1415. continue;
  1416. }
  1417. break;
  1418. }
  1419. }
  1420. // search from right
  1421. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1422. for(int i = location; i < 4; i++)
  1423. {
  1424. slave = ShmPsuGrouping->Layout[i];
  1425. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1426. {
  1427. available++;
  1428. }
  1429. else
  1430. {
  1431. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1432. {
  1433. continue;
  1434. }
  1435. break;
  1436. }
  1437. }
  1438. return available;
  1439. #endif
  1440. }
  1441. void PsuGroupShareCheck(byte group)
  1442. {
  1443. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1444. total = GetPsuGroupAvailable(group) + 1;
  1445. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1446. // search from left
  1447. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1448. for(int i = location; i >= 0; i--)
  1449. {
  1450. slave = ShmPsuGrouping->Layout[i];
  1451. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1452. {
  1453. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1454. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1455. {
  1456. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1457. }
  1458. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1459. break;
  1460. }
  1461. else
  1462. {
  1463. break;
  1464. }
  1465. }
  1466. if(share == 0)
  1467. {
  1468. // search from right
  1469. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1470. for(int i = location; i < 4; i++)
  1471. {
  1472. slave = ShmPsuGrouping->Layout[i];
  1473. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1474. {
  1475. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1476. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1477. {
  1478. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1479. }
  1480. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1481. break;
  1482. }
  1483. else
  1484. {
  1485. break;
  1486. }
  1487. }
  1488. }
  1489. if(share > 0)
  1490. {
  1491. //printf("\r\n Grab %02X", slave);
  1492. PsuGroupSwitchToIdle(slave);
  1493. }
  1494. else
  1495. {
  1496. //printf("\r\n No Need To Grab");
  1497. }
  1498. }
  1499. void SimplePsuGroupStartCharging(byte group)
  1500. {
  1501. //int slave = 0, location = 0;
  1502. int available = 0;
  1503. PsuGroupPartner partner;
  1504. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1505. {
  1506. return;
  1507. }
  1508. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1509. {
  1510. return;
  1511. }
  1512. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1513. {
  1514. SetGroupToMaster(group);
  1515. PsuGroupShareCheck(group);
  1516. }
  1517. else
  1518. {
  1519. available = GetPsuGroupAvailable(group);
  1520. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1521. if(available == 0)
  1522. {
  1523. return;
  1524. }
  1525. }
  1526. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1527. for(int i = 0; i < partner.Quantity; i++)
  1528. {
  1529. AddGroupCollection(partner.Member[i], group);
  1530. }
  1531. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1532. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1533. #if 0
  1534. // search from left
  1535. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1536. for(int i = location; i >= 0; i--)
  1537. {
  1538. slave = ShmPsuGrouping->Layout[i];
  1539. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1540. {
  1541. //printf("\r\n Find %02X From Left", slave);
  1542. AddGroupCollection(slave, group);
  1543. }
  1544. else
  1545. {
  1546. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1547. {
  1548. continue;
  1549. }
  1550. break;
  1551. }
  1552. }
  1553. // search from right
  1554. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1555. for(int i = location; i < 4; i++)
  1556. {
  1557. slave = ShmPsuGrouping->Layout[i];
  1558. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1559. {
  1560. //printf("\r\n Find %02X From Right", slave);
  1561. AddGroupCollection(slave, group);
  1562. }
  1563. else
  1564. {
  1565. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1566. {
  1567. continue;
  1568. }
  1569. break;
  1570. }
  1571. }
  1572. #endif
  1573. }
  1574. void PsuGroupStopCharging(byte group)
  1575. {
  1576. int total = 0;
  1577. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1578. {
  1579. return;
  1580. }
  1581. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  1582. if(total > 0)
  1583. {
  1584. unsigned char collection[GENERAL_GUN_QUANTITY];
  1585. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  1586. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1587. for(int i = 0; i < total; i++)
  1588. {
  1589. //printf(" %02X", collection[i]);
  1590. }
  1591. for(int i = 0; i < total; i++)
  1592. {
  1593. RemoveGroupCollection(collection[i], group);
  1594. }
  1595. }
  1596. SetGroupToIdle(group);
  1597. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1598. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1599. }
  1600. void RunSimplePsuGrouping(char *v1, char *v2)
  1601. {
  1602. int group = 0, charging = 0;
  1603. group = atoi(v1);
  1604. charging = atoi(v2);
  1605. group -= 1;
  1606. if(group >= 0 && group < 4)
  1607. {
  1608. if(charging > 0)
  1609. {
  1610. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1611. {
  1612. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1613. PsuGroupSwitchToIdle(group);
  1614. }
  1615. SimplePsuGroupStartCharging(group);
  1616. }
  1617. if(charging == 0)
  1618. {
  1619. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  1620. {
  1621. PsuGroupStopCharging(group);
  1622. }
  1623. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1624. {
  1625. PsuGroupSwitchToIdle(group);
  1626. }
  1627. }
  1628. ShowGroupingInfo();
  1629. }
  1630. }
  1631. void ConnectionInfo(void)
  1632. {
  1633. int address = 0;
  1634. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1635. {
  1636. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  1637. printf(" Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  1638. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  1639. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  1640. ((address >> 0) & 0xFF), ((address >> 8) & 0xFF), ((address >> 16) & 0xFF), ((address >> 24) & 0xFF));
  1641. }
  1642. }
  1643. void GunEnableInfo(int gunIndex)
  1644. {
  1645. printf(" Gun %d Index: %2X, Status = %2d , %7s, MeterValue: %10.4f, Local: : %10.4f, Gun: : %10.4f\r\n", gunIndex + 1, _chargingData[gunIndex]->Index, _chargingData[gunIndex]->SystemStatus,
  1646. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Enable ? "Enable" : "Disable",
  1647. _chargingData[gunIndex]->PowerConsumption,
  1648. ShmChargerInfo->MeterValue[gunIndex].LocalConsumption,
  1649. ShmChargerInfo->MeterValue[gunIndex].GunConsumption);
  1650. }
  1651. int FindDispenserIpAddress(int dispenser)
  1652. {
  1653. int address = 0;
  1654. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1655. {
  1656. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched &&
  1657. dispenser == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex)
  1658. {
  1659. address = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  1660. }
  1661. }
  1662. return address;
  1663. }
  1664. int DispenserInfo(int dispenser)
  1665. {
  1666. int ipAddress = 0;
  1667. int gunCnt = 0;
  1668. printf(" Dispenser %d Status: %d", dispenser + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus);
  1669. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  1670. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  1671. {
  1672. ipAddress = FindDispenserIpAddress(dispenser);
  1673. gunCnt = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorQuantity;
  1674. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ModelName,
  1675. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  1676. for(int i = 0; i < gunCnt; i++)
  1677. {
  1678. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].ConnectorID[i];
  1679. printf(" - Connector[%d] Gun %d, %s\r\n", i, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  1680. }
  1681. }
  1682. else
  1683. {
  1684. printf(", No Information\r\n");
  1685. }
  1686. return gunCnt;
  1687. }
  1688. void ShowCabinetInfo(char *inputCmd, unsigned int opt)
  1689. {
  1690. bool keepRun = false;
  1691. bool reflash = false;
  1692. int time = 0;
  1693. int dispenserLine = 0;
  1694. struct timespec _Loop_time;
  1695. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  1696. {
  1697. keepRun = true;
  1698. }
  1699. printf("\r\n");
  1700. printf("Power Cabinet & Dispenser Info\r\n");
  1701. do
  1702. {
  1703. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  1704. if(time >= 1000)
  1705. {
  1706. if(reflash)
  1707. {
  1708. ConsoleReflash(1, 2);
  1709. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  1710. dispenserLine = dispenserLine > 0 ? (dispenserLine + 1) : dispenserLine;
  1711. ConsoleReflash(1, dispenserLine);
  1712. dispenserLine = 0;
  1713. }
  1714. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  1715. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1716. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1717. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1718. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1719. printf("\r\n");
  1720. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  1721. {
  1722. GunEnableInfo(i);
  1723. }
  1724. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity > 0)
  1725. {
  1726. printf("\r\n");
  1727. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  1728. {
  1729. dispenserLine += DispenserInfo(i) + 1;
  1730. }
  1731. }
  1732. GetClockTime(&_Loop_time);
  1733. if((opt & OPTION_REFLASH) > 0)
  1734. {
  1735. reflash = true;
  1736. }
  1737. }
  1738. if(keepRun)
  1739. {
  1740. keepRun = IsLoopStopCmd() ? false : true;
  1741. usleep(10000);
  1742. }
  1743. }while(keepRun);
  1744. printf("\r\n");
  1745. }
  1746. void SetTestControl(char *v1, char *v2)
  1747. {
  1748. int testItem = 0;
  1749. int testItemLen = 5;
  1750. int enable = 0;
  1751. char strTest[32][32] = {"tbl", "tfsb", "chgsm", "fcre", "ubill"};
  1752. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation", "FCharging Release Extend", "Undisposed Bill"};
  1753. enable = atoi(v2);
  1754. if(enable < 0)
  1755. {
  1756. return;
  1757. }
  1758. for(int i = 0; i < testItemLen; i++)
  1759. {
  1760. if(strcmp((char *)&strTest[i][0], v1) == 0)
  1761. {
  1762. testItem = i + 1;
  1763. break;
  1764. }
  1765. }
  1766. if(testItem != 0)
  1767. {
  1768. if(enable)
  1769. {
  1770. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  1771. }
  1772. else
  1773. {
  1774. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  1775. }
  1776. printf("%s %s Test Item, Test Control Value = %08X\n",
  1777. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  1778. }
  1779. else
  1780. {
  1781. printf("Test Item %s Not Found\n", v1);
  1782. for(int i = 0; i < testItemLen; i++)
  1783. {
  1784. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  1785. }
  1786. }
  1787. printf("\r\n");
  1788. }
  1789. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim
  1790. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX XXX kw XXX kW XXX kW
  1791. void ShowGroupingDemand(void)
  1792. {
  1793. byte target = 0;
  1794. unsigned char k1k2 = 0;
  1795. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim");
  1796. for(int i = 0; i < 4; i++)
  1797. {
  1798. target = ShmPsuGrouping->Layout[i];
  1799. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  1800. {
  1801. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  1802. }
  1803. else
  1804. {
  1805. k1k2 = _chargingData[target]->RelayK1K2Status;
  1806. }
  1807. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  1808. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  1809. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  1810. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  1811. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  1812. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1813. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  1814. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  1815. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  1816. {
  1817. printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  1818. printf(" %3d kW %3d kW %3d kW",
  1819. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Available,
  1820. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Capability,
  1821. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_PhysicalLimit);
  1822. }
  1823. }
  1824. printf("\r\n\r\n");
  1825. }
  1826. // v1: gun
  1827. // v2: voltage
  1828. // v3: current
  1829. void SetGunStartCharging(char *inputCmd, unsigned int opt, unsigned char isWeb)
  1830. {
  1831. int totalCnt = 0, maxPara = 0;
  1832. maxPara = 3;
  1833. totalCnt = GetSubCommand(inputCmd);
  1834. if(totalCnt != maxPara)
  1835. {
  1836. printf("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\r\n\r\n");
  1837. return;
  1838. }
  1839. int gun = 0;
  1840. float _voltage = 0, _current = 0;
  1841. gun = atoi(&MultiSubCmd[0][0]);
  1842. _voltage = atof(&MultiSubCmd[1][0]);
  1843. _current = atof(&MultiSubCmd[2][0]);
  1844. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  1845. {
  1846. printf("\r\n");
  1847. printf("Gun Start Charging Input parameter %d, %.1f, %.1f out of range\r\n", gun, _voltage, _current);
  1848. printf("\r\n");
  1849. return;
  1850. }
  1851. bool wait = true;
  1852. int time = 0;
  1853. struct timespec _Wait_time;
  1854. unsigned char PreviousSystemStatus = 0xFF;
  1855. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  1856. printf("\r\n");
  1857. while(wait)
  1858. {
  1859. switch(_chargingData[gun - 1]->SystemStatus)
  1860. {
  1861. case S_IDLE:
  1862. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1863. {
  1864. printf("Gun %d S_IDLE\r\n", gun);
  1865. printf("Set Gun %d Start Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  1866. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  1867. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  1868. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1869. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1870. if(isWeb)
  1871. {
  1872. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.WebApiTrigger = true;
  1873. }
  1874. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1875. }
  1876. break;
  1877. case S_REASSIGN_CHECK:
  1878. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1879. {
  1880. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  1881. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1882. }
  1883. break;
  1884. case S_REASSIGN:
  1885. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1886. {
  1887. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  1888. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1889. }
  1890. break;
  1891. case S_PREPARNING:
  1892. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1893. {
  1894. printf("Gun %d S_PREPARNING\r\n", gun);
  1895. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1896. }
  1897. break;
  1898. case S_PREPARING_FOR_EV:
  1899. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1900. {
  1901. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  1902. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1903. }
  1904. break;
  1905. case S_PREPARING_FOR_EVSE:
  1906. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1907. {
  1908. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  1909. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1910. }
  1911. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1912. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1913. {
  1914. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1915. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1916. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  1917. }
  1918. break;
  1919. case S_CHARGING:
  1920. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1921. {
  1922. printf("Gun %d S_CHARGING\r\n", gun);
  1923. if(PreviousSystemStatus == 0xFF)
  1924. {
  1925. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1926. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1927. printf("Gun %d Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  1928. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  1929. {
  1930. printf("Set Gun %d Force Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  1931. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1932. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1933. }
  1934. }
  1935. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1936. GetClockTime(&_Wait_time);
  1937. }
  1938. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1939. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1940. {
  1941. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1942. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1943. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  1944. }
  1945. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  1946. if(time >= 1)
  1947. {
  1948. wait = false;
  1949. printf("Done\r\n");
  1950. }
  1951. break;
  1952. case S_TERMINATING:
  1953. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1954. {
  1955. printf("Gun %d S_TERMINATING\r\n", gun);
  1956. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1957. }
  1958. wait = false;
  1959. break;
  1960. case S_COMPLETE:
  1961. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1962. {
  1963. printf("Gun %d S_COMPLETE\r\n", gun);
  1964. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1965. }
  1966. wait = false;
  1967. break;
  1968. case S_ALARM:
  1969. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1970. {
  1971. printf("Gun %d S_ALARM\r\n", gun);
  1972. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1973. }
  1974. wait = false;
  1975. break;
  1976. default:
  1977. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1978. {
  1979. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  1980. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1981. }
  1982. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  1983. wait = false;
  1984. break;
  1985. }
  1986. char word[128];
  1987. char newString[7][10];
  1988. int i,j,ctr;
  1989. memset(word, 0x00, sizeof(word));
  1990. get_char(word);
  1991. if (strlen(word) == 0)
  1992. {
  1993. continue;
  1994. }
  1995. j=0; ctr=0;
  1996. strcpy(newString[1], "-1");
  1997. strcpy(newString[2], "-1");
  1998. for (i = 0; i <= (strlen(word)); i++)
  1999. {
  2000. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2001. {
  2002. newString[ctr][j] = '\0';
  2003. ctr++;
  2004. j = 0;
  2005. }
  2006. else
  2007. {
  2008. newString[ctr][j] = word[i];
  2009. j++;
  2010. }
  2011. }
  2012. if(strcmp(newString[0], "c") == 0)
  2013. {
  2014. printf("Stop\r\n");
  2015. wait = false;
  2016. }
  2017. usleep(100000);
  2018. }
  2019. printf("\r\n");
  2020. }
  2021. void GenerateManualStop(int gunIndex, bool isAlarm, char *alarmCode)
  2022. {
  2023. if(isAlarm)
  2024. {
  2025. if(!_chargingData[gunIndex]->ChargingStopFlag.bits.AlarmStop)
  2026. {
  2027. if(strncmp((char *)_chargingData[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL)
  2028. {
  2029. memcpy((char *)_chargingData[gunIndex]->ConnectorAlarmCode, alarmCode, 6);
  2030. }
  2031. _chargingData[gunIndex]->ChargingStopFlag.bits.AlarmStop = true;
  2032. printf("Set Gun %d Stop Charging(ManualAlarm)\r\n", gunIndex + 1);
  2033. }
  2034. }
  2035. else
  2036. {
  2037. if(!_chargingData[gunIndex]->ChargingStopFlag.bits.ManualStop)
  2038. {
  2039. _chargingData[gunIndex]->ChargingStopFlag.bits.ManualStop = true;
  2040. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gunIndex + 1);
  2041. }
  2042. }
  2043. }
  2044. // v1: gun
  2045. void SetGunStopCharging(char *inputCmd, unsigned int opt)
  2046. {
  2047. int totalCnt = 0, maxPara = 0;
  2048. maxPara = 2;
  2049. totalCnt = GetSubCommand(inputCmd);
  2050. if(totalCnt > maxPara || totalCnt == 0)
  2051. {
  2052. printf("Input cmd fail ------ gunstp [gun 1-4] [status code]\r\n\r\n");
  2053. return;
  2054. }
  2055. int gun = 0;
  2056. gun = atoi(&MultiSubCmd[0][0]);
  2057. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2058. {
  2059. printf("\r\n");
  2060. printf("Gun Stop Charging Input parameter %d over range\r\n", gun);
  2061. printf("\r\n");
  2062. return;
  2063. }
  2064. bool isAlarmStop = false;
  2065. char manualAlarm[7];
  2066. if(totalCnt == 2)
  2067. {
  2068. if((strlen(&MultiSubCmd[1][0]) == 6) && atoi(&MultiSubCmd[1][0]) != 0)
  2069. {
  2070. memset(manualAlarm, 0x00, sizeof(manualAlarm));
  2071. memcpy(manualAlarm, &MultiSubCmd[1][0], 6);
  2072. isAlarmStop = true;
  2073. }
  2074. }
  2075. bool wait = true;
  2076. int time = 0;
  2077. struct timespec _Wait_time;
  2078. unsigned char PreviousSystemStatus = 0xFF;
  2079. printf("\r\n");
  2080. while(wait)
  2081. {
  2082. switch(_chargingData[gun - 1]->SystemStatus)
  2083. {
  2084. case S_IDLE:
  2085. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2086. {
  2087. printf("Gun %d S_IDLE\r\n", gun);
  2088. if(PreviousSystemStatus == 0xFF)
  2089. {
  2090. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2091. {
  2092. printf("Set Group [%02X] Stop\r\n", gun - 1);
  2093. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2094. }
  2095. }
  2096. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2097. GetClockTime(&_Wait_time);
  2098. }
  2099. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2100. if(time >= 1)
  2101. {
  2102. wait = false;
  2103. printf("Done\r\n");
  2104. }
  2105. break;
  2106. case S_REASSIGN_CHECK:
  2107. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2108. {
  2109. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2110. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2111. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2112. }
  2113. break;
  2114. case S_REASSIGN:
  2115. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2116. {
  2117. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2118. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2119. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2120. }
  2121. break;
  2122. case S_PREPARNING:
  2123. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2124. {
  2125. printf("Gun %d S_PREPARNING\r\n", gun);
  2126. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2127. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2128. }
  2129. break;
  2130. case S_PREPARING_FOR_EV:
  2131. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2132. {
  2133. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2134. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2135. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2136. }
  2137. break;
  2138. case S_PREPARING_FOR_EVSE:
  2139. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2140. {
  2141. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2142. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2143. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2144. }
  2145. break;
  2146. case S_CHARGING:
  2147. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2148. {
  2149. printf("Gun %d S_CHARGING\r\n", gun);
  2150. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2151. GenerateManualStop(gun - 1, isAlarmStop, manualAlarm);
  2152. }
  2153. break;
  2154. case S_TERMINATING:
  2155. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2156. {
  2157. printf("Gun %d S_TERMINATING\r\n", gun);
  2158. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2159. }
  2160. break;
  2161. case S_COMPLETE:
  2162. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2163. {
  2164. printf("Gun %d S_COMPLETE\r\n", gun);
  2165. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2166. }
  2167. break;
  2168. case S_ALARM:
  2169. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2170. {
  2171. printf("Gun %d S_ALARM\r\n", gun);
  2172. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2173. }
  2174. break;
  2175. default:
  2176. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2177. {
  2178. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2179. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2180. }
  2181. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2182. wait = false;
  2183. break;
  2184. }
  2185. char word[128];
  2186. char newString[7][10];
  2187. int i,j,ctr;
  2188. memset(word, 0x00, sizeof(word));
  2189. get_char(word);
  2190. if (strlen(word) == 0)
  2191. {
  2192. continue;
  2193. }
  2194. j=0; ctr=0;
  2195. strcpy(newString[1], "-1");
  2196. strcpy(newString[2], "-1");
  2197. for (i = 0; i <= (strlen(word)); i++)
  2198. {
  2199. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2200. {
  2201. newString[ctr][j] = '\0';
  2202. ctr++;
  2203. j = 0;
  2204. }
  2205. else
  2206. {
  2207. newString[ctr][j] = word[i];
  2208. j++;
  2209. }
  2210. }
  2211. if(strcmp(newString[0], "c") == 0)
  2212. {
  2213. printf("Stop\r\n");
  2214. wait = false;
  2215. }
  2216. usleep(100000);
  2217. }
  2218. printf("\r\n");
  2219. }
  2220. void SetGunExtend(char *v1)
  2221. {
  2222. int gun = 0;
  2223. gun = atoi(v1);
  2224. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2225. {
  2226. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2227. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2228. }
  2229. else
  2230. {
  2231. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2232. }
  2233. printf("\r\n\r\n");
  2234. }
  2235. // Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...
  2236. // X XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A
  2237. void ShowGunOutput(void)
  2238. {
  2239. byte target = 0;
  2240. unsigned short voltage = 0, current = 0;
  2241. printf("\r\n Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...");
  2242. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2243. {
  2244. target = ShmPsuGrouping->Layout[i];
  2245. // "\r\n %d %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A"
  2246. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2247. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2248. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2249. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2250. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2251. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2252. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2253. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2254. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2255. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2256. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2257. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2258. /*
  2259. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2260. {
  2261. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2262. }
  2263. */
  2264. }
  2265. printf("\r\n\r\n");
  2266. }
  2267. void SetGpio(char *v1, char *v2)
  2268. {
  2269. int testItem = 0;
  2270. int testItemLen = 1;
  2271. int ioOutput = 0;
  2272. char strTest[32][32] = {"4g"};
  2273. char strItem[32][32] = {"4G Reset"};
  2274. ioOutput = atoi(v2);
  2275. if(ioOutput < 0)
  2276. {
  2277. return;
  2278. }
  2279. for(int i = 0; i < testItemLen; i++)
  2280. {
  2281. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2282. {
  2283. testItem = i + 1;
  2284. break;
  2285. }
  2286. }
  2287. if(testItem != 0)
  2288. {
  2289. if(ioOutput)
  2290. {
  2291. system("echo 1 > /sys/class/gpio/gpio104/value");
  2292. }
  2293. else
  2294. {
  2295. system("echo 0 > /sys/class/gpio/gpio104/value");
  2296. }
  2297. printf("Set %s %s\n",
  2298. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2299. }
  2300. else
  2301. {
  2302. printf("Gpio Item %s Not Found\n", v1);
  2303. }
  2304. printf("\r\n");
  2305. }
  2306. void ShowStatus(void)
  2307. {
  2308. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2309. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2310. {
  2311. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2312. i + 1,
  2313. _chargingData[i]->SystemStatus,
  2314. _chargingData[i]->IsAvailable,
  2315. ShmChargerInfo->Control.GunAvailable[i]);
  2316. printf("\r\nAlarmCode");
  2317. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2318. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2319. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2320. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2321. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2322. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2323. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2324. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2325. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2326. }
  2327. printf("\r\n");
  2328. printf("\r\nPower Cabinet Role: %s, Switch Value: %d, ",
  2329. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2330. ShmChargerInfo->Control.CabinetSwitch);
  2331. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2332. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2333. {
  2334. printf("\r\n WarningCode:");
  2335. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2336. {
  2337. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2338. }
  2339. }
  2340. printf("\r\n\r\n");
  2341. }
  2342. void ShowWhiteCardList(void)
  2343. {
  2344. printf("\r\nWhite Card List");
  2345. for(int i = 0; i < 10; i++)
  2346. {
  2347. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2348. }
  2349. printf("\r\n\r\n");
  2350. }
  2351. void WriteWhiteCard(char *v1, char *v2)
  2352. {
  2353. int cardIndex = 0;
  2354. cardIndex = atoi(v1);
  2355. if(cardIndex < 1 || cardIndex > 10)
  2356. {
  2357. printf("\r\n White Card Index Fail\r\n\r\n");
  2358. return;
  2359. }
  2360. if(strlen(v2) == 0 || strlen(v2) > 31)
  2361. {
  2362. printf("\r\n White Card Fail\r\n\r\n");
  2363. return;
  2364. }
  2365. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2366. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2367. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2368. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2369. printf("\r\n\r\n");
  2370. }
  2371. void EraseWhiteCard(char *v1)
  2372. {
  2373. int cardIndex = 0;
  2374. cardIndex = atoi(v1);
  2375. if(cardIndex < 1 || cardIndex > 10)
  2376. {
  2377. printf("\r\n White Card Index Fail\r\n\r\n");
  2378. return;
  2379. }
  2380. printf("\r\n Erase White Card Index = %d", cardIndex);
  2381. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2382. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  2383. printf("\r\n\r\n");
  2384. }
  2385. // MaxChargingProfile: %s
  2386. // Offline MaxPower: %s
  2387. // Max Total Power: XXXX kW, Total Current: XXXX A, MaxSoc: XXX %
  2388. // Total Energy: XXXX kWh, Duration: XXXX Minute(s)
  2389. void ShowMaxLimit(void)
  2390. {
  2391. char tempString[64];
  2392. //************************************************************************************************
  2393. memset(tempString, 0x00, sizeof(tempString));
  2394. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1)
  2395. {
  2396. sprintf(tempString, " %s", "Unlimited");
  2397. }
  2398. else
  2399. {
  2400. sprintf(tempString, " %4d kW", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2401. }
  2402. printf(" MaxChargingProfile: %s\r\n", tempString);
  2403. //************************************************************************************************
  2404. memset(tempString, 0x00, sizeof(tempString));
  2405. if(ShmChargerInfo->OutputLimit.Offline_MaxChargingPower <= 0)
  2406. {
  2407. sprintf(tempString, " %s", "Unlimited");
  2408. }
  2409. else
  2410. {
  2411. sprintf(tempString, " %4d kW", ShmChargerInfo->OutputLimit.Offline_MaxChargingPower / 1000);
  2412. }
  2413. printf(" Offline MaxPower: %s\r\n", tempString);
  2414. //************************************************************************************************
  2415. printf(" Max Total Power: %4d kW, Total Current: %4d A, MaxSoc: %3d %%\r\n",
  2416. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2417. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
  2418. ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  2419. //************************************************************************************************
  2420. printf(" Total Energy: %4d kWh, Duration: %4d Minute(s)\r\n",
  2421. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2422. }
  2423. void ShowGunLimit(int gun_index)
  2424. {
  2425. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2426. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
  2427. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
  2428. // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
  2429. printf(" %d %d ", gun_index + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable);
  2430. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable)
  2431. {
  2432. printf(" %7s %2d",
  2433. _chargingData[gun_index]->Type <= _Type_GB ? str_gun_type[_chargingData[gun_index]->Type] : "???",
  2434. ShmChargerInfo->PsuGrouping.GroupCollection[gun_index].GunPsuQuantity);
  2435. printf(" %4d V %4d A",
  2436. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalVoltage / 10),
  2437. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteMaxPhysicalCurrent / 10));
  2438. printf(" %4d / %4d / %4d kW",
  2439. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower / 10),
  2440. _chargingData[gun_index]->ChargingProfilePower == -1 ? (int)_chargingData[gun_index]->ChargingProfilePower : ((int)_chargingData[gun_index]->ChargingProfilePower / 1000),
  2441. ShmChargerInfo->OutputLimit.GunMaxProfilePower[gun_index] == 0 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (ShmChargerInfo->OutputLimit.GunMaxProfilePower[gun_index] / 1000));
  2442. printf(" %4d / %4d A",
  2443. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent / 10),
  2444. _chargingData[gun_index]->ChargingProfileCurrent == -1 ? (int)_chargingData[gun_index]->ChargingProfileCurrent : ((int)_chargingData[gun_index]->ChargingProfileCurrent / 10));
  2445. }
  2446. printf("\r\n");
  2447. }
  2448. void ShowChargerLimit(char *inputCmd, unsigned int opt)
  2449. {
  2450. bool keepRun = false;
  2451. bool reflash = false;
  2452. int time = 0;
  2453. struct timespec _Loop_time;
  2454. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2455. {
  2456. keepRun = true;
  2457. }
  2458. printf("\r\n");
  2459. printf("Charger Limit\r\n");
  2460. do
  2461. {
  2462. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2463. if(time >= 1000)
  2464. {
  2465. if(reflash)
  2466. {
  2467. ConsoleReflash(1, 6);
  2468. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  2469. }
  2470. ShowMaxLimit();
  2471. printf("\r\n");
  2472. printf(" Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur\r\n");
  2473. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2474. {
  2475. ShowGunLimit(i);
  2476. }
  2477. GetClockTime(&_Loop_time);
  2478. if((opt & OPTION_REFLASH) > 0)
  2479. {
  2480. reflash = true;
  2481. }
  2482. }
  2483. if(keepRun)
  2484. {
  2485. keepRun = IsLoopStopCmd() ? false : true;
  2486. usleep(10000);
  2487. }
  2488. }while(keepRun);
  2489. printf("\r\n");
  2490. }
  2491. void SetPsuCommand(char *inputCmd, unsigned int opt)
  2492. {
  2493. }
  2494. void SetGunCommand(char *v1, char *v2, char *v3)
  2495. {
  2496. int cmdItem = 0;
  2497. int cmdItemLen = 2;
  2498. int gunID = 0;
  2499. int enable = 0;
  2500. char strGunCmd[32][32] = {"enable", "operative"};
  2501. char strDescription[32][32] = {"Available", "Operative"};
  2502. gunID = atoi(v2);
  2503. enable = atoi(v3);
  2504. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2505. {
  2506. return;
  2507. }
  2508. for(int i = 0; i < cmdItemLen; i++)
  2509. {
  2510. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2511. {
  2512. cmdItem = i + 1;
  2513. break;
  2514. }
  2515. }
  2516. if(cmdItem != 0)
  2517. {
  2518. switch(cmdItem)
  2519. {
  2520. case 1:
  2521. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2522. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2523. break;
  2524. case 2:
  2525. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2526. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2527. break;
  2528. }
  2529. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2530. }
  2531. else
  2532. {
  2533. printf("Gun cmd %s not found\n", v1);
  2534. for(int i = 0; i < cmdItemLen; i++)
  2535. {
  2536. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2537. }
  2538. }
  2539. printf("\r\n");
  2540. }
  2541. void ShowWebSystemInfo(void)
  2542. {
  2543. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2544. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2545. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2546. printf("\r\n");
  2547. printf("Web [System]\r\n");
  2548. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2549. printf(" *AuthorisationMode[%7s]\r\n",
  2550. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2551. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2552. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2553. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2554. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2555. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2556. {
  2557. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2558. }
  2559. else
  2560. {
  2561. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2562. }
  2563. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2564. {
  2565. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2566. }
  2567. else
  2568. {
  2569. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2570. }
  2571. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2572. {
  2573. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2574. }
  2575. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2576. {
  2577. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2578. }
  2579. else
  2580. {
  2581. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2582. }
  2583. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  2584. {
  2585. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  2586. }
  2587. else
  2588. {
  2589. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  2590. }
  2591. }
  2592. void ShowWebChargingInfo(void)
  2593. {
  2594. printf("\r\n");
  2595. printf("Web [Charging]\r\n");
  2596. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  2597. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  2598. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  2599. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2600. printf(" *Max Charging Soc : %4d %%\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  2601. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  2602. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  2603. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  2604. }
  2605. // *DHCP Client [Enable]
  2606. // - MAC Add [%s]
  2607. // - IP Add [%s]
  2608. // - Submask [%s]
  2609. // - Gateway [%s]
  2610. void ShowEthernetInfo(void)
  2611. {
  2612. printf(" *DHCP Client [%s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  2613. printf(" - MAC Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress : "NULL");
  2614. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress : "NULL");
  2615. printf(" - SubMask [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress : "NULL");
  2616. printf(" - Gateway [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress : "NULL");
  2617. }
  2618. // *WiFi Mode [Station]
  2619. // - SSID [%s]
  2620. // - PWD [%s]
  2621. // - TargetMac [%s]
  2622. // - RSSI [%s]
  2623. // - DHCP [%s]
  2624. // - MAC Add [%s]
  2625. // - IP Add [%s]
  2626. // - Submask [%s]
  2627. // - Gateway [%s]
  2628. // - ConnStatus [Connected]
  2629. void ShowWiFiInfo(void)
  2630. {
  2631. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  2632. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  2633. {
  2634. printf(" *WiFi Mode [%s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  2635. }
  2636. else
  2637. {
  2638. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  2639. }
  2640. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_STATION)
  2641. {
  2642. printf(" - SSID [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid : "NULL");
  2643. printf(" - PWD [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword : "NULL");
  2644. printf(" - TargetMac [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiTargetBssidMac : "NULL");
  2645. printf(" - RSSI [%d dBm]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi);
  2646. printf(" - DHCP [%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiDhcpClient == 0 ? "Enable" : "Disable");
  2647. printf(" - MAC Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress : "NULL");
  2648. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress : "NULL");
  2649. printf(" - SubMask [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress : "NULL");
  2650. printf(" - Gateway [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress : "NULL");
  2651. printf(" - ConnStatus [%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  2652. }
  2653. }
  2654. // *3G/4G Mode [%s]
  2655. // - APN [%s]
  2656. // - NetworkType[%s]
  2657. // - RSSI [%d dBm]
  2658. // - ChapPapId [%s]
  2659. // - ChapPapPwd [%s]
  2660. // - Modem IMEI [%s]
  2661. // - SIM IMSI [%s]
  2662. // - SIM ICCID [%s]
  2663. // - SIM Status [%s]
  2664. // - Modem Mode [%s]
  2665. // - IP Add [%s]
  2666. // - ConnStatus [%s]
  2667. void Show3G4GInfo(void)
  2668. {
  2669. char *strNetworkType[] = {"Auto", "CDMA", "WCDMA", "LTE", "TD-SCDMA", "UMTS", "CDMA", "HDR", "CDMA/HDR"};
  2670. char *strSimStatus[] = {"No SIM Card", "Valid SIM Card", "Invalid SIM Card"};
  2671. char *strModemMode[] = {"No Services", "CDMA", "GSM/GPRS", "WCDMA", "GSM/WCDMA", "TD_SCDMA", "HSPA", "LTE", "Mode 8", "Unknown"};
  2672. printf(" *3G/4G Mode [%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  2673. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
  2674. {
  2675. printf(" - APN [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn : "NULL");
  2676. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType <= 8)
  2677. {
  2678. printf(" - NetworkType[%s]\r\n", strNetworkType[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType]);
  2679. }
  2680. else
  2681. {
  2682. printf(" - NetworkType[%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkType);
  2683. }
  2684. printf(" - RSSI [%d dBm]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  2685. printf(" - ChapPapId [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId : "NULL");
  2686. printf(" - ChapPapPwd [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd : "NULL");
  2687. printf(" - Modem IMEI [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemImei : "NULL");
  2688. printf(" - SIM IMSI [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi : "NULL");
  2689. printf(" - SIM ICCID [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid : "NULL");
  2690. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus <= 2)
  2691. {
  2692. printf(" - SIM Status [%s]\r\n", strSimStatus[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus]);
  2693. }
  2694. else
  2695. {
  2696. printf(" - SIM Status [%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimStatus);
  2697. }
  2698. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode <= 9)
  2699. {
  2700. printf(" - Modem Mode [%s]\r\n", strModemMode[ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode]);
  2701. }
  2702. else
  2703. {
  2704. printf(" - Modem Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomModemMode);
  2705. }
  2706. printf(" - IP Add [%s]\r\n", strlen((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress) > 0 ? (char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress : "NULL");
  2707. printf(" - ConnStatus [%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  2708. }
  2709. }
  2710. void ShowWebNetworkInfo(void)
  2711. {
  2712. printf("\r\n");
  2713. printf("Web [Network]\r\n");
  2714. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2715. ShowEthernetInfo();
  2716. ShowWiFiInfo();
  2717. Show3G4GInfo();
  2718. }
  2719. void ShowWebEthernetOnly(void)
  2720. {
  2721. printf("\r\n");
  2722. printf("Web [Network]\r\n");
  2723. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2724. ShowEthernetInfo();
  2725. }
  2726. void ShowWebWiFiOnly(void)
  2727. {
  2728. printf("\r\n");
  2729. printf("Web [Network]\r\n");
  2730. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2731. ShowWiFiInfo();
  2732. }
  2733. void ShowWeb3G4GOnly(void)
  2734. {
  2735. printf("\r\n");
  2736. printf("Web [Network]\r\n");
  2737. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2738. Show3G4GInfo();
  2739. }
  2740. void ShowWebBackendInfo(void)
  2741. {
  2742. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  2743. char *str_security_profile[] = {
  2744. "None security",
  2745. "Unsecured Transport with Basic Atuentication",
  2746. "TLS with Basic Authentication",
  2747. "TLS with Client Side Certificates"
  2748. };
  2749. printf("\r\n");
  2750. printf("Web [Backend]\r\n");
  2751. printf(" *Common\r\n");
  2752. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  2753. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  2754. {
  2755. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  2756. }
  2757. else
  2758. {
  2759. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  2760. }
  2761. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  2762. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  2763. printf(" *OCPP\r\n");
  2764. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  2765. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  2766. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2767. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2768. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  2769. {
  2770. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  2771. }
  2772. else
  2773. {
  2774. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2775. }
  2776. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  2777. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  2778. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  2779. {
  2780. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  2781. }
  2782. else
  2783. {
  2784. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  2785. }
  2786. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  2787. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  2788. {
  2789. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  2790. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  2791. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  2792. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  2793. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  2794. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  2795. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  2796. }
  2797. }
  2798. void ShowWebAllInfo(void)
  2799. {
  2800. ShowWebSystemInfo();
  2801. ShowWebChargingInfo();
  2802. ShowWebNetworkInfo();
  2803. ShowWebBackendInfo();
  2804. }
  2805. void ShowWebInfo(char *inputCmd, unsigned int opt)
  2806. {
  2807. int totalCnt = 0, maxPara = 0;
  2808. maxPara = 1;
  2809. totalCnt = GetSubCommand(inputCmd);
  2810. if(totalCnt > maxPara)
  2811. {
  2812. printf("Input cmd fail ------ web [cmd]\r\n\r\n");
  2813. return;
  2814. }
  2815. bool find = false;
  2816. int showItem = 0;
  2817. int itemLen = 8;
  2818. char strItem[32][32] = {"system", "charging", "network", "backend", "all", "eth", "wifi", "4g"};
  2819. void *actionList[32] = {
  2820. &ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo,
  2821. &ShowWebAllInfo, &ShowWebEthernetOnly, &ShowWebWiFiOnly, &ShowWeb3G4GOnly};
  2822. void (*ItemAction)();
  2823. for(showItem = 0; showItem < itemLen; showItem++)
  2824. {
  2825. if(strcmp((char *)&strItem[showItem][0], &MultiSubCmd[0][0]) == 0)
  2826. {
  2827. find = true;
  2828. break;
  2829. }
  2830. }
  2831. if(find)
  2832. {
  2833. ItemAction = actionList[showItem];
  2834. ItemAction();
  2835. }
  2836. else
  2837. {
  2838. printf("\r\n");
  2839. printf ("Input cmd fail ------ web [cmd]\r\n");
  2840. for(int i = 0; i < itemLen; i++)
  2841. {
  2842. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  2843. }
  2844. }
  2845. printf("\r\n");
  2846. }
  2847. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  2848. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  2849. // PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  2850. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Local: XXXXXXX.XXX kWh
  2851. // Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  2852. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Remote: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  2853. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXXXX.XXX kWh, IdTag: [XXXXXXXXXX]
  2854. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW, TxId: [XXXXXXXXXX]
  2855. // Start: [0000-00-00 00:00:00] PSU: XXXX V, XXXX A, Limit: XXXX A, XXXX kW, Ratio: X.XX %
  2856. // Stop: [0000-00-00 00:00:00] Gun: XXXX V, XXXX A, Power: XXXX.X kW, FireV: XXXX.X V
  2857. // Remote: XXXXXXX.XXX kWh, Local: XXXXXXX.XXX kWh, Meter: XXXXXXX.XXX kWh
  2858. void ShowGunInfo(int gun)
  2859. {
  2860. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  2861. #if 0
  2862. printf(" Gun %d (%s) Soc: %3d %s, Energy: %10.3f kWh, IdTag [%20s] Transaction [%d], TotalCost: %.2f\r\n",
  2863. gun + 1,
  2864. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2865. _chargingData[gun]->EvBatterySoc, "%",
  2866. _chargingData[gun]->PresentChargedEnergy,
  2867. _chargingData[gun]->StartUserId,
  2868. ShmChargerInfo->UserTransaction[gun].TransactionId,
  2869. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  2870. #endif
  2871. //************************************************************************************************
  2872. printf(" Gun %d (%s) Soc: %3d %s, Energy: %11.3f kWh",
  2873. gun + 1,
  2874. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2875. _chargingData[gun]->EvBatterySoc, "%",
  2876. _chargingData[gun]->PresentChargedEnergy);
  2877. if(strlen((char *)_chargingData[gun]->StartUserId) > 0)
  2878. {
  2879. printf(", IdTag: [%s]", _chargingData[gun]->StartUserId);
  2880. }
  2881. printf("\r\n");
  2882. //************************************************************************************************
  2883. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW",
  2884. _chargingData[gun]->SystemStatus,
  2885. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  2886. (int)_chargingData[gun]->EvBatterytargetVoltage,
  2887. (int)_chargingData[gun]->EvBatterytargetCurrent,
  2888. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  2889. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  2890. if(ShmChargerInfo->UserTransaction[gun].TransactionId > 0)
  2891. {
  2892. printf(", TxId: [%d]", ShmChargerInfo->UserTransaction[gun].TransactionId);
  2893. }
  2894. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost > 0)
  2895. {
  2896. printf(", $: %.2f", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  2897. }
  2898. printf("\r\n");
  2899. //************************************************************************************************
  2900. if(strlen(ShmChargerInfo->Timestamp[gun].StartCharging) > 0)
  2901. {
  2902. printf(" Start: [%s] ", ShmChargerInfo->Timestamp[gun].StartCharging);
  2903. }
  2904. else
  2905. {
  2906. printf(" ");
  2907. }
  2908. printf("PSU: %4d V, %4d A, Limit: %4d A, %4d kW, Ratio: %4.2f %%\r\n",
  2909. (int)(_chargingData[gun]->PresentChargingVoltage),
  2910. (int)(_chargingData[gun]->PresentChargingCurrent),
  2911. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  2912. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10),
  2913. ShmPsuGrouping->GroupCollection[gun].MaxOutputRatio);
  2914. //************************************************************************************************
  2915. if(strlen(ShmChargerInfo->Timestamp[gun].StopCharging) > 0)
  2916. {
  2917. printf(" Stop: [%s] ", ShmChargerInfo->Timestamp[gun].StopCharging);
  2918. }
  2919. else
  2920. {
  2921. printf(" ");
  2922. }
  2923. printf("Gun: %4d V, %4d A, Power: %6.1f kW, FireV: %6.1f V\r\n",
  2924. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingVoltage / 10),
  2925. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].RemoteChargingCurrent / 10),
  2926. _chargingData[gun]->PresentChargingPower,
  2927. (_chargingData[gun]->FireChargingVoltage / 10));
  2928. //************************************************************************************************
  2929. printf(" Remote: %11.3f kWh, Local: %11.3f kWh, Meter: %11.3f kWh\r\n",
  2930. ShmChargerInfo->MeterValue[gun].GunConsumption,
  2931. ShmChargerInfo->MeterValue[gun].LocalConsumption,
  2932. _chargingData[gun]->PowerConsumption);
  2933. }
  2934. void ShowInfo(char *inputCmd, unsigned int opt)
  2935. {
  2936. bool keepRun = false;
  2937. bool reflash = false;
  2938. int time = 0;
  2939. struct timespec _Loop_time;
  2940. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  2941. {
  2942. keepRun = true;
  2943. }
  2944. do
  2945. {
  2946. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  2947. if(time >= 1000)
  2948. {
  2949. if(reflash)
  2950. {
  2951. ConsoleReflash(CONNECTOR_QUANTITY, 6);
  2952. }
  2953. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2954. {
  2955. printf("\r\n");
  2956. ShowGunInfo(i);
  2957. }
  2958. GetClockTime(&_Loop_time);
  2959. if((opt & OPTION_REFLASH) > 0)
  2960. {
  2961. reflash = true;
  2962. }
  2963. }
  2964. if(keepRun)
  2965. {
  2966. keepRun = IsLoopStopCmd() ? false : true;
  2967. usleep(10000);
  2968. }
  2969. }while(keepRun);
  2970. printf("\r\n");
  2971. }
  2972. void RtcSyncCmd(char *inputCmd, unsigned int opt)
  2973. {
  2974. int totalCnt = 0, maxPara = 0;
  2975. char hostAdd[32];
  2976. int dispenser = 0, offset = 0;
  2977. memset(hostAdd, 0x00, sizeof(hostAdd));
  2978. maxPara = 2;
  2979. totalCnt = GetSubCommand(inputCmd);
  2980. if(totalCnt != maxPara)
  2981. {
  2982. printf("Input cmd fail ------ rtc [dispenser 1-4] [offset minute]\r\n\r\n");
  2983. return;
  2984. }
  2985. printf("\r\n");
  2986. dispenser = atoi(&MultiSubCmd[0][0]);
  2987. offset = atoi(&MultiSubCmd[1][0]);
  2988. if(dispenser <= 0 || dispenser > CONNECTOR_QUANTITY)
  2989. {
  2990. printf("dispenser %d over range\r\n\r\n", dispenser);
  2991. return;
  2992. }
  2993. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_None ||
  2994. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_Timeout)
  2995. {
  2996. printf("dispenser %d is not available\r\n\r\n", dispenser);
  2997. return;
  2998. }
  2999. // find dispenser ip address
  3000. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3001. {
  3002. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
  3003. {
  3004. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex == (dispenser - 1))
  3005. {
  3006. sprintf(hostAdd, "%d.%d.%d.%d",
  3007. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) &0xFF),
  3008. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) &0xFF),
  3009. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) &0xFF),
  3010. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) &0xFF));
  3011. }
  3012. }
  3013. }
  3014. if(strlen(hostAdd) == 0)
  3015. {
  3016. printf("dispenser %d ip is not available\r\n\r\n", dispenser);
  3017. return;
  3018. }
  3019. printf("try sycn dispenser %d [%s] rtc, offset: %d minutes\r\n", dispenser, hostAdd, offset);
  3020. // get current time and create offset time
  3021. time_t timep;
  3022. struct tm *tm;
  3023. time(&timep);
  3024. tm = localtime(&timep);
  3025. printf(" NowTime: %d/%02d/%02d %02d:%02d:%02d\r\n",
  3026. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3027. if(offset != 0)
  3028. {
  3029. timep += (offset * 60);
  3030. tm = localtime(&timep);
  3031. printf("OffsetTime: %d/%02d/%02d %02d:%02d:%02d\r\n\r\n",
  3032. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3033. }
  3034. // create send socket
  3035. int rtcfd = 0;
  3036. struct sockaddr_in serverInfo;
  3037. struct timeval tv;
  3038. char rtcTxBuffer[64];
  3039. char rtcRxBuffer[64];
  3040. int txLen = 0, rxLen = 0;
  3041. unsigned char chksum = 0x00;
  3042. rtcfd = socket(AF_INET, SOCK_STREAM, 0);
  3043. if (rtcfd < 0)
  3044. {
  3045. printf("create rtc socket fail\r\n\r\n");
  3046. return;
  3047. }
  3048. memset(rtcTxBuffer, 0x00, sizeof(rtcTxBuffer));
  3049. memset(rtcRxBuffer, 0x00, sizeof(rtcRxBuffer));
  3050. tv.tv_sec = 3;
  3051. tv.tv_usec = 0;
  3052. setsockopt(rtcfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
  3053. setsockopt(rtcfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); //設定傳送3s
  3054. bzero(&serverInfo,sizeof(serverInfo));
  3055. serverInfo.sin_family = AF_INET;
  3056. serverInfo.sin_addr.s_addr = inet_addr(hostAdd);
  3057. serverInfo.sin_port = htons(8234);
  3058. if(connect(rtcfd, (struct sockaddr *)&serverInfo, sizeof(serverInfo)) < 0)
  3059. {
  3060. printf("connect to host: %s fail\r\n\r\n", hostAdd);
  3061. close(rtcfd);
  3062. return;
  3063. }
  3064. // set tx header & data
  3065. rtcTxBuffer[0] = 0xAA; // Frame ID
  3066. rtcTxBuffer[1] = 0x00; // Master address
  3067. rtcTxBuffer[2] = 0xFF; // Slave address
  3068. rtcTxBuffer[3] = 0x87; // 0x87
  3069. rtcTxBuffer[4] = 0x0E; // Length_Low
  3070. rtcTxBuffer[5] = 0x00; // Length_High
  3071. sprintf(&rtcTxBuffer[6], "%04d%02d%02d%02d%02d%02d",
  3072. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3073. txLen = rtcTxBuffer[4] + (rtcTxBuffer[5] << 8);
  3074. chksum = 0;
  3075. for(int i = 0; i < txLen; i++)
  3076. {
  3077. chksum ^= rtcTxBuffer[6 + i];
  3078. }
  3079. rtcTxBuffer[6 + txLen] = chksum;
  3080. send(rtcfd, rtcTxBuffer, txLen + 7, MSG_NOSIGNAL);
  3081. // receive
  3082. if(recv(rtcfd, &rtcRxBuffer[0], 6, MSG_WAITALL) < 0)
  3083. {
  3084. printf("read head fail\r\n\r\n");
  3085. close(rtcfd);
  3086. return;
  3087. }
  3088. rxLen = rtcRxBuffer[4] + (rtcRxBuffer[5] << 8);
  3089. if(recv(rtcfd, &rtcRxBuffer[6], rxLen + 1, MSG_WAITALL) < 0)
  3090. {
  3091. printf("read data fail\r\n\r\n");
  3092. close(rtcfd);
  3093. return;
  3094. }
  3095. chksum = 0;
  3096. for(int i = 0; i < rxLen; i++)
  3097. {
  3098. chksum ^= rtcRxBuffer[6 + i];
  3099. }
  3100. if(chksum == rtcRxBuffer[6 + rxLen])
  3101. {
  3102. printf("set %s rtc: ", hostAdd);
  3103. for(int i = 0; i < txLen; i++)
  3104. {
  3105. printf("%c", rtcTxBuffer[6 + i]);
  3106. }
  3107. printf(" %s\r\n\r\n", rtcRxBuffer[6] == 0x01 ? "success" : "fail");
  3108. }
  3109. else
  3110. {
  3111. printf("receive rtc checksum fail\r\n\r\n");
  3112. }
  3113. close(rtcfd);
  3114. }
  3115. void ParsingModelName(char *modelName)
  3116. {
  3117. ParsingRatedCur parsingRatedCur = {0};
  3118. RateCurInfo *pRatedCurInfo = NULL;
  3119. if(RatedCurrentParsing(modelName, &parsingRatedCur) != PASS)
  3120. {
  3121. printf("Parsing [%s] failed\r\n", modelName);
  3122. return;
  3123. }
  3124. printf("Model Name: [%s]\r\n", modelName);
  3125. for(int i = 0; i < 2; i++)
  3126. {
  3127. pRatedCurInfo = (RateCurInfo *)&parsingRatedCur.ParsingInfo[i];
  3128. printf(" Gun %d Type %d, MaxVol: %d, MaxCur: %d\r\n",
  3129. i + 1, pRatedCurInfo->GunType, pRatedCurInfo->Voltage, pRatedCurInfo->Current);
  3130. }
  3131. }
  3132. void ParsingModelNameCmd(char *inputCmd, unsigned int opt)
  3133. {
  3134. int totalCnt = 0, maxPara = 0;
  3135. maxPara = 1;
  3136. totalCnt = GetSubCommand(inputCmd);
  3137. if(totalCnt > maxPara)
  3138. {
  3139. printf("Input cmd fail ------ pmodel [model_name]\r\n\r\n");
  3140. return;
  3141. }
  3142. printf("\r\n");
  3143. if(totalCnt != 0)
  3144. {
  3145. ParsingModelName(&MultiSubCmd[0][0]);
  3146. }
  3147. else
  3148. {
  3149. printf("Cabinet\r\n");
  3150. ParsingModelName((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  3151. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  3152. {
  3153. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  3154. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  3155. {
  3156. printf("\r\n");
  3157. printf("Dispenser %d\r\n", i + 1);
  3158. ParsingModelName((char *)&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName[0]);
  3159. }
  3160. }
  3161. }
  3162. printf("\r\n");
  3163. }
  3164. void CustomerPriceTest(char *inputCmd, unsigned int opt)
  3165. {
  3166. #if 0
  3167. char priceString[512];
  3168. float price = 0;
  3169. printf("\r\n");
  3170. // running cost
  3171. printf("Running Cost\r\n");
  3172. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $15.96 NTD; Occupancy Fee: $0 NTD; Total Cost: $15.96 NTD; Account Balance: $37693 NTD");
  3173. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3174. printf("Connection Fee: %.2f\r\n", price);
  3175. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3176. printf("Session Fee: %.2f\r\n", price);
  3177. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3178. printf("Occupancy Fee: %.2f\r\n", price);
  3179. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3180. printf("Total Cost: %.2f\r\n", price);
  3181. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3182. printf("Account Balance: %.2f\r\n", price);
  3183. // final cost
  3184. printf("Final Cost\r\n");
  3185. strcpy(priceString, "Connection Fee: $0 NTD; Session Fee: $283.68 NTD; Occupancy Fee: $0 NTD; Total Cost: $283.68 NTD; Account Balance: $37410 NTD");
  3186. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3187. printf("Connection Fee: %.2f\r\n", price);
  3188. price = PriceParsing((char *)priceString, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
  3189. printf("Session Fee: %.2f\r\n", price);
  3190. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3191. printf("Occupancy Fee: %.2f\r\n", price);
  3192. price = PriceParsing((char *)priceString, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
  3193. printf("Total Cost: %.2f\r\n", price);
  3194. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3195. printf("Account Balance: %.2f\r\n", price);
  3196. // user price
  3197. printf("User Price\r\n");
  3198. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr; Account Balance: $17553 NTD");
  3199. price = PriceParsing((char *)priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3200. printf("Connection Fee: %.2f\r\n", price);
  3201. price = PriceParsing((char *)priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3202. printf("Current Rate: %.2f\r\n", price);
  3203. price = PriceParsing((char *)priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3204. printf("Occupancy Fee: %.2f\r\n", price);
  3205. price = PriceParsing((char *)priceString, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
  3206. printf("Account Balance: %.2f\r\n", price);
  3207. // default price
  3208. printf("Default Price\r\n");
  3209. strcpy(priceString, "Connection Fee: $0 NTD/time; Current Rate: $12 NTD/kWh; Occupancy Fee: $0 NTD/hr");
  3210. price = PriceParsing(priceString, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
  3211. printf("Connection Fee: %.2f\r\n", price);
  3212. price = PriceParsing(priceString, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
  3213. printf("Current Rate: %.2f\r\n", price);
  3214. price = PriceParsing(priceString, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
  3215. printf("Occupancy Fee: %.2f\r\n", price);
  3216. printf("\r\n");
  3217. printf("TCC Default Price\r\n");
  3218. strcpy(priceString, "$ 12/kWh");
  3219. price = PriceParsing(priceString, "", "");
  3220. printf("Default: %.2f\r\n", price);
  3221. printf("\r\n");
  3222. char userPrice[512];
  3223. printf("Shell Default Price\r\n");
  3224. strcpy(priceString, "100.0 kW\nPrice\nTransaction Fee: $0.6165/Flat\nIdle Fee: $0.5/Flat\n\n100.0 kW\nPrice\nTransaction Fee: $0.6165/Flat\nIdle Fee: $0.5/Flat\n\n");
  3225. ShellPriceParsing(priceString, userPrice);
  3226. printf("DefaultPrice: %s\r\n", userPrice);
  3227. printf("\r\n");
  3228. printf("Shell User Price\r\n");
  3229. ShellPriceParsing(priceString, userPrice);
  3230. printf("UserPrice: %s\r\n", userPrice);
  3231. printf("\r\n");
  3232. strcpy(priceString, "Current Period Price:$0.35/kWh\nCurrent Idle Fee: $5.0/hr\nCurrent Total: 2.70kWh $2.53 ConnectorId: 1\nLast update: 2021-06-28T11:22:31");
  3233. price = ShellRunningCostParsing(priceString);
  3234. printf("Shell Running Cost\r\n");
  3235. printf("Cost: %.2f\r\n", price);
  3236. printf("\r\n");
  3237. strcpy(priceString, "2022-01-18 07:00:00-2022-01-18 08:15:30\n07:00 AM $1.00/kWh 4.30kWh Cost: $4.300\n07:30 AM $2.00/kWh 0.00kWh Cost: $4.300\n07:46 AM $0.00/Flat 10m Cost: $0.000\n07:56 AM $0.50/Flat 19m Cost: $0.500\nTotal\nSale: $4.80\nTax: $0.00\nTransaction Fee: $0.62\nDiscount: $0.00\nCost: $5.42\nEnergy: 4.3000kWh\nTime: 1 Hrs 15 Mins\nPayment: RFID\nReceipt: https://qa.qa.greenlotstest-qa.com/greenlots/receipt.jsf?session5658739 | Call 1 800 Greenlots or check app for more detailed receipt\nEV_DISCONNECTED");
  3238. printf("Shell Final Cost\r\n");
  3239. int urlLen = 0;
  3240. char url[512];
  3241. price = ShellFinalCostParsing(priceString);
  3242. urlLen = GetShellReceiptInfo(priceString, url);
  3243. printf("Cost: %.2f\r\n", price);
  3244. if(urlLen > 0)
  3245. {
  3246. printf("Receipt: [%s]\r\n", url);
  3247. }
  3248. #endif
  3249. }
  3250. void EvCommMsgDebug(char *inputCmd, unsigned int opt)
  3251. {
  3252. int totalCnt = 0, maxPara = 0;
  3253. maxPara = 2;
  3254. totalCnt = GetSubCommand(inputCmd);
  3255. printf("\r\n");
  3256. if(totalCnt == 1)
  3257. {
  3258. if(strcmp(&MultiSubCmd[0][0], "clean") == 0)
  3259. {
  3260. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] = 0;
  3261. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] = 0;
  3262. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] = 0;
  3263. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3] = 0;
  3264. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3265. printf("Clean All EvComm Msg Flag\r\n");
  3266. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3267. return;
  3268. }
  3269. }
  3270. if(totalCnt != maxPara)
  3271. {
  3272. printf("Input cmd fail ------ evmsg [reg] [enable 0-1]\r\n\r\n");
  3273. return;
  3274. }
  3275. bool find = false;
  3276. int reg = 0, enable = 0;
  3277. reg = atoi(&MultiSubCmd[0][0]);
  3278. enable = atoi(&MultiSubCmd[1][0]);
  3279. if(enable > 1 || enable < 0)
  3280. {
  3281. printf("enable(%d) out of range\r\n\r\n", enable);
  3282. return;
  3283. }
  3284. if(reg >= _Reg_Dispenser_Model_Name && reg < _Reg_None)
  3285. {
  3286. find = true;
  3287. if(enable)
  3288. {
  3289. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] |= (1 << (reg % 32));
  3290. printf("Set EvComm Msg Flag: 0x%02X\r\n", reg);
  3291. }
  3292. else
  3293. {
  3294. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[reg / 32] &= ~(1 << (reg % 32));
  3295. printf("Clean EvComm Msg Flag: 0x%02X\r\n", reg);
  3296. }
  3297. }
  3298. else
  3299. {
  3300. if(strcmp(&MultiSubCmd[0][0], "all") == 0)
  3301. {
  3302. find = true;
  3303. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.bits.RegDbg_All = enable;
  3304. printf("%s EvComm All Msg Flag\r\n", enable ? "Enable" : "Disable");
  3305. }
  3306. }
  3307. if(find)
  3308. {
  3309. printf("EvCommMsg[0]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0]);
  3310. printf("EvCommMsg[1]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1]);
  3311. printf("EvCommMsg[2]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2]);
  3312. printf("EvCommMsg[3]: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3]);
  3313. printf("\r\n");
  3314. if(ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[0] ||
  3315. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[1] ||
  3316. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[2] ||
  3317. ShmChargerInfo->Control.EvCommCtrl.MsgFlag.DebugVal[3])
  3318. {
  3319. if(!ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3320. {
  3321. printf("Enable MsgEvComm Flag Debug\r\n\r\n");
  3322. }
  3323. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = true;
  3324. }
  3325. else
  3326. {
  3327. if(ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm)
  3328. {
  3329. printf("Disable MsgEvComm Flag Debug\r\n\r\n");
  3330. }
  3331. ShmChargerInfo->Control.DebugCtrl.bits.MsgEvComm = false;
  3332. }
  3333. }
  3334. else
  3335. {
  3336. printf("reg: 0x%02X out of range\r\n", reg);
  3337. printf("\r\n");
  3338. }
  3339. }
  3340. void EvCommIdDebug(char *inputCmd, unsigned int opt)
  3341. {
  3342. int totalCnt = 0, maxPara = 0;
  3343. maxPara = 2;
  3344. totalCnt = GetSubCommand(inputCmd);
  3345. printf("\r\n");
  3346. if(totalCnt != maxPara)
  3347. {
  3348. printf("Input cmd fail ------ evid [id] [enable 0-1]\r\n\r\n");
  3349. return;
  3350. }
  3351. int id = 0, enable = 0;
  3352. id = atoi(&MultiSubCmd[0][0]);
  3353. enable = atoi(&MultiSubCmd[1][0]);
  3354. if(enable > 1 || enable < 0)
  3355. {
  3356. printf("enable(%d) out of range\r\n\r\n", enable);
  3357. return;
  3358. }
  3359. if(id > 0 && id <= CONNECTOR_QUANTITY)
  3360. {
  3361. if(enable)
  3362. {
  3363. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal |= (1 << id);
  3364. printf("Set EvComm ID %d Enable\r\n", id);
  3365. }
  3366. else
  3367. {
  3368. ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal &= ~(1 << id);
  3369. printf("Clean EvComm ID %d\r\n", id);
  3370. }
  3371. printf("EvComm ID: %08X\r\n", ShmChargerInfo->Control.EvCommCtrl.IdFlag.DebugVal);
  3372. printf("\r\n");
  3373. }
  3374. else
  3375. {
  3376. printf("id(%d) out of range\r\n\r\n", id);
  3377. }
  3378. }
  3379. bool SetModelName(char *modelName)
  3380. {
  3381. if(!IsCabinetModelNameLegal(modelName))
  3382. {
  3383. printf("Model Name: [%s] is Illegal\r\n", modelName);
  3384. return false;
  3385. }
  3386. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.ModelName, modelName, MODELNAME_LENGTH);
  3387. printf("Set Model Name: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ModelName);
  3388. return true;
  3389. }
  3390. bool SetSerialNumber(char *serialNumber)
  3391. {
  3392. if(!IsSerialNumberLegal(serialNumber))
  3393. {
  3394. printf("Serial Number: [%s] is Illegal\r\n", serialNumber);
  3395. return false;
  3396. }
  3397. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SerialNumber, serialNumber, SERIAL_NUMBER_LENGTH);
  3398. printf("Set Serial Number: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3399. return true;
  3400. }
  3401. bool SetSystemID(char *systemId)
  3402. {
  3403. if(!IsSystemIdLegal(systemId))
  3404. {
  3405. printf("System ID: [%s] is Illegal\r\n", systemId);
  3406. return false;
  3407. }
  3408. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  3409. printf("Set System ID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  3410. return true;
  3411. }
  3412. bool CleanSystemID(void)
  3413. {
  3414. memset((char *)&ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
  3415. printf("Clean System ID OK\r\n");
  3416. return true;
  3417. }
  3418. bool SetAuthorisationMode(char *mode)
  3419. {
  3420. bool disable = false;
  3421. if(strcmp(mode, "disable") == EQUAL)
  3422. {
  3423. disable = true;
  3424. }
  3425. else
  3426. {
  3427. if(strcmp(mode, "enable") != EQUAL)
  3428. {
  3429. printf("Authorisation Mode: [%s] is Illegal\r\n", mode);
  3430. printf(" [value] enable | disable\r\n");
  3431. return false;
  3432. }
  3433. }
  3434. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = disable;
  3435. printf("Set Authorisation Mode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 0 ? "Enable" : "Disable");
  3436. if(disable && ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID)
  3437. {
  3438. printf("AuthorisationMode Is Disable, AuthrizeByEVCCID Need To Set Disable\r\n");
  3439. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = false;
  3440. }
  3441. return true;
  3442. }
  3443. bool SetAuthrizeByEVCCID(char *isEVCCID)
  3444. {
  3445. bool enable = false;
  3446. if(strcmp(isEVCCID, "enable") == EQUAL)
  3447. {
  3448. enable = true;
  3449. }
  3450. else
  3451. {
  3452. if(strcmp(isEVCCID, "disable") != EQUAL)
  3453. {
  3454. printf("Authrize By EVCCID: [%s] is Illegal\r\n", isEVCCID);
  3455. printf(" [value] enable | disable\r\n");
  3456. return false;
  3457. }
  3458. }
  3459. if(enable && ShmSysConfigAndInfo->SysConfig.AuthorisationMode == 1)
  3460. {
  3461. printf("AuthorisationMode Is Disable, Reset AuthrizeByEVCCID To Disable\r\n");
  3462. enable = false;
  3463. }
  3464. ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID = enable;
  3465. printf("Set AuthrizeByEVCCID: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID ? "Enable" : "Disable");
  3466. return true;
  3467. }
  3468. bool SetQRCodeMadeMode(char *qrCodeMode)
  3469. {
  3470. bool customized = false;
  3471. if(strcmp(qrCodeMode, "customized") == EQUAL)
  3472. {
  3473. customized = true;
  3474. }
  3475. else
  3476. {
  3477. if(strcmp(qrCodeMode, "default") != EQUAL)
  3478. {
  3479. printf("QR Code Made Mode: [%s] is Illegal\r\n", qrCodeMode);
  3480. printf(" [value] default | customized\r\n");
  3481. return false;
  3482. }
  3483. }
  3484. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = customized;
  3485. printf("Set QRCodeMadeMode: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode ? "Customized" : "Default");
  3486. return true;
  3487. }
  3488. bool SetQRCodeContent(char *content)
  3489. {
  3490. if(strlen(content) >= sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent))
  3491. {
  3492. printf("QR Code Content: [%s] is Out Of Length\r\n", content);
  3493. return false;
  3494. }
  3495. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3496. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, content, strlen(content));
  3497. printf("Set QRCodeContent: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  3498. return true;
  3499. }
  3500. bool CleanQRCodeContent(void)
  3501. {
  3502. memset((char *)&ShmSysConfigAndInfo->SysConfig.QRCodeContent, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.QRCodeContent));
  3503. printf("Clean QRCode Content OK\r\n");
  3504. return true;
  3505. }
  3506. bool SetLEDIntensity(char *intensity)
  3507. {
  3508. int ledIntensity = _LED_INTENSITY_DARKEST;
  3509. char *strIntensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  3510. if(strcmp(intensity, "brightest") == EQUAL)
  3511. {
  3512. ledIntensity = _LED_INTENSITY_BRIGHTEST;
  3513. }
  3514. else if(strcmp(intensity, "medium") == EQUAL)
  3515. {
  3516. ledIntensity = _LED_INTENSITY_MEDIUM;
  3517. }
  3518. else if(strcmp(intensity, "darkest") != EQUAL)
  3519. {
  3520. printf("LED Intensity: [%s] is Illegal\r\n", intensity);
  3521. printf(" [value] darkest | medium | brightest\r\n");
  3522. return false;
  3523. }
  3524. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = ledIntensity;
  3525. printf("Set LED Intensity: [%s] OK\r\n", strIntensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  3526. return true;
  3527. }
  3528. bool SetMaxChargingEnergy(char *energy)
  3529. {
  3530. int _energy = 0;
  3531. _energy = atoi(energy);
  3532. if(_energy < 0)
  3533. {
  3534. printf("MaxChargingEnergy: [%s] is Illegal\r\n", energy);
  3535. printf(" [value] > 0\r\n");
  3536. return false;
  3537. }
  3538. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = _energy;
  3539. printf("Set MaxChargingEnergy: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  3540. return true;
  3541. }
  3542. bool SetMaxChargingPower(char *power)
  3543. {
  3544. int _power = 0;
  3545. _power = atoi(power);
  3546. if(_power < 0)
  3547. {
  3548. printf("MaxChargingEnergy: [%s] is Illegal\r\n", power);
  3549. printf(" [value] > 0\r\n");
  3550. return false;
  3551. }
  3552. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = _power;
  3553. printf("Set MaxChargingPower: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  3554. return true;
  3555. }
  3556. bool SetMaxChargingCurrent(char *current)
  3557. {
  3558. int _current = 0;
  3559. _current = atoi(current);
  3560. if(_current < 0)
  3561. {
  3562. printf("MaxChargingEnergy: [%s] is Illegal\r\n", current);
  3563. printf(" [value] > 0\r\n");
  3564. return false;
  3565. }
  3566. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = _current;
  3567. printf("Set MaxChargingCurrent: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  3568. return true;
  3569. }
  3570. bool SetMaxChargingDuration(char *duration)
  3571. {
  3572. int _duration = 0;
  3573. _duration = atoi(duration);
  3574. if(_duration < 0)
  3575. {
  3576. printf("MaxChargingDuration: [%s] is Illegal\r\n", duration);
  3577. printf(" [value] > 0\r\n");
  3578. return false;
  3579. }
  3580. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = _duration;
  3581. printf("Set MaxChargingDuration: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  3582. return true;
  3583. }
  3584. bool SetMaxChargingSoc(char *soc)
  3585. {
  3586. int _soc = 0;
  3587. _soc = atoi(soc);
  3588. if(_soc < 0 || _soc > 100)
  3589. {
  3590. printf("MaxChargingSoc: [%s] is Illegal\r\n", soc);
  3591. printf(" [value] 0 ~ 100\r\n");
  3592. return false;
  3593. }
  3594. ShmSysConfigAndInfo->SysConfig.MaxChargingSoc = _soc;
  3595. printf("Set MaxChargingSoc: [%d] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
  3596. return true;
  3597. }
  3598. bool SetStopChargingByButton(char *btn)
  3599. {
  3600. bool enable = false;
  3601. if(strcmp(btn, "enable") == EQUAL)
  3602. {
  3603. enable = true;
  3604. }
  3605. else
  3606. {
  3607. if(strcmp(btn, "disable") != EQUAL)
  3608. {
  3609. printf("Stop Charging By Button: [%s] is Illegal\r\n", btn);
  3610. printf(" [value] enable | disable\r\n");
  3611. return false;
  3612. }
  3613. }
  3614. ShmSysConfigAndInfo->SysConfig.StopChargingByButton = enable;
  3615. printf("Set Stop Charging By Button: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton ? "Enable" : "Disable");
  3616. return true;
  3617. }
  3618. bool SetOfflinePolicy(char *policy)
  3619. {
  3620. int offlinePolicy = _OFFLINE_POLICY_LOCAL_LIST;
  3621. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  3622. if(strcmp(policy, "free") == EQUAL)
  3623. {
  3624. offlinePolicy = _OFFLINE_POLICY_FREE_CHARGING;
  3625. }
  3626. else if(strcmp(policy, "nocharging") == EQUAL)
  3627. {
  3628. offlinePolicy = _OFFLINE_POLICY_NO_CHARGING;
  3629. }
  3630. else if(strcmp(policy, "local") != EQUAL)
  3631. {
  3632. printf("Offline Policy: [%s] is Illegal\r\n", policy);
  3633. printf(" [value] local | rfid | free | nocharging\r\n");
  3634. return false;
  3635. }
  3636. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = offlinePolicy;
  3637. printf("Set Offline Policy: [%s] OK\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  3638. return true;
  3639. }
  3640. bool SetOcppServerURL(char *url)
  3641. {
  3642. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL))
  3643. {
  3644. printf("Ocpp Server URL: [%s] is Out Of Length\r\n", url);
  3645. return false;
  3646. }
  3647. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3648. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, url);
  3649. printf("Set Ocpp Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  3650. return true;
  3651. }
  3652. bool CleanOcppServerURL(void)
  3653. {
  3654. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  3655. printf("Clean Ocpp Server URL OK\r\n");
  3656. return true;
  3657. }
  3658. bool SetChargeBoxId(char *boxId)
  3659. {
  3660. if(strlen(boxId) >= sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId))
  3661. {
  3662. printf("Charge Box Id: [%s] is Out Of Length\r\n", boxId);
  3663. return false;
  3664. }
  3665. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3666. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, boxId);
  3667. printf("Set Charge Box Id: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  3668. return true;
  3669. }
  3670. bool CleanChargeBoxId(void)
  3671. {
  3672. memset((char *)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
  3673. printf("Clean Charge Box Id OK\r\n");
  3674. return true;
  3675. }
  3676. bool SetChargePointVendor(char *vendor)
  3677. {
  3678. if(strlen(vendor) >= sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor))
  3679. {
  3680. printf("Charge Point Vendor: [%s] is Out Of Length\r\n", vendor);
  3681. return false;
  3682. }
  3683. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3684. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, vendor);
  3685. printf("Set Charge Point Vendor: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3686. return true;
  3687. }
  3688. bool CleanChargePointVendor(void)
  3689. {
  3690. memset((char *)&ShmSysConfigAndInfo->SysConfig.chargePointVendor, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  3691. printf("Clean Charge Point Vendor OK\r\n");
  3692. return true;
  3693. }
  3694. bool SetOcppReceiptrURL(char *receipt)
  3695. {
  3696. if(strlen(receipt) >= sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL))
  3697. {
  3698. printf("Ocpp Receiptr URL: [%s] is Out Of Length\r\n", receipt);
  3699. return false;
  3700. }
  3701. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3702. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, receipt);
  3703. printf("Set Ocpp Receiptr URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL);
  3704. return true;
  3705. }
  3706. bool CleanOcppReceiptrURL(void)
  3707. {
  3708. memset((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL));
  3709. printf("Clean Ocpp Receiptr URL OK\r\n");
  3710. return true;
  3711. }
  3712. bool SetMaintainServerURL(char *url)
  3713. {
  3714. if(strlen(url) >= sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL))
  3715. {
  3716. printf("Maintain Server URL: [%s] is Out Of Length\r\n", url);
  3717. return false;
  3718. }
  3719. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3720. strcpy((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, url);
  3721. printf("Set Maintain Server URL: [%s] OK\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  3722. return true;
  3723. }
  3724. bool CleanMaintainServerURL(void)
  3725. {
  3726. memset((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  3727. printf("Clean Maintain Server URL OK\r\n");
  3728. return true;
  3729. }
  3730. void FlashSetCmd(char *inputCmd, unsigned int opt)
  3731. {
  3732. char subMain[MAX_SUB_CMD_LENGTH];
  3733. char subSub[MAX_SUB_CMD_LENGTH];
  3734. memset(subMain, 0x00, sizeof(subMain));
  3735. memset(subSub, 0x00, sizeof(subSub));
  3736. bool find = false;
  3737. int actIndex = 0;
  3738. int maxLen = 20;
  3739. char strWriteItem[32][32] = {
  3740. "model", "sn", "sysid", "auth", "evccid", "qrmode", "qrcode", "led",
  3741. "energy", "power", "current", "time", "soc", "stopbtn", "policy", "backend",
  3742. "boxid", "vendor", "receipt", "maintain"};
  3743. bool (*writeFlashList[32])(char *) = {
  3744. &SetModelName, &SetSerialNumber, &SetSystemID, &SetAuthorisationMode,
  3745. &SetAuthrizeByEVCCID, &SetQRCodeMadeMode, &SetQRCodeContent, &SetLEDIntensity,
  3746. &SetMaxChargingEnergy, &SetMaxChargingPower, &SetMaxChargingCurrent, &SetMaxChargingDuration,
  3747. &SetMaxChargingSoc, &SetStopChargingByButton, &SetOfflinePolicy, &SetOcppServerURL,
  3748. &SetChargeBoxId, &SetChargePointVendor, &SetOcppReceiptrURL, &SetMaintainServerURL};
  3749. bool (*WriteFlashAct)(char *);
  3750. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3751. {
  3752. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3753. {
  3754. if(strcmp((char *)&strWriteItem[actIndex][0], subMain) == 0)
  3755. {
  3756. find = true;
  3757. break;
  3758. }
  3759. }
  3760. if(find)
  3761. {
  3762. printf("\r\n");
  3763. WriteFlashAct = writeFlashList[actIndex];
  3764. WriteFlashAct(subSub);
  3765. printf("\r\n");
  3766. return;
  3767. }
  3768. }
  3769. printf("\r\n");
  3770. printf("Input cmd fail ------ model [set] [cmd] [value]\r\n");
  3771. printf(" [cmd]");
  3772. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3773. {
  3774. printf("%s%s", actIndex == 0 ? " " : " | ", &strWriteItem[actIndex][0]);
  3775. }
  3776. printf("\r\n\r\n");
  3777. }
  3778. void FlashCleanCmd(char *inputCmd, unsigned int opt)
  3779. {
  3780. char subMain[MAX_SUB_CMD_LENGTH];
  3781. char subSub[MAX_SUB_CMD_LENGTH];
  3782. memset(subMain, 0x00, sizeof(subMain));
  3783. memset(subSub, 0x00, sizeof(subSub));
  3784. bool find = false;
  3785. int actIndex = 0;
  3786. int maxLen = 7;
  3787. char strCleanItem[32][32] = {
  3788. "sysid", "qrcode", "backend", "boxid", "vendor", "receipt", "maintain"};
  3789. bool (*cleanFlashList[32])() = {
  3790. &CleanSystemID, &CleanQRCodeContent, &CleanOcppServerURL, &CleanChargeBoxId,
  3791. &CleanChargePointVendor, &CleanOcppReceiptrURL, &CleanMaintainServerURL};
  3792. bool (*CleanFlashAct)();
  3793. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  3794. {
  3795. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3796. {
  3797. if(strcmp((char *)&strCleanItem[actIndex][0], subMain) == 0)
  3798. {
  3799. find = true;
  3800. break;
  3801. }
  3802. }
  3803. if(find)
  3804. {
  3805. printf("\r\n");
  3806. CleanFlashAct = cleanFlashList[actIndex];
  3807. CleanFlashAct();
  3808. printf("\r\n");
  3809. return;
  3810. }
  3811. }
  3812. printf("\r\n");
  3813. printf("Input cmd fail ------ model [clean] [cmd]\r\n");
  3814. printf(" [cmd]");
  3815. for(actIndex = 0; actIndex < maxLen; actIndex++)
  3816. {
  3817. printf("%s%s", actIndex == 0 ? " " : " | ", &strCleanItem[actIndex][0]);
  3818. }
  3819. printf("\r\n\r\n");
  3820. }
  3821. void FlashWriteCmd(char *inputCmd, unsigned int opt)
  3822. {
  3823. if(strcmp(inputCmd, "now") == EQUAL)
  3824. {
  3825. printf("\r\n");
  3826. printf("Write Flash Immediately\r\n\r\n");
  3827. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
  3828. ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately = true;
  3829. }
  3830. else
  3831. {
  3832. printf("\r\n");
  3833. printf("Write Flash Command Not Available\r\n\r\n");
  3834. }
  3835. }
  3836. void FlashCmd(char *inputCmd, unsigned int opt)
  3837. {
  3838. char subMain[MAX_SUB_CMD_LENGTH];
  3839. char subSub[MAX_SUB_CMD_LENGTH];
  3840. memset(subMain, 0x00, sizeof(subMain));
  3841. memset(subSub, 0x00, sizeof(subSub));
  3842. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3843. {
  3844. if(strcmp(subMain, "set") == EQUAL)
  3845. {
  3846. FlashSetCmd(subSub, opt);
  3847. return;
  3848. }
  3849. if(strcmp(subMain, "write") == EQUAL)
  3850. {
  3851. FlashWriteCmd(subSub, opt);
  3852. return;
  3853. }
  3854. if(strcmp(subMain, "clean") == EQUAL)
  3855. {
  3856. FlashCleanCmd(subSub, opt);
  3857. return;
  3858. }
  3859. }
  3860. printf("\r\n");
  3861. printf("Input cmd fail ------ flash [set | write | clean] [cmd] [...]\r\n\r\n");
  3862. }
  3863. void EnableAbnormalRelay(void)
  3864. {
  3865. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = true;
  3866. printf("\r\n");
  3867. printf("Enable Abnormal Relay Cmd\r\n\r\n");
  3868. }
  3869. void DisableAbnormalRelay(void)
  3870. {
  3871. ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay = NO;
  3872. printf("\r\n");
  3873. printf("Disable Abnormal Relay Cmd\r\n\r\n");
  3874. }
  3875. void RelayWriteOutputCmd(char *inputCmd)
  3876. {
  3877. char subMain[MAX_SUB_CMD_LENGTH];
  3878. char subSub[MAX_SUB_CMD_LENGTH];
  3879. memset(subMain, 0x00, sizeof(subMain));
  3880. memset(subSub, 0x00, sizeof(subSub));
  3881. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3882. {
  3883. int value = 0;
  3884. value = atoi(&subMain[0]);
  3885. if(value > 0 && value <= MAX_GUN_QUANTITY && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  3886. {
  3887. int OnOff = 0;
  3888. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  3889. {
  3890. EnableAbnormalRelay();
  3891. }
  3892. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  3893. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_N = OnOff;
  3894. ShmChargerInfo->PsuGrouping.OutputRelayConfig[value - 1].bits.Output_P = OnOff;
  3895. printf("\r\n");
  3896. printf("Write Gun %d OutputRelay %s\r\n\r\n", value, subSub);
  3897. return;
  3898. }
  3899. }
  3900. printf("\r\n");
  3901. printf("Input cmd fail ------ relay [write] [output] [value 1-4] [on | off]\r\n\r\n");
  3902. }
  3903. void RelayWriteParallelCmd(char *inputCmd)
  3904. {
  3905. char subMain[MAX_SUB_CMD_LENGTH];
  3906. char subSub[MAX_SUB_CMD_LENGTH];
  3907. memset(subMain, 0x00, sizeof(subMain));
  3908. memset(subSub, 0x00, sizeof(subSub));
  3909. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3910. {
  3911. int value = 0;
  3912. value = atoi(&subMain[0]);
  3913. if(value > 0 && value <= PARALLEL_RELAY_COUNT && (strcmp(subSub, "on") == 0 || strcmp(subSub, "off") == 0))
  3914. {
  3915. int OnOff = 0;
  3916. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  3917. {
  3918. EnableAbnormalRelay();
  3919. }
  3920. OnOff = strcmp(subSub, "on") == 0 ? YES : NO;
  3921. if(OnOff)
  3922. {
  3923. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << (value - 1);
  3924. }
  3925. else
  3926. {
  3927. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << (value - 1));
  3928. }
  3929. printf("\r\n");
  3930. printf("Write ParallelRelay %d %s\r\n\r\n", value, subSub);
  3931. return;
  3932. }
  3933. }
  3934. printf("\r\n");
  3935. printf("Input cmd fail ------ relay [write] [parallel] [value 1-6] [on | off]\r\n\r\n");
  3936. }
  3937. void AbnormalRelayCmd(char *inputCmd, unsigned int opt)
  3938. {
  3939. char subMain[MAX_SUB_CMD_LENGTH];
  3940. char subSub[MAX_SUB_CMD_LENGTH];
  3941. memset(subMain, 0x00, sizeof(subMain));
  3942. memset(subSub, 0x00, sizeof(subSub));
  3943. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 1)
  3944. {
  3945. if(strcmp(subMain, "enable") == 0)
  3946. {
  3947. EnableAbnormalRelay();
  3948. return;
  3949. }
  3950. if(strcmp(subMain, "disable") == 0)
  3951. {
  3952. DisableAbnormalRelay();
  3953. return;
  3954. }
  3955. }
  3956. printf("\r\n");
  3957. printf("Input cmd fail ------ relay [abnormal] [enable | disable]\r\n\r\n");
  3958. }
  3959. void RelayWriteCmd(char *inputCmd, unsigned int opt)
  3960. {
  3961. char subMain[MAX_SUB_CMD_LENGTH];
  3962. char subSub[MAX_SUB_CMD_LENGTH];
  3963. memset(subMain, 0x00, sizeof(subMain));
  3964. memset(subSub, 0x00, sizeof(subSub));
  3965. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) == 2)
  3966. {
  3967. if(strcmp(subMain, "output") == 0)
  3968. {
  3969. RelayWriteOutputCmd(subSub);
  3970. return;
  3971. }
  3972. if(strcmp(subMain, "parallel") == 0)
  3973. {
  3974. RelayWriteParallelCmd(subSub);
  3975. return;
  3976. }
  3977. }
  3978. printf("\r\n");
  3979. printf("Input cmd fail ------ relay [write] [output | parallel] [value] [on | off]\r\n\r\n");
  3980. }
  3981. void RelayReadCmd(char *inputCmd, unsigned int opt)
  3982. {
  3983. }
  3984. void RelayStatusCmd(char *inputCmd, unsigned int opt)
  3985. {
  3986. }
  3987. void OutputRelayAutoTest(void)
  3988. {
  3989. int MaxGunCount = 0;
  3990. struct timespec _Loop_time;
  3991. int time = 0;
  3992. MaxGunCount = ShmChargerInfo->Control.MaxConnector;
  3993. for(int i = 0; i < MaxGunCount; i++)
  3994. {
  3995. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = YES;
  3996. GetClockTime(&_Loop_time);
  3997. while(1)
  3998. {
  3999. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4000. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4001. {
  4002. printf("Gun %d Output Relay N Driving Check OK\r\n", i + 1);
  4003. break;
  4004. }
  4005. if(time >= 3000)
  4006. {
  4007. printf("Gun %d Output Relay N Driving Check Fault\r\n", i + 1);
  4008. break;
  4009. }
  4010. usleep(10000);
  4011. }
  4012. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = YES;
  4013. GetClockTime(&_Loop_time);
  4014. while(1)
  4015. {
  4016. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4017. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4018. {
  4019. printf("Gun %d Output Relay P Driving Check OK\r\n", i + 1);
  4020. break;
  4021. }
  4022. if(time >= 3000)
  4023. {
  4024. printf("Gun %d Output Relay P Driving Check Fault\r\n", i + 1);
  4025. break;
  4026. }
  4027. usleep(10000);
  4028. }
  4029. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N = NO;
  4030. GetClockTime(&_Loop_time);
  4031. while(1)
  4032. {
  4033. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4034. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_N == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_N)
  4035. {
  4036. printf("Gun %d Output Relay N Welding Check OK\r\n", i + 1);
  4037. break;
  4038. }
  4039. if(time >= 3000)
  4040. {
  4041. printf("Gun %d Output Relay N Welding Check Fault\r\n", i + 1);
  4042. break;
  4043. }
  4044. usleep(10000);
  4045. }
  4046. ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P = NO;
  4047. GetClockTime(&_Loop_time);
  4048. while(1)
  4049. {
  4050. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4051. if(ShmChargerInfo->PsuGrouping.OutputRelayConfig[i].bits.Output_P == ShmChargerInfo->PsuGrouping.OutputRelayConfirmed[i].bits.Output_P)
  4052. {
  4053. printf("Gun %d Output Relay P Welding Check OK\r\n", i + 1);
  4054. break;
  4055. }
  4056. if(time >= 3000)
  4057. {
  4058. printf("Gun %d Output Relay P Welding Check Fault\r\n", i + 1);
  4059. break;
  4060. }
  4061. usleep(10000);
  4062. }
  4063. }
  4064. }
  4065. void ParallelRelayAutoTest(void)
  4066. {
  4067. int ParallelRelayCount = 0;
  4068. struct timespec _Loop_time;
  4069. int time = 0;
  4070. if(ShmChargerInfo->Control.MaxConnector == GENERAL_GUN_QUANTITY)
  4071. {
  4072. ParallelRelayCount = ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 1 ? PARALLEL_RELAY_COUNT : 3;
  4073. }
  4074. else
  4075. {
  4076. ParallelRelayCount = 1;
  4077. }
  4078. for(int i = 0; i < ParallelRelayCount; i++)
  4079. {
  4080. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue |= 1 << i;
  4081. GetClockTime(&_Loop_time);
  4082. while(1)
  4083. {
  4084. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4085. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4086. {
  4087. printf("Location %d Parallel Relay Driving Check OK\r\n", i + 1);
  4088. break;
  4089. }
  4090. if(time >= 3000)
  4091. {
  4092. printf("Location %d Parallel Relay Driving Check Fault\r\n", i + 1);
  4093. break;
  4094. }
  4095. usleep(10000);
  4096. }
  4097. ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue &= ~(1 << i);
  4098. GetClockTime(&_Loop_time);
  4099. while(1)
  4100. {
  4101. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4102. if(ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue == ShmChargerInfo->PsuGrouping.ParallelRelayConfirmed.CtrlValue)
  4103. {
  4104. printf("Location %d Parallel Relay Welding Check OK\r\n", i + 1);
  4105. break;
  4106. }
  4107. if(time >= 3000)
  4108. {
  4109. printf("Location %d Parallel Relay Welding Check Fault\r\n", i + 1);
  4110. break;
  4111. }
  4112. usleep(10000);
  4113. }
  4114. }
  4115. }
  4116. void RelayAutoTest(char *inputCmd)
  4117. {
  4118. if(strcmp(inputCmd, "now") != EQUAL)
  4119. {
  4120. printf("\r\n");
  4121. printf("Input cmd fail ------ relay [autotest] [now]\r\n\r\n");
  4122. return;
  4123. }
  4124. if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
  4125. {
  4126. EnableAbnormalRelay();
  4127. }
  4128. OutputRelayAutoTest();
  4129. ParallelRelayAutoTest();
  4130. printf("Relay Auto Test Completed\r\n");
  4131. DisableAbnormalRelay();
  4132. }
  4133. void RelayCmd(char *inputCmd, unsigned int opt)
  4134. {
  4135. char subMain[MAX_SUB_CMD_LENGTH];
  4136. char subSub[MAX_SUB_CMD_LENGTH];
  4137. memset(subMain, 0x00, sizeof(subMain));
  4138. memset(subSub, 0x00, sizeof(subSub));
  4139. if(MainAndSubCommandParsing(inputCmd, subMain, subSub) >= 2)
  4140. {
  4141. if(strcmp(subMain, "abnormal") == EQUAL)
  4142. {
  4143. AbnormalRelayCmd(subSub, opt);
  4144. return;
  4145. }
  4146. if(strcmp(subMain, "write") == EQUAL)
  4147. {
  4148. RelayWriteCmd(subSub, opt);
  4149. return;
  4150. }
  4151. if(strcmp(subMain, "read") == EQUAL)
  4152. {
  4153. RelayReadCmd(subSub, opt);
  4154. return;
  4155. }
  4156. if(strcmp(subMain, "status") == EQUAL)
  4157. {
  4158. RelayStatusCmd(subSub, opt);
  4159. return;
  4160. }
  4161. if(strcmp(subMain, "autotest") == EQUAL)
  4162. {
  4163. RelayAutoTest(subSub);
  4164. return;
  4165. }
  4166. }
  4167. printf("\r\n");
  4168. printf("Input cmd fail ------ relay [abnormal | write | read | autotest] [...]\r\n\r\n");
  4169. }
  4170. // Sys CurrentRate: [XX.XX]
  4171. // TimeOfDayPrice: [00-01: XX.XX] [01-02: XX.XX] [02-03: XX.XX] [03-04: XX.XX] [04-05: XX.XX] [05-06: XX.XX]
  4172. // : [06-07: XX.XX] [07-08: XX.XX] [08-09: XX.XX] [09-10: XX.XX] [10-11: XX.XX] [11-12: XX.XX]
  4173. // : [12-13: XX.XX] [13-14: XX.XX] [14-15: XX.XX] [15-16: XX.XX] [16-17: XX.XX] [17-18: XX.XX]
  4174. // : [18-19: XX.XX] [19-20: XX.XX] [20-21: XX.XX] [21-22: XX.XX] [22-23: XX.XX] [23-24: XX.XX]
  4175. int ShowSysPriceInfo(void)
  4176. {
  4177. int showLine = 1;
  4178. char priceString[1024];
  4179. //************************************************************************************************
  4180. printf(" Sys CurrentRate: [%5.2f]\r\n", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
  4181. if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
  4182. {
  4183. //************************************************************************************************
  4184. memset(priceString, 0x00, sizeof(priceString));
  4185. for(int i = 0; i < 6; i++)
  4186. {
  4187. char strTemp[64];
  4188. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4189. strcat(priceString, strTemp);
  4190. }
  4191. printf(" TimeOfDayPrice:%s\r\n", priceString);
  4192. //************************************************************************************************
  4193. memset(priceString, 0x00, sizeof(priceString));
  4194. for(int i = 6; i < 12; i++)
  4195. {
  4196. char strTemp[64];
  4197. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4198. strcat(priceString, strTemp);
  4199. }
  4200. printf(" :%s\r\n", priceString);
  4201. //************************************************************************************************
  4202. memset(priceString, 0x00, sizeof(priceString));
  4203. for(int i = 12; i < 18; i++)
  4204. {
  4205. char strTemp[64];
  4206. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4207. strcat(priceString, strTemp);
  4208. }
  4209. printf(" :%s\r\n", priceString);
  4210. //************************************************************************************************
  4211. memset(priceString, 0x00, sizeof(priceString));
  4212. for(int i = 18; i < 24; i++)
  4213. {
  4214. char strTemp[64];
  4215. sprintf(strTemp, " [%02d-%02d: %5.2f]", i, i + 1, ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[i]);
  4216. strcat(priceString, strTemp);
  4217. }
  4218. printf(" :%s\r\n", priceString);
  4219. showLine += 4;
  4220. }
  4221. return showLine;
  4222. }
  4223. // Gun X UserPrice: [%s]
  4224. // Receipt: [%s]
  4225. int ShowGunPriceInfo(int gun)
  4226. {
  4227. int showLine = 2;
  4228. char priceString[1024];
  4229. //************************************************************************************************
  4230. memset(priceString, 0x00, sizeof(priceString));
  4231. if(strlen(&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun][0]) > 0)
  4232. {
  4233. strcpy(priceString, &ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun][0]);
  4234. }
  4235. else
  4236. {
  4237. strcpy(priceString, "NULL");
  4238. }
  4239. printf(" Gun %d UserPrice: [%s]\r\n", gun + 1, priceString);
  4240. //************************************************************************************************
  4241. memset(priceString, 0x00, sizeof(priceString));
  4242. if(strlen(&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun][0]) > 0)
  4243. {
  4244. strcpy(priceString, &ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun][0]);
  4245. }
  4246. else
  4247. {
  4248. strcpy(priceString, "NULL");
  4249. }
  4250. printf(" Receipt: [%s]\r\n", priceString);
  4251. return showLine;
  4252. }
  4253. void ShowPrice(char *inputCmd, unsigned int opt)
  4254. {
  4255. int totalLine = 0;
  4256. bool keepRun = false;
  4257. bool reflash = false;
  4258. int time = 0;
  4259. struct timespec _Loop_time;
  4260. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  4261. {
  4262. keepRun = true;
  4263. }
  4264. do
  4265. {
  4266. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  4267. if(time >= 1000)
  4268. {
  4269. if(reflash)
  4270. {
  4271. ConsoleReflash(1, totalLine);
  4272. }
  4273. totalLine = 0;
  4274. printf("\r\n");
  4275. totalLine += ShowSysPriceInfo() + 1;
  4276. printf("\r\n");
  4277. totalLine += 1;
  4278. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  4279. {
  4280. totalLine += ShowGunPriceInfo(i);
  4281. }
  4282. GetClockTime(&_Loop_time);
  4283. if((opt & OPTION_REFLASH) > 0)
  4284. {
  4285. reflash = true;
  4286. }
  4287. }
  4288. if(keepRun)
  4289. {
  4290. keepRun = IsLoopStopCmd() ? false : true;
  4291. usleep(10000);
  4292. }
  4293. }while(keepRun);
  4294. printf("\r\n");
  4295. }
  4296. int main(void)
  4297. {
  4298. char newString[32][MAX_SUB_CMD_LENGTH];
  4299. char inputString[MAX_SUB_CMD_LENGTH], normalCmd[MAX_SUB_CMD_LENGTH];
  4300. char mainCmd[MAX_SUB_CMD_LENGTH], subCmd[MAX_SUB_CMD_LENGTH], multiCmd[MAX_SUB_CMD_LENGTH];
  4301. int cmdCnt = 0, parseCnt = 0;
  4302. unsigned int option = 0;
  4303. if(InitShareMemory() == FAIL)
  4304. {
  4305. printf ("InitShareMemory = FAIL \n");
  4306. if(ShmStatusCodeData != NULL)
  4307. {
  4308. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4309. }
  4310. sleep(5);
  4311. return 0;
  4312. }
  4313. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  4314. {
  4315. if (!FindChargingInfoData(i, &_chargingData[0]))
  4316. {
  4317. return 0;
  4318. }
  4319. }
  4320. // clean command
  4321. memset(mainCmd, 0x00, sizeof(mainCmd));
  4322. memset(subCmd, 0x00, sizeof(subCmd));
  4323. for(int i = 0; i < 32; i++)
  4324. {
  4325. memset(&newString[i], 0x00, 32);
  4326. }
  4327. for(;;)
  4328. {
  4329. memset(inputString, 0x00, sizeof(inputString));
  4330. memset(normalCmd, 0x00, sizeof(normalCmd));
  4331. get_char(inputString);
  4332. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  4333. if(cmdCnt > 0)
  4334. {
  4335. // clean command
  4336. memset(mainCmd, 0x00, sizeof(mainCmd));
  4337. memset(subCmd, 0x00, sizeof(subCmd));
  4338. for(int i = 0; i < 32; i++)
  4339. {
  4340. memset(&newString[i], 0x00, MAX_SUB_CMD_LENGTH);
  4341. }
  4342. //printf("CmdCnt: %d\r\n", cmdCnt);
  4343. //printf("Input: %s", inputString);
  4344. //printf("Normalize: %s\r\n", normalCmd);
  4345. //printf("option: %08X\r\n", option);
  4346. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  4347. //printf("MainCmd: %s\r\n", mainCmd);
  4348. //printf("SubCmd: %s\r\n", subCmd);
  4349. parseCnt = 0;
  4350. strcpy(multiCmd, normalCmd);
  4351. do
  4352. {
  4353. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  4354. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  4355. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  4356. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  4357. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  4358. parseCnt++;
  4359. }while(parseCnt < cmdCnt - 1);
  4360. //printf("\r\n");
  4361. //for(int i = 0; i < cmdCnt; i++)
  4362. //{
  4363. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  4364. //}
  4365. }
  4366. else
  4367. {
  4368. usleep(100000);
  4369. continue;
  4370. }
  4371. if(strcmp(newString[0], "state") == 0)
  4372. {
  4373. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4374. continue;
  4375. // 槍狀態
  4376. RunStatusProc(newString[1], newString[2]);
  4377. }
  4378. else if(strcmp(newString[0], "card") == 0)
  4379. {
  4380. // 刷卡狀態
  4381. RunCardProc(newString[1], newString[2]);
  4382. }
  4383. else if(strcmp(newString[0], "gun") == 0)
  4384. {
  4385. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4386. continue;
  4387. // 插槍狀態
  4388. RunGunPlugitProc(newString[1], newString[2]);
  4389. }
  4390. else if(strcmp(newString[0], "lock") == 0)
  4391. {
  4392. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4393. continue;
  4394. // 插槍狀態
  4395. GetGunLockStatusProc(newString[1], newString[2]);
  4396. }
  4397. else if(strcmp(newString[0], "sysid") == 0)
  4398. {
  4399. // 測試 sys id
  4400. SetSystemIDProc();
  4401. }
  4402. else if(strcmp(newString[0], "self") == 0)
  4403. {
  4404. // CSU 自我檢測狀態
  4405. RunSelfProc(newString[1]);
  4406. }
  4407. else if(strcmp(newString[0], "ver") == 0)
  4408. {
  4409. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4410. // continue;
  4411. // 取 FW 版號
  4412. //GetFwVerProc(newString[1]);
  4413. ShowFwVer();
  4414. }
  4415. else if (strcmp(newString[0], "update") == 0)
  4416. {
  4417. // 更新
  4418. FwUpdateFlagProc(newString[1]);
  4419. }
  4420. else if (strcmp(newString[0], "ac") == 0)
  4421. {
  4422. // AC contactor 狀態
  4423. CheckAcStatus(newString[1]);
  4424. }
  4425. else if (strcmp(newString[0], "cable") == 0)
  4426. {
  4427. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4428. continue;
  4429. // cable check pass
  4430. SetCableChkStatus(newString[1], newString[2]);
  4431. }
  4432. else if (strcmp(newString[0], "pow") == 0)
  4433. {
  4434. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4435. continue;
  4436. // cable check pass
  4437. SetPowerValue(newString[1], newString[2]);
  4438. }
  4439. else if(strcmp(mainCmd, "model") == 0)
  4440. {
  4441. ModelNameCmd(subCmd, option);
  4442. }
  4443. else if(strcmp(mainCmd, "sn") == 0)
  4444. {
  4445. SerialNumberCmd(subCmd, option);
  4446. }
  4447. else if(strcmp(newString[0], "fan") == 0)
  4448. {
  4449. // 設定風扇速度
  4450. SetFanSpeed(newString[1]);
  4451. }
  4452. else if(strcmp(newString[0], "speed") == 0)
  4453. {
  4454. // 取得風扇速度
  4455. GetFanSpeed();
  4456. }
  4457. else if(strcmp(newString[0], "debug") == 0)
  4458. {
  4459. // 設定 debug mode
  4460. SetDebugMode(newString[1]);
  4461. }
  4462. else if (strcmp(newString[0], "gfd") == 0)
  4463. {
  4464. // 設定盲沖使用 GFD 功能
  4465. SetGFDMode(newString[1]);
  4466. }
  4467. else if(strcmp(mainCmd, "temp") == 0)
  4468. {
  4469. // 取得溫度
  4470. GetTemperature(subCmd, option);
  4471. }
  4472. else if(strcmp(mainCmd, "acin") == 0)
  4473. {
  4474. // 取得三向輸入電壓
  4475. GetInputVol(subCmd, option);
  4476. }
  4477. else if(strcmp(newString[0], "psu") == 0)
  4478. {
  4479. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  4480. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4481. {
  4482. printf ("PSU : Param fail..Please retry again......\n");
  4483. continue;
  4484. }
  4485. // 取得 PSU 資訊
  4486. GetPsuInformation(newString[1], newString[2], newString[3]);
  4487. }
  4488. else if (strcmp(newString[0], "cap") == 0)
  4489. {
  4490. GetConnectorCapInfo(newString[1]);
  4491. }
  4492. else if(strcmp(newString[0], "error") == 0)
  4493. {
  4494. CreateOneError(newString[1]);
  4495. }
  4496. else if (strcmp(newString[0], "auth") == 0)
  4497. {
  4498. GetAuthorizeFlag(newString[1]);
  4499. }
  4500. else if (strcmp(newString[0], "id") == 0)
  4501. {
  4502. GetOrClearId(newString[1]);
  4503. }
  4504. else if(strcmp(newString[0], "wiring") == 0)
  4505. {
  4506. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  4507. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  4508. {
  4509. SetWiringInfo(newString[1], newString[2]);
  4510. }
  4511. ShowWiringInfo();
  4512. }
  4513. else if(strcmp(newString[0], "cwiring") == 0)
  4514. {
  4515. CleanWiringInfo();
  4516. }
  4517. else if(strcmp(newString[0], "reset") == 0)
  4518. {
  4519. SetSystemSoftRest();
  4520. }
  4521. else if(strcmp(newString[0], "reboot") == 0)
  4522. {
  4523. SetSystemHardReboot();
  4524. }
  4525. else if(strcmp(newString[0], "sgroup") == 0)
  4526. {
  4527. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4528. {
  4529. ShowGroupingInfo();
  4530. continue;
  4531. }
  4532. RunSimplePsuGrouping(newString[1], newString[2]);
  4533. }
  4534. else if(strcmp(mainCmd, "cabinet") == 0)
  4535. {
  4536. ShowCabinetInfo(subCmd, option);
  4537. }
  4538. else if(strcmp(newString[0], "tctl") == 0)
  4539. {
  4540. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4541. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4542. {
  4543. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  4544. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  4545. continue;
  4546. }
  4547. SetTestControl(newString[1], newString[2]);
  4548. }
  4549. else if(strcmp(newString[0], "group") == 0)
  4550. {
  4551. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4552. {
  4553. ShowGroupingInfo();
  4554. continue;
  4555. }
  4556. }
  4557. else if(strcmp(newString[0], "gdmd") == 0)
  4558. {
  4559. ShowGroupingDemand();
  4560. }
  4561. else if(strcmp(mainCmd, "gunchg") == 0)
  4562. {
  4563. SetGunStartCharging(subCmd, option, NO);
  4564. }
  4565. else if(strcmp(mainCmd, "webchg") == 0)
  4566. {
  4567. SetGunStartCharging(subCmd, option, YES);
  4568. }
  4569. else if(strcmp(mainCmd, "gunstp") == 0)
  4570. {
  4571. SetGunStopCharging(subCmd, option);
  4572. }
  4573. else if(strcmp(newString[0], "gunext") == 0)
  4574. {
  4575. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4576. {
  4577. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  4578. continue;
  4579. }
  4580. SetGunExtend(newString[1]);
  4581. }
  4582. else if(strcmp(newString[0], "output") == 0)
  4583. {
  4584. ShowGunOutput();
  4585. }
  4586. else if(strcmp(newString[0], "gio") == 0)
  4587. {
  4588. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4589. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4590. {
  4591. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  4592. continue;
  4593. }
  4594. SetGpio(newString[1], newString[2]);
  4595. }
  4596. else if(strcmp(newString[0], "status") == 0)
  4597. {
  4598. ShowStatus();
  4599. }
  4600. else if(strcmp(newString[0], "whiteR") == 0)
  4601. {
  4602. ShowWhiteCardList();
  4603. }
  4604. else if(strcmp(newString[0], "whiteW") == 0)
  4605. {
  4606. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4607. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  4608. {
  4609. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  4610. continue;
  4611. }
  4612. WriteWhiteCard(newString[1], newString[2]);
  4613. }
  4614. else if(strcmp(newString[0], "whiteE") == 0)
  4615. {
  4616. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  4617. {
  4618. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  4619. continue;
  4620. }
  4621. EraseWhiteCard(newString[1]);
  4622. }
  4623. else if(strcmp(mainCmd, "limit") == 0)
  4624. {
  4625. ShowChargerLimit(subCmd, option);
  4626. }
  4627. else if(strcmp(mainCmd, "pcmd") == 0)
  4628. {
  4629. SetPsuCommand(subCmd, option);
  4630. }
  4631. else if(strcmp(newString[0], "gcmd") == 0)
  4632. {
  4633. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  4634. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  4635. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  4636. {
  4637. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  4638. continue;
  4639. }
  4640. SetGunCommand(newString[1], newString[2], newString[3]);
  4641. }
  4642. else if(strcmp(mainCmd, "web") == 0)
  4643. {
  4644. ShowWebInfo(subCmd, option);
  4645. }
  4646. else if(strcmp(mainCmd, "info") == 0)
  4647. {
  4648. ShowInfo(subCmd, option);
  4649. }
  4650. else if(strcmp(mainCmd, "rtcsync") == 0)
  4651. {
  4652. RtcSyncCmd(subCmd, option);
  4653. }
  4654. else if(strcmp(mainCmd, "pmodel") == 0)
  4655. {
  4656. ParsingModelNameCmd(subCmd, option);
  4657. }
  4658. else if(strcmp(mainCmd, "pt") == 0)
  4659. {
  4660. CustomerPriceTest(subCmd, option);
  4661. }
  4662. else if(strcmp(mainCmd, "evmsg") == 0)
  4663. {
  4664. EvCommMsgDebug(subCmd, option);
  4665. }
  4666. else if(strcmp(mainCmd, "evid") == 0)
  4667. {
  4668. EvCommIdDebug(subCmd, option);
  4669. }
  4670. else if(strcmp(mainCmd, "flash") == 0)
  4671. {
  4672. FlashCmd(subCmd, option);
  4673. }
  4674. else if(strcmp(mainCmd, "relay") == 0)
  4675. {
  4676. RelayCmd(subCmd, option);
  4677. }
  4678. else if(strcmp(mainCmd, "price") == 0)
  4679. {
  4680. ShowPrice(subCmd, option);
  4681. }
  4682. else
  4683. {
  4684. printf ("%s\n", msg);
  4685. }
  4686. usleep(100000);
  4687. }
  4688. return 0;
  4689. }