ReadCmdline.c 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912
  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 STR_OPT_REFLASH 'f'
  48. #define STR_OPT_LOOP 'l'
  49. #define STR_OPT_TIME 't'
  50. #define TTY_PATH "/dev/tty"
  51. #define STTY_US "stty raw -echo -F "
  52. #define STTY_DEF "stty -raw echo -F "
  53. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  54. struct StatusCodeData *ShmStatusCodeData;
  55. struct PrimaryMcuData *ShmPrimaryMcuData;
  56. struct CHAdeMOData *ShmCHAdeMOData;
  57. struct CcsData *ShmCcsData;
  58. struct GBTData *ShmGBTData;
  59. struct FanModuleData *ShmFanModuleData;
  60. struct RelayModuleData *ShmRelayModuleData;
  61. struct LedModuleData *ShmLedModuleData;
  62. struct PsuData *ShmPsuData;
  63. ChargerInfoData *ShmChargerInfo;
  64. PsuPositionInfoData *ShmPsuPosition;
  65. PsuGroupingInfoData *ShmPsuGrouping;
  66. struct OCPP16Data *ShmOCPP16Data;
  67. struct OCPP20Data *ShmOCPP20Data;
  68. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  69. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  70. char *msg = "state : get gun state (index) \n"
  71. "card : scanning card (x) : \n"
  72. "gun : get gun plugit state (index) \n"
  73. "lock : get gun locked state (index) \n"
  74. "self : self test state (x) \n"
  75. "ver : ver of board (407 or index or rb or fan) \n"
  76. "ac : get ac relay state (x) \n"
  77. "gunchg: set gun start charging \n"
  78. "gunstp: set gun stop charging \n"
  79. "gunext: extend gun capability \n";
  80. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  81. {
  82. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  83. {
  84. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  85. {
  86. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  87. return true;
  88. }
  89. }
  90. for (byte index = 0; index < CCS_QUANTITY; index++)
  91. {
  92. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  93. {
  94. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  95. return true;
  96. }
  97. }
  98. for (byte index = 0; index < GB_QUANTITY; index++)
  99. {
  100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  101. {
  102. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  103. return true;
  104. }
  105. }
  106. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  107. {
  108. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  109. return true;
  110. }
  111. return false;
  112. }
  113. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  114. {
  115. if (target < AC_QUANTITY)
  116. {
  117. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  118. return true;
  119. }
  120. return false;
  121. }
  122. int InitShareMemory()
  123. {
  124. int result = PASS;
  125. int MeterSMId;
  126. //initial ShmSysConfigAndInfo
  127. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  128. {
  129. result = FAIL;
  130. }
  131. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  132. {
  133. result = FAIL;
  134. }
  135. else
  136. {}
  137. //initial ShmStatusCodeData
  138. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  139. {
  140. result = FAIL;
  141. }
  142. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  143. {
  144. result = FAIL;
  145. }
  146. else
  147. {}
  148. if (CHAdeMO_QUANTITY > 0) {
  149. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  150. IPC_CREAT | 0777)) < 0) {
  151. result = FAIL;
  152. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  153. == (void *) -1) {
  154. result = FAIL;
  155. } else {
  156. }
  157. }
  158. if (CCS_QUANTITY > 0) {
  159. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  160. IPC_CREAT | 0777)) < 0) {
  161. result = FAIL;
  162. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  163. result = FAIL;
  164. } else {
  165. }
  166. }
  167. if (GB_QUANTITY > 0) {
  168. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  169. IPC_CREAT | 0777)) < 0) {
  170. return 0;
  171. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  172. return 0;
  173. }
  174. memset(ShmGBTData, 0, sizeof(struct GBTData));
  175. }
  176. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  177. {
  178. result = FAIL;
  179. }
  180. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  181. {
  182. result = FAIL;
  183. }
  184. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  185. {
  186. result = FAIL;
  187. }
  188. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  189. {
  190. result = FAIL;
  191. }
  192. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  193. {
  194. result = FAIL;
  195. }
  196. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  197. {
  198. result = FAIL;
  199. }
  200. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  201. {
  202. result = FAIL;
  203. }
  204. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  205. {
  206. result = FAIL;
  207. }
  208. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  209. {
  210. result = FAIL;
  211. }
  212. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  213. {
  214. result = FAIL;
  215. }
  216. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  217. {
  218. result = FAIL;
  219. }
  220. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  221. {
  222. result = FAIL;
  223. }
  224. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  225. {
  226. result = FAIL;
  227. }
  228. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  229. {
  230. result = FAIL;
  231. }
  232. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  233. {
  234. result = FAIL;
  235. }
  236. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  237. {
  238. result = FAIL;
  239. }
  240. if(result == PASS)
  241. {
  242. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  243. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  244. }
  245. return result;
  246. }
  247. void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
  248. {
  249. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  250. {
  251. sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  252. return;
  253. }
  254. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  255. {
  256. strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
  257. return;
  258. }
  259. sprintf(transactionId, "%d", 0);
  260. }
  261. static void get_char(char *word)
  262. {
  263. fd_set rfds;
  264. struct timeval tv;
  265. FD_ZERO(&rfds);
  266. FD_SET(0, &rfds);
  267. tv.tv_sec = 0;
  268. tv.tv_usec = 10; //wait input timout time
  269. //if input
  270. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  271. {
  272. fgets(word, 128, stdin);
  273. }
  274. }
  275. // return command length
  276. int ParsingCmd(char *inputString, char *outputString)
  277. {
  278. bool valid = false, done = false;
  279. int len = 0, start = 0;
  280. for(int i = 0; i < strlen(inputString); i++)
  281. {
  282. if(!valid)
  283. {
  284. if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
  285. {
  286. valid = true;
  287. start = i;
  288. }
  289. }
  290. else
  291. {
  292. if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= 32)
  293. {
  294. done = true;
  295. break;
  296. }
  297. }
  298. len = (valid && !done) ? len + 1 : len;
  299. }
  300. if(valid)
  301. {
  302. memcpy(outputString, &inputString[start], len);
  303. outputString[len] = '\0';
  304. }
  305. return len;
  306. }
  307. bool IsOption(char *strCmd, unsigned int *opt)
  308. {
  309. int len = 0;
  310. char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_TIME};
  311. unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_TIME};
  312. len = strlen(strCmd);
  313. if(len == 2)
  314. {
  315. if(strCmd[0] == STR_OPTION)
  316. {
  317. for(int i = 0; i < OPTION_CNT; i++)
  318. {
  319. if(strCmd[1] == str_opt[i])
  320. {
  321. *opt |= opt_value[i];
  322. return true;
  323. }
  324. }
  325. }
  326. }
  327. return false;
  328. }
  329. // inputCmdString: console input string
  330. // outputCmdString: input string parsed
  331. // return command quantity
  332. int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
  333. {
  334. int len = 0, cnt = 0, start = 0;
  335. int cmdLen = 0, totalLen = 0;
  336. len = strlen(inputCmdString);
  337. *opt = 0;
  338. if(len > 0)
  339. {
  340. while(start < len - 1)
  341. {
  342. if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0')
  343. {
  344. cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
  345. if(cmdLen > 0)
  346. {
  347. //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
  348. if(!IsOption(&outputCmdString[totalLen], opt))
  349. {
  350. outputCmdString[totalLen + cmdLen] = ' ';
  351. cnt++;
  352. totalLen += cmdLen + 1;
  353. }
  354. start += cmdLen;
  355. }
  356. }
  357. else
  358. {
  359. start++;
  360. }
  361. }
  362. outputCmdString[totalLen - 1] = '\0';
  363. }
  364. return cnt;
  365. }
  366. int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
  367. {
  368. int len = 0, totalLen = 0;
  369. strcpy(mainCmd, "");
  370. strcpy(subCmd, "");
  371. totalLen = strlen(normalCmd);
  372. if(totalLen > 0)
  373. {
  374. len = ParsingCmd(normalCmd, mainCmd);
  375. //printf("Find MainCmd: %s\r\n", mainCmd);
  376. if(len > 0 && totalLen > len)
  377. {
  378. strcpy(subCmd, &normalCmd[len + 1]);
  379. //printf("Find SubCmd: %s\r\n", subCmd);
  380. }
  381. }
  382. return 0;
  383. }
  384. int GetCommandSring(char *outputCmdString)
  385. {
  386. int len = 0, cnt = 0;
  387. int cmdLen = 0, totalLen = 0;
  388. char word[128];
  389. memset(word, 0x00, sizeof(word));
  390. get_char(word);
  391. len = strlen(word);
  392. if(len == 0)
  393. {
  394. return -1;
  395. }
  396. int start = 0;
  397. while(start < len - 1)
  398. {
  399. if(word[start] != ' ' && word[start] != '\0')
  400. {
  401. cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
  402. char newCmd[32];
  403. memset(newCmd, 0x00, 32);
  404. memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
  405. cnt = cmdLen > 0 ? cnt + 1 : cnt;
  406. totalLen += cmdLen + 1;
  407. start += cmdLen;
  408. }
  409. else
  410. {
  411. start++;
  412. }
  413. }
  414. return cnt;
  415. }
  416. bool IsLoopStopCmd(void)
  417. {
  418. bool stop = false;
  419. int cnt = 0;
  420. char cmd[256];
  421. char totalCmd[256];
  422. memset(cmd, 0x00, 256);
  423. memset(totalCmd, 0x00, 256);
  424. cnt = GetCommandSring(totalCmd);
  425. if(cnt > 0)
  426. {
  427. strcpy(&cmd[0], totalCmd);
  428. if(strcmp(&cmd[0], "c") == 0)
  429. {
  430. stop = true;
  431. }
  432. }
  433. return stop;
  434. }
  435. void ConsoleReflash(int groupCnt, int lineCnt)
  436. {
  437. for(int i = 0; i < groupCnt; i++)
  438. {
  439. for(int i = 0; i < lineCnt; i++)
  440. {
  441. printf("\033[1A");
  442. printf("\033[K");
  443. }
  444. }
  445. printf("\r");
  446. }
  447. void RunStatusProc(char *v1, char *v2)
  448. {
  449. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  450. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  451. if (strcmp(v1, "ac") == 0)
  452. {
  453. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  454. {
  455. printf("FindChargingInfoData (AC) false \n");
  456. }
  457. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  458. return;
  459. }
  460. int _index = atoi(v1);
  461. if (_index <= 1)
  462. {
  463. if (!FindChargingInfoData(_index, &_chargingData[0]))
  464. {
  465. printf ("FindChargingInfoData error\n");
  466. return;
  467. }
  468. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  469. {
  470. // get
  471. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  472. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  473. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  474. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  475. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  476. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  477. }
  478. else
  479. {
  480. // set
  481. _chargingData[_index]->SystemStatus = atoi(v2);
  482. }
  483. }
  484. else
  485. {
  486. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  487. {
  488. printf("FindChargingInfoData (AC) false \n");
  489. }
  490. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  491. {
  492. // get
  493. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  494. }
  495. else
  496. {
  497. // set
  498. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  499. }
  500. }
  501. }
  502. void RunCardProc(char *v1, char *v2)
  503. {
  504. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  505. {
  506. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  507. {
  508. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  509. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  510. }
  511. else
  512. {
  513. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  514. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  515. }
  516. }
  517. else
  518. {
  519. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  520. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  521. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  522. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  523. }
  524. }
  525. void RunGunPlugitProc(char *v1, char *v2)
  526. {
  527. if (strcmp(v1, "ac") == 0)
  528. {
  529. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  530. {
  531. printf("FindChargingInfoData (AC) false \n");
  532. }
  533. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  534. {
  535. // get
  536. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  537. }
  538. else
  539. {
  540. // set
  541. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  542. }
  543. return;
  544. }
  545. int _index = atoi(v1);
  546. if (!FindChargingInfoData(_index, &_chargingData[0]))
  547. {
  548. printf("FindChargingInfoData error\n");
  549. return;
  550. }
  551. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  552. {
  553. // get
  554. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  555. }
  556. else
  557. {
  558. // set
  559. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  560. }
  561. }
  562. void GetGunLockStatusProc(char *v1, char *v2)
  563. {
  564. int _index = atoi(v1);
  565. if (!FindChargingInfoData(_index, &_chargingData[0]))
  566. {
  567. printf("FindChargingInfoData error\n");
  568. return;
  569. }
  570. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  571. {
  572. _chargingData[_index]->GunLocked = atoi(v2);
  573. }
  574. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  575. }
  576. void SetSystemIDProc()
  577. {
  578. char *systemId = "Alston_Test";
  579. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  580. }
  581. void RunSelfProc()
  582. {
  583. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  584. }
  585. void ShowFwVer(void)
  586. {
  587. printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  588. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  589. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
  590. printf("\r\n Csu Kernel: ");
  591. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  592. {
  593. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  594. {
  595. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  596. }
  597. }
  598. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  599. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  600. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  601. printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  602. printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  603. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  604. {
  605. printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  606. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  607. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  608. {
  609. printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
  610. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
  611. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
  612. printf("\r\n Csu Kernel: ");
  613. for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
  614. {
  615. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
  616. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
  617. {
  618. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
  619. }
  620. }
  621. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
  622. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
  623. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
  624. printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
  625. printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
  626. printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
  627. printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
  628. }
  629. }
  630. printf("\r\n\r\n");
  631. }
  632. void GetFwVerProc(char *v1)
  633. {
  634. if (strcmp(v1, "407") == 0)
  635. {
  636. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  637. }
  638. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  639. {
  640. int _index = atoi(v1);
  641. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  642. {
  643. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  644. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  645. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  646. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  647. {
  648. if(ParentIndex == 0)
  649. {
  650. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  651. }
  652. else
  653. {
  654. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  655. }
  656. }
  657. }
  658. else
  659. {
  660. printf("Gun %d is disable\r\n", _index);
  661. }
  662. }
  663. else if (strcmp(v1, "rb") == 0)
  664. {
  665. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  666. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  667. }
  668. else if (strcmp(v1, "fan") == 0)
  669. {
  670. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  671. }
  672. else if (strcmp(v1, "dc") == 0)
  673. {
  674. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  675. }
  676. else if (strcmp(v1, "led") == 0)
  677. {
  678. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  679. }
  680. }
  681. void CreateOneError(char *v1)
  682. {
  683. int value = atoi(v1);
  684. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  685. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  686. }
  687. void GetAuthorizeFlag(char *v1)
  688. {
  689. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  690. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  691. else
  692. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  693. }
  694. void GetOrClearId(char *v1)
  695. {
  696. int _index = atoi(v1);
  697. if (!FindChargingInfoData(_index, &_chargingData[0]))
  698. {
  699. printf("FindChargingInfoData error\n");
  700. return;
  701. }
  702. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  703. }
  704. void FwUpdateFlagProc()
  705. {
  706. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  707. }
  708. void CheckAcStatus(char *v1)
  709. {
  710. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  711. {
  712. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  713. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  714. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  715. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  716. }
  717. else
  718. {
  719. if(system("pidof -s main > /dev/null") != 0)
  720. {
  721. if(strcmp(v1, "0") == 0)
  722. {
  723. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  724. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  725. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  726. printf("Set AC Contactor Off\r\n");
  727. }
  728. else
  729. {
  730. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  731. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  732. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  733. printf("Set AC Contactor On\r\n");
  734. }
  735. }
  736. else
  737. {
  738. printf("main task is running\r\n");
  739. }
  740. }
  741. }
  742. void SetCableChkStatus(char *v1, char *v2)
  743. {
  744. int _index = atoi(v1);
  745. if (!FindChargingInfoData(_index, &_chargingData[0]))
  746. {
  747. printf ("FindChargingInfoData error\n");
  748. return;
  749. }
  750. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  751. }
  752. void SetPowerValue(char *v1, char *v2)
  753. {
  754. int _index = atoi(v1);
  755. float _Current = atof(v2);
  756. // 盲沖的時候才允許使用~
  757. if (_chargingData[_index]->Type != 9)
  758. return;
  759. if (!FindChargingInfoData(_index, &_chargingData[0]))
  760. {
  761. printf ("FindChargingInfoData error\n");
  762. return;
  763. }
  764. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  765. }
  766. void GetSystemInfo()
  767. {
  768. printf ("\r\n ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  769. printf ("\r\nSerialNumber = %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  770. printf ("\r\nInternetConn = %d", ShmSysConfigAndInfo->SysInfo.InternetConn);
  771. printf ("\r\nMaxChargingPower = %d kW, MaxChargingCurrent = %d A",
  772. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  773. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  774. printf("\r\n\r\n");
  775. }
  776. void SetFanSpeed(char *v1)
  777. {
  778. int speed = atoi(v1);
  779. ShmFanModuleData->TestFanSpeed = speed;
  780. }
  781. void GetFanSpeed()
  782. {
  783. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  784. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  785. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  786. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  787. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  788. }
  789. void SetDebugMode(char *v1)
  790. {
  791. int mode = atoi(v1);
  792. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  793. }
  794. void SetGFDMode(char *v1)
  795. {
  796. int mode = atoi(v1);
  797. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  798. }
  799. // PSU 0 PSU 1 PSU 2 ...
  800. // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
  801. // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
  802. void GetTemperature(char *inputCmd, unsigned int opt)
  803. {
  804. bool keepRun = false;
  805. bool reflash = false;
  806. int time = 0;
  807. struct timespec _Loop_time;
  808. char strGunTemp[16], strChillerTemp[16];
  809. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  810. {
  811. keepRun = true;
  812. }
  813. printf("\r\n");
  814. printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
  815. printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
  816. do
  817. {
  818. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  819. if(time >= 1000)
  820. {
  821. if(reflash)
  822. {
  823. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  824. }
  825. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  826. {
  827. sprintf(strGunTemp, "N/A");
  828. sprintf(strChillerTemp, "N/A");
  829. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  830. {
  831. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  832. }
  833. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  834. {
  835. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  836. }
  837. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  838. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  839. {
  840. printf(" %3d/%3d/%3d",
  841. ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
  842. ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
  843. ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
  844. }
  845. printf("\r\n");
  846. }
  847. GetClockTime(&_Loop_time);
  848. if((opt & OPTION_REFLASH) > 0)
  849. {
  850. reflash = true;
  851. }
  852. }
  853. if(keepRun)
  854. {
  855. keepRun = IsLoopStopCmd() ? false : true;
  856. usleep(10000);
  857. }
  858. }while(keepRun);
  859. }
  860. void GetInputVol(char *inputCmd, unsigned int opt)
  861. {
  862. bool keepRun = false;
  863. bool reflash = false;
  864. int time = 0;
  865. struct timespec _Loop_time;
  866. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  867. {
  868. keepRun = true;
  869. }
  870. printf("\r\n");
  871. do
  872. {
  873. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  874. if(time >= 1000)
  875. {
  876. if(reflash)
  877. {
  878. ConsoleReflash(1, 1);
  879. }
  880. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  881. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  882. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  883. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  884. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  885. GetClockTime(&_Loop_time);
  886. if((opt & OPTION_REFLASH) > 0)
  887. {
  888. reflash = true;
  889. }
  890. }
  891. if(keepRun)
  892. {
  893. keepRun = IsLoopStopCmd() ? false : true;
  894. usleep(10000);
  895. }
  896. }while(keepRun);
  897. printf("\r\n");
  898. }
  899. void GetPsuInformation(char *v1, char *v2, char *v3)
  900. {
  901. printf("**********************AC Contact needed*************************\n");
  902. if(strcmp(v1, "count") == 0)
  903. {
  904. for (int i = 0; i < 4; i++)
  905. {
  906. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  907. }
  908. }
  909. else if(strcmp(v1, "ver") == 0)
  910. {
  911. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  912. {
  913. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  914. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  915. }
  916. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  917. {
  918. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  919. {
  920. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  921. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  922. }
  923. }
  924. }
  925. else if(strcmp(v1, "cap") == 0)
  926. {
  927. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  928. {
  929. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  930. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  931. }
  932. }
  933. else if(strcmp(v1, "input") == 0)
  934. {
  935. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  936. {
  937. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  938. {
  939. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  940. i, count,
  941. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  942. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  943. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  944. }
  945. }
  946. }
  947. else if (strcmp(v1, "output") == 0)
  948. {
  949. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  950. {
  951. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  952. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  953. }
  954. }
  955. else if (strcmp(v1, "test") == 0)
  956. {
  957. int mode = atoi(v2);
  958. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  959. {
  960. ShmPsuData->Work_Step = mode;
  961. }
  962. }
  963. else if (strcmp(v1, "out") == 0)
  964. {
  965. float vol = atof(v2);
  966. float cur = atof(v3);
  967. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  968. {
  969. if (!FindChargingInfoData(0, &_chargingData[0]))
  970. {
  971. printf ("FindChargingInfoData error\n");
  972. return;
  973. }
  974. _chargingData[0]->EvBatterytargetVoltage = vol;
  975. _chargingData[0]->EvBatterytargetCurrent = cur;
  976. }
  977. }
  978. printf("*************************************************\n");
  979. }
  980. void GetConnectorCapInfo(char *v1)
  981. {
  982. int _GunIndex = atoi(v1);
  983. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  984. {
  985. printf ("FindChargingInfoData error\n");
  986. return;
  987. }
  988. printf ("Charger Max Current = %d, Max Power = %d \n",
  989. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  990. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  991. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  992. _GunIndex,
  993. _chargingData[_GunIndex]->RealMaxPower,
  994. _chargingData[_GunIndex]->RealMaxVoltage,
  995. _chargingData[_GunIndex]->RealMaxCurrent);
  996. }
  997. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  998. {
  999. int _GunIndex = atoi(v1);
  1000. float _Voltage = atof(v2);
  1001. float _Current = atof(v3);
  1002. unsigned char PreviousSystemStatus = 0xff;
  1003. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1004. {
  1005. printf ("FindChargingInfoData error\n");
  1006. return;
  1007. }
  1008. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  1009. if(_Voltage > 1000 || _Voltage < 50)
  1010. {
  1011. printf ("Input Voltage over range\n");
  1012. return;
  1013. }
  1014. // if(_Current > 100 || _Current < 2){
  1015. //
  1016. // printf ("Input Current over range\n");
  1017. // return;
  1018. // }
  1019. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1020. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1021. //kill ev task
  1022. system("killall Module_EvComm");
  1023. //_Voltage = (_Voltage * 10);
  1024. //_Current = (_Current * 10);
  1025. //system(STTY_US TTY_PATH);
  1026. while(true)
  1027. {
  1028. //fix gun 1
  1029. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1030. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1031. {
  1032. case S_IDLE:
  1033. {
  1034. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1035. {
  1036. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1037. printf ("[UnconditionalCharge - S_IDLE]\n");
  1038. }
  1039. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  1040. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  1041. }
  1042. break;
  1043. case S_PREPARNING:
  1044. {
  1045. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1046. {
  1047. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1048. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1049. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1050. printf ("wait find module\n");
  1051. }
  1052. //main 會在此階段判斷以下資料跳到下一個 state
  1053. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1054. //ShmPsuData->SystemPresentPsuQuantity;
  1055. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1056. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1057. //_chargingData[gun_index]->AvailableChargingPower;
  1058. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1059. //sleep(10);
  1060. //清除 main timeout 機制
  1061. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1062. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1063. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1064. }
  1065. break;
  1066. case S_PREPARING_FOR_EV:
  1067. {
  1068. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1069. {
  1070. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1071. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  1072. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1073. }
  1074. //清除 main timeout 機制
  1075. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1076. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1077. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1078. //充電電壓電流
  1079. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1080. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1081. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1082. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1083. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1084. //確定模組己升壓完成
  1085. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1086. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1087. {
  1088. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1089. //EV done
  1090. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  1091. }
  1092. }
  1093. break;
  1094. case S_PREPARING_FOR_EVSE:
  1095. {
  1096. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1097. {
  1098. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1099. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  1100. }
  1101. //printf ("tar vol = %d \n", _Voltage);
  1102. //printf ("tar cur = %d \n", _Current);
  1103. //清除 main timeout 機制
  1104. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1105. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1106. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1107. //充電電壓電流
  1108. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1109. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1110. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1111. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1112. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1113. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1114. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1115. //確定模組己升壓完成
  1116. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  1117. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  1118. //{
  1119. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1120. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1121. sleep(5);
  1122. //EV done
  1123. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  1124. //}
  1125. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  1126. //{
  1127. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1128. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1129. //}
  1130. }
  1131. break;
  1132. case S_CHARGING:
  1133. {
  1134. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1135. {
  1136. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1137. //充電電壓電流
  1138. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1139. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  1140. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  1141. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1142. printf ("[UnconditionalCharge - S_CHARGING]\n");
  1143. }
  1144. //ev task do this
  1145. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  1146. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  1147. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  1148. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1149. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1150. }
  1151. }
  1152. break;
  1153. case S_TERMINATING:
  1154. {
  1155. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1156. {
  1157. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1158. system("/root/Module_EvComm &");
  1159. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  1160. //無阻塞偵測 keybaord 結束
  1161. system(STTY_DEF TTY_PATH);
  1162. }
  1163. sleep(3);
  1164. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  1165. return;
  1166. }
  1167. break;
  1168. case S_COMPLETE:
  1169. {
  1170. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1171. {
  1172. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1173. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  1174. }
  1175. sleep(3);
  1176. return;
  1177. }
  1178. break;
  1179. }
  1180. char word[128];
  1181. char newString[7][10];
  1182. int i,j,ctr;
  1183. memset(word, 0x00, sizeof(word));
  1184. get_char(word);
  1185. if (strlen(word) == 0)
  1186. {
  1187. continue;
  1188. }
  1189. j=0; ctr=0;
  1190. strcpy(newString[1], "-1");
  1191. strcpy(newString[2], "-1");
  1192. for (i = 0; i <= (strlen(word)); i++)
  1193. {
  1194. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1195. {
  1196. newString[ctr][j] = '\0';
  1197. ctr++;
  1198. j = 0;
  1199. }
  1200. else
  1201. {
  1202. newString[ctr][j] = word[i];
  1203. j++;
  1204. }
  1205. }
  1206. if(strcmp(newString[0], "chg") == 0)
  1207. {
  1208. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1209. continue;
  1210. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1211. continue;
  1212. float _vol = atof(newString[1]);
  1213. float _cur = atof(newString[2]);
  1214. if (_cur <= 0 || _cur <= 0)
  1215. continue;
  1216. printf("vol = %f, cur = %f \n", _vol, _cur);
  1217. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  1218. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  1219. }
  1220. else if (strcmp(newString[0], "c") == 0)
  1221. {
  1222. printf("stop \n\r");
  1223. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  1224. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1225. }
  1226. usleep(100000);
  1227. }
  1228. }
  1229. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  1230. {
  1231. float _Voltage[2], _Current[2];
  1232. _Voltage[0] = atof(v1);
  1233. _Current[0] = atof(v2);
  1234. _Voltage[1] = atof(v3);
  1235. _Current[1] = atof(v4);
  1236. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  1237. if(!FindChargingInfoData(0, &_chargingData[0]))
  1238. {
  1239. printf ("FindChargingInfoData 0 error\n");
  1240. return;
  1241. }
  1242. if(!FindChargingInfoData(1, &_chargingData[0]))
  1243. {
  1244. printf ("FindChargingInfoData 1 error\n");
  1245. return;
  1246. }
  1247. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  1248. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  1249. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  1250. {
  1251. printf ("Input Voltage over range\n");
  1252. return;
  1253. }
  1254. //kill ev task
  1255. system("killall Module_EvComm");
  1256. while(true)
  1257. {
  1258. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  1259. {
  1260. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  1261. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  1262. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1263. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1264. }
  1265. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  1266. {
  1267. system(STTY_DEF TTY_PATH);
  1268. sleep(5);
  1269. return;
  1270. }
  1271. for(int i = 0; i < 2; i++)
  1272. {
  1273. switch(_chargingData[i]->SystemStatus)
  1274. {
  1275. case S_IDLE:
  1276. {
  1277. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1278. {
  1279. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1280. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  1281. }
  1282. }
  1283. break;
  1284. case S_PREPARNING:
  1285. {
  1286. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1287. {
  1288. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1289. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1290. printf ("wait find module\n");
  1291. }
  1292. //清除 main timeout 機制
  1293. _chargingData[i]->TimeoutFlag = 0;
  1294. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1295. _chargingData[i]->Type = 9;
  1296. }
  1297. break;
  1298. case S_PREPARING_FOR_EV:
  1299. {
  1300. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1301. {
  1302. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1303. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1304. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1305. }
  1306. //清除 main timeout 機制
  1307. _chargingData[i]->TimeoutFlag = 0;
  1308. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1309. _chargingData[i]->Type = 9;
  1310. //充電電壓電流
  1311. _chargingData[i]->EvBatterySoc = 50;
  1312. _chargingData[i]->EvBatterytargetVoltage = 500;
  1313. _chargingData[i]->EvBatterytargetCurrent = 2;
  1314. _chargingData[i]->AvailableChargingCurrent = 1000;
  1315. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1316. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1317. }
  1318. break;
  1319. case S_PREPARING_FOR_EVSE:
  1320. {
  1321. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1322. {
  1323. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1324. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1325. }
  1326. //清除 main timeout 機制
  1327. _chargingData[i]->TimeoutFlag = 0;
  1328. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1329. _chargingData[i]->Type = 9;
  1330. //充電電壓電流
  1331. _chargingData[i]->EvBatterySoc = 50;
  1332. _chargingData[i]->EvBatterytargetVoltage = 500;
  1333. _chargingData[i]->EvBatterytargetCurrent = 2;
  1334. _chargingData[i]->AvailableChargingCurrent = 1000;
  1335. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1336. sleep(5);
  1337. //EV done
  1338. _chargingData[i]->SystemStatus = S_CHARGING;
  1339. }
  1340. break;
  1341. case S_CHARGING:
  1342. {
  1343. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1344. {
  1345. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1346. //充電電壓電流
  1347. _chargingData[i]->EvBatterySoc = 50;
  1348. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1349. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1350. _chargingData[i]->AvailableChargingCurrent = 1000;
  1351. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1352. }
  1353. }
  1354. break;
  1355. case S_TERMINATING:
  1356. {
  1357. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1358. {
  1359. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1360. system("/root/Module_EvComm &");
  1361. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1362. }
  1363. sleep(3);
  1364. _chargingData[i]->SystemStatus = S_COMPLETE;
  1365. }
  1366. break;
  1367. case S_COMPLETE:
  1368. {
  1369. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1370. {
  1371. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1372. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1373. }
  1374. }
  1375. break;
  1376. }
  1377. }
  1378. char word[128];
  1379. char newString[7][10];
  1380. int i,j,ctr;
  1381. memset(word, 0x00, sizeof(word));
  1382. get_char(word);
  1383. if (strlen(word) == 0)
  1384. {
  1385. continue;
  1386. }
  1387. j=0; ctr=0;
  1388. strcpy(newString[1], "-1");
  1389. strcpy(newString[2], "-1");
  1390. for (i = 0; i <= (strlen(word)); i++)
  1391. {
  1392. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1393. {
  1394. newString[ctr][j] = '\0';
  1395. ctr++;
  1396. j = 0;
  1397. }
  1398. else
  1399. {
  1400. newString[ctr][j] = word[i];
  1401. j++;
  1402. }
  1403. }
  1404. if(strcmp(newString[0], "chg") == 0)
  1405. {
  1406. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1407. continue;
  1408. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1409. continue;
  1410. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1411. continue;
  1412. int _gun = atoi(newString[1]);
  1413. float _vol = atof(newString[2]);
  1414. float _cur = atof(newString[3]);
  1415. if(_gun >= 2 || _gun < 0)
  1416. continue;
  1417. if (_cur <= 0 || _cur <= 0)
  1418. continue;
  1419. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1420. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1421. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1422. }
  1423. else if (strcmp(newString[0], "c") == 0)
  1424. {
  1425. printf("stop \n\r");
  1426. _chargingData[0]->SystemStatus = S_TERMINATING;
  1427. _chargingData[1]->SystemStatus = S_TERMINATING;
  1428. }
  1429. usleep(100000);
  1430. }
  1431. }
  1432. void SetWiringInfo(char *v1, char *v2)
  1433. {
  1434. int dispenser = atoi(v1);
  1435. int connector = atoi(v2);
  1436. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1437. {
  1438. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1439. {
  1440. printf("\r\n");
  1441. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1442. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1443. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1444. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1445. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1446. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1447. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1448. }
  1449. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1450. {
  1451. printf("\r\n");
  1452. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1453. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1454. int quantity = 0;
  1455. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1456. {
  1457. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1458. }
  1459. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1460. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1461. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1462. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1463. }
  1464. }
  1465. }
  1466. void ShowWiringInfo(void)
  1467. {
  1468. printf("\r\n");
  1469. printf("********** Wiring Info **********\r\n");
  1470. printf("Dispenser = %d, Connector = %d\r\n",
  1471. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1472. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1473. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1474. {
  1475. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1476. {
  1477. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1478. }
  1479. }
  1480. printf("\r\n");
  1481. }
  1482. void CleanWiringInfo(void)
  1483. {
  1484. printf("\r\n");
  1485. printf("******* Clean Wiring Info *******\r\n");
  1486. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1487. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1488. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
  1489. printf("\r\n");
  1490. }
  1491. void SetSystemSoftRest(void)
  1492. {
  1493. printf("********* Set Soft Reset ********\r\n");
  1494. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1495. }
  1496. void SetSystemHardReboot(void)
  1497. {
  1498. printf("******** Set Hard Reboot ********\r\n");
  1499. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1500. }
  1501. void SetGroupRole(byte group, byte role)
  1502. {
  1503. if(group < GENERAL_GUN_QUANTITY)
  1504. {
  1505. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1506. {
  1507. //printf("\r\nSet Group %d Role = %d", group, role);
  1508. }
  1509. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1510. }
  1511. }
  1512. void SetGroupToIdle(byte group)
  1513. {
  1514. if(group < GENERAL_GUN_QUANTITY)
  1515. {
  1516. SetGroupRole(group, _GROLE_IDLE);
  1517. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1518. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1519. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1520. //printf("\r\n Reset Group %02X To Idle", group);
  1521. }
  1522. }
  1523. void SetGroupToMaster(byte group)
  1524. {
  1525. if(group < GENERAL_GUN_QUANTITY)
  1526. {
  1527. SetGroupRole(group, _GROLE_MASTER);
  1528. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1529. //printf("\r\n Set Group %02X As Master", group);
  1530. }
  1531. }
  1532. void SetGroupToSlave(byte group, byte target)
  1533. {
  1534. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1535. {
  1536. SetGroupRole(group, _GROLE_SLAVE);
  1537. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1538. //printf("\r\n Set Group %02X As Slave", group);
  1539. }
  1540. }
  1541. // group: group index, target: target index
  1542. // add group to target's member
  1543. void AddGroupCollection(byte group, byte target)
  1544. {
  1545. int ParallelConfig = 0;
  1546. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1547. {
  1548. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1549. {
  1550. return;
  1551. }
  1552. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1553. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1554. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1555. {
  1556. return;
  1557. }
  1558. SetGroupToSlave(group, target);
  1559. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1560. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1561. if(ParallelConfig != 0)
  1562. {
  1563. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1564. }
  1565. //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);
  1566. }
  1567. }
  1568. // group: group index, target: target index
  1569. // remove group out of target's member
  1570. void RemoveGroupCollection(byte group, byte target)
  1571. {
  1572. int location = 0, slave = 0;
  1573. bool find = false;
  1574. int ParallelConfig = 0;
  1575. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1576. {
  1577. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1578. {
  1579. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1580. {
  1581. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1582. location = i;
  1583. find = true;
  1584. break;
  1585. }
  1586. }
  1587. if(find)
  1588. {
  1589. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1590. {
  1591. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1592. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1593. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1594. }
  1595. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1596. SetGroupToIdle(group);
  1597. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1598. if(ParallelConfig != 0)
  1599. {
  1600. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1601. }
  1602. //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);
  1603. }
  1604. }
  1605. }
  1606. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1607. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1608. void ShowGroupingInfo(void)
  1609. {
  1610. byte target = 0;
  1611. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1612. for(int i = 0; i < 4; i++)
  1613. {
  1614. target = ShmPsuGrouping->Layout[i];
  1615. printf("\r\n %d (%2d) %2d %d %02X ",
  1616. target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
  1617. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
  1618. for(int j = 0; j < 3; j++)
  1619. {
  1620. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
  1621. {
  1622. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
  1623. }
  1624. else
  1625. {
  1626. printf(" ");
  1627. }
  1628. }
  1629. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1630. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1631. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1632. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1633. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1634. }
  1635. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1636. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1637. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1638. printf("\r\n\r\n");
  1639. }
  1640. void PsuGroupSwitchToIdle(byte group)
  1641. {
  1642. int master = 0, quantity = 0, location = 0, total = 0;
  1643. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1644. {
  1645. return;
  1646. }
  1647. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1648. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1649. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1650. for(int i = 0; i < quantity; i++)
  1651. {
  1652. if(total == 0)
  1653. {
  1654. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1655. {
  1656. location = i;
  1657. total++;
  1658. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1659. }
  1660. }
  1661. else
  1662. {
  1663. // find other group in the same direction
  1664. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1665. {
  1666. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1667. {
  1668. total++;
  1669. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1670. }
  1671. }
  1672. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1673. {
  1674. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1675. {
  1676. total++;
  1677. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. if(total > 0)
  1683. {
  1684. unsigned char collection[GENERAL_GUN_QUANTITY];
  1685. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1686. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1687. for(int i = 0; i < total; i++)
  1688. {
  1689. //printf(" %02X", collection[i + location]);
  1690. }
  1691. for(int i = 0; i < total; i++)
  1692. {
  1693. RemoveGroupCollection(collection[i + location], master);
  1694. }
  1695. }
  1696. }
  1697. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1698. {
  1699. int slave = 0, location = 0;
  1700. PsuGroupPartner partner;
  1701. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1702. // search from left
  1703. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1704. for(int i = location; i >= 0; i--)
  1705. {
  1706. if(partner.Quantity >= quantity)
  1707. {
  1708. break;
  1709. }
  1710. slave = ShmPsuGrouping->Layout[i];
  1711. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1712. {
  1713. //printf("\r\n Find Group %02X From Left", slave);
  1714. partner.Member[partner.Quantity++] = slave;
  1715. }
  1716. else
  1717. {
  1718. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1719. {
  1720. continue;
  1721. }
  1722. break;
  1723. }
  1724. }
  1725. // search from right
  1726. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1727. for(int i = location; i < 4; i++)
  1728. {
  1729. if(partner.Quantity >= quantity)
  1730. {
  1731. break;
  1732. }
  1733. slave = ShmPsuGrouping->Layout[i];
  1734. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1735. {
  1736. //printf("\r\n Find Group %02X From Right", slave);
  1737. partner.Member[partner.Quantity++] = slave;
  1738. }
  1739. else
  1740. {
  1741. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1742. {
  1743. continue;
  1744. }
  1745. break;
  1746. }
  1747. }
  1748. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1749. }
  1750. int GetPsuGroupAvailable(byte group)
  1751. {
  1752. //int slave = 0, location = 0, available = 0;
  1753. PsuGroupPartner partner;
  1754. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1755. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1756. return partner.Quantity;
  1757. #if 0
  1758. // search from left
  1759. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1760. for(int i = location; i >= 0; i--)
  1761. {
  1762. slave = ShmPsuGrouping->Layout[i];
  1763. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1764. {
  1765. available++;
  1766. }
  1767. else
  1768. {
  1769. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1770. {
  1771. continue;
  1772. }
  1773. break;
  1774. }
  1775. }
  1776. // search from right
  1777. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1778. for(int i = location; i < 4; i++)
  1779. {
  1780. slave = ShmPsuGrouping->Layout[i];
  1781. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1782. {
  1783. available++;
  1784. }
  1785. else
  1786. {
  1787. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1788. {
  1789. continue;
  1790. }
  1791. break;
  1792. }
  1793. }
  1794. return available;
  1795. #endif
  1796. }
  1797. void PsuGroupShareCheck(byte group)
  1798. {
  1799. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1800. total = GetPsuGroupAvailable(group) + 1;
  1801. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1802. // search from left
  1803. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1804. for(int i = location; i >= 0; i--)
  1805. {
  1806. slave = ShmPsuGrouping->Layout[i];
  1807. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1808. {
  1809. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1810. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1811. {
  1812. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1813. }
  1814. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1815. break;
  1816. }
  1817. else
  1818. {
  1819. break;
  1820. }
  1821. }
  1822. if(share == 0)
  1823. {
  1824. // search from right
  1825. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1826. for(int i = location; i < 4; i++)
  1827. {
  1828. slave = ShmPsuGrouping->Layout[i];
  1829. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1830. {
  1831. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1832. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1833. {
  1834. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1835. }
  1836. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1837. break;
  1838. }
  1839. else
  1840. {
  1841. break;
  1842. }
  1843. }
  1844. }
  1845. if(share > 0)
  1846. {
  1847. //printf("\r\n Grab %02X", slave);
  1848. PsuGroupSwitchToIdle(slave);
  1849. }
  1850. else
  1851. {
  1852. //printf("\r\n No Need To Grab");
  1853. }
  1854. }
  1855. void SimplePsuGroupStartCharging(byte group)
  1856. {
  1857. //int slave = 0, location = 0;
  1858. int available = 0;
  1859. PsuGroupPartner partner;
  1860. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1861. {
  1862. return;
  1863. }
  1864. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1865. {
  1866. return;
  1867. }
  1868. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1869. {
  1870. SetGroupToMaster(group);
  1871. PsuGroupShareCheck(group);
  1872. }
  1873. else
  1874. {
  1875. available = GetPsuGroupAvailable(group);
  1876. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1877. if(available == 0)
  1878. {
  1879. return;
  1880. }
  1881. }
  1882. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1883. for(int i = 0; i < partner.Quantity; i++)
  1884. {
  1885. AddGroupCollection(partner.Member[i], group);
  1886. }
  1887. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1888. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1889. #if 0
  1890. // search from left
  1891. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1892. for(int i = location; i >= 0; i--)
  1893. {
  1894. slave = ShmPsuGrouping->Layout[i];
  1895. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1896. {
  1897. //printf("\r\n Find %02X From Left", slave);
  1898. AddGroupCollection(slave, group);
  1899. }
  1900. else
  1901. {
  1902. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1903. {
  1904. continue;
  1905. }
  1906. break;
  1907. }
  1908. }
  1909. // search from right
  1910. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1911. for(int i = location; i < 4; i++)
  1912. {
  1913. slave = ShmPsuGrouping->Layout[i];
  1914. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1915. {
  1916. //printf("\r\n Find %02X From Right", slave);
  1917. AddGroupCollection(slave, group);
  1918. }
  1919. else
  1920. {
  1921. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1922. {
  1923. continue;
  1924. }
  1925. break;
  1926. }
  1927. }
  1928. #endif
  1929. }
  1930. void PsuGroupStopCharging(byte group)
  1931. {
  1932. int total = 0;
  1933. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1934. {
  1935. return;
  1936. }
  1937. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  1938. if(total > 0)
  1939. {
  1940. unsigned char collection[GENERAL_GUN_QUANTITY];
  1941. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  1942. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1943. for(int i = 0; i < total; i++)
  1944. {
  1945. //printf(" %02X", collection[i]);
  1946. }
  1947. for(int i = 0; i < total; i++)
  1948. {
  1949. RemoveGroupCollection(collection[i], group);
  1950. }
  1951. }
  1952. SetGroupToIdle(group);
  1953. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1954. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1955. }
  1956. void RunSimplePsuGrouping(char *v1, char *v2)
  1957. {
  1958. int group = 0, charging = 0;
  1959. group = atoi(v1);
  1960. charging = atoi(v2);
  1961. group -= 1;
  1962. if(group >= 0 && group < 4)
  1963. {
  1964. if(charging > 0)
  1965. {
  1966. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1967. {
  1968. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1969. PsuGroupSwitchToIdle(group);
  1970. }
  1971. SimplePsuGroupStartCharging(group);
  1972. }
  1973. if(charging == 0)
  1974. {
  1975. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  1976. {
  1977. PsuGroupStopCharging(group);
  1978. }
  1979. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1980. {
  1981. PsuGroupSwitchToIdle(group);
  1982. }
  1983. }
  1984. ShowGroupingInfo();
  1985. }
  1986. }
  1987. void ShowCabinetInfo(void)
  1988. {
  1989. int ipAddress = 0;
  1990. printf("\r\n");
  1991. printf("Psu Work Step = %d, PsuComm: %d\r\n", ShmPsuData->Work_Step, ShmChargerInfo->Control.CommInfo.PsuComm.CommCnt);
  1992. printf("Psu RxCnt: %d\r\n", ShmChargerInfo->Control.CommInfo.PsuComm.RxCnt);
  1993. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  1994. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1995. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1996. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1997. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1998. printf("\r\n");
  1999. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2000. {
  2001. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  2002. printf(" Dispenser Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  2003. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  2004. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  2005. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2006. }
  2007. printf("\r\n");
  2008. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2009. {
  2010. printf(" Connector[%d] Index: %2X, Status = %2d , %s\r\n", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
  2011. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? "Enable" : "Disable");
  2012. }
  2013. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  2014. {
  2015. printf(" Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  2016. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  2017. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  2018. {
  2019. ipAddress = 0;
  2020. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  2021. {
  2022. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
  2023. i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
  2024. {
  2025. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
  2026. }
  2027. }
  2028. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
  2029. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2030. for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
  2031. {
  2032. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j];
  2033. printf(" - Connector[%d] Gun %d, %s\r\n", j, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  2034. }
  2035. }
  2036. else
  2037. {
  2038. printf(", No Information\r\n");
  2039. }
  2040. }
  2041. printf("\r\n");
  2042. }
  2043. void SetTestControl(char *v1, char *v2)
  2044. {
  2045. int testItem = 0;
  2046. int testItemLen = 3;
  2047. int enable = 0;
  2048. char strTest[32][32] = {"tbl", "tfsb", "chgsm"};
  2049. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation"};
  2050. enable = atoi(v2);
  2051. if(enable < 0)
  2052. {
  2053. return;
  2054. }
  2055. for(int i = 0; i < testItemLen; i++)
  2056. {
  2057. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2058. {
  2059. testItem = i + 1;
  2060. break;
  2061. }
  2062. }
  2063. if(testItem != 0)
  2064. {
  2065. if(enable)
  2066. {
  2067. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  2068. }
  2069. else
  2070. {
  2071. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  2072. }
  2073. printf("%s %s Test Item, Test Control Value = %08X\n",
  2074. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  2075. }
  2076. else
  2077. {
  2078. printf("Test Item %s Not Found\n", v1);
  2079. for(int i = 0; i < testItemLen; i++)
  2080. {
  2081. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  2082. }
  2083. }
  2084. printf("\r\n");
  2085. }
  2086. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading
  2087. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX
  2088. void ShowGroupingDemand(void)
  2089. {
  2090. byte target = 0;
  2091. unsigned char k1k2 = 0;
  2092. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading");
  2093. for(int i = 0; i < 4; i++)
  2094. {
  2095. target = ShmPsuGrouping->Layout[i];
  2096. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  2097. {
  2098. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  2099. }
  2100. else
  2101. {
  2102. k1k2 = _chargingData[target]->RelayK1K2Status;
  2103. }
  2104. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  2105. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  2106. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  2107. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  2108. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  2109. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  2110. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  2111. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  2112. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  2113. {
  2114. printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  2115. }
  2116. }
  2117. printf("\r\n\r\n");
  2118. }
  2119. // v1: gun
  2120. // v2: voltage
  2121. // v3: current
  2122. void SetGunStartCharging(char *v1, char *v2, char *v3)
  2123. {
  2124. int gun = 0;
  2125. float _voltage = 0, _current = 0;
  2126. gun = atoi(v1);
  2127. _voltage = atof(v2);
  2128. _current = atof(v3);
  2129. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  2130. {
  2131. printf("\r\nGun Start Charging Input parameter %s, %s, %s over range", v1, v2, v3);
  2132. printf("\r\n\r\n");
  2133. return;
  2134. }
  2135. /*
  2136. if(_chargingData[gun - 1]->SystemStatus == S_IDLE)
  2137. {
  2138. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2139. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2140. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2141. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2142. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2143. }
  2144. else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2145. {
  2146. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2147. {
  2148. printf("\r\nSet Gun %d > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2149. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2150. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2151. }
  2152. else
  2153. {
  2154. printf("\r\nGun %d Force Charging Is Disable", gun);
  2155. }
  2156. }
  2157. else
  2158. {
  2159. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2160. }
  2161. printf("\r\n\r\n");
  2162. */
  2163. bool wait = true;
  2164. int time = 0;
  2165. struct timespec _Wait_time;
  2166. unsigned char PreviousSystemStatus = 0xFF;
  2167. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  2168. while(wait)
  2169. {
  2170. switch(_chargingData[gun - 1]->SystemStatus)
  2171. {
  2172. case S_IDLE:
  2173. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2174. {
  2175. printf("\r\nGun %d S_IDLE", gun);
  2176. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2177. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2178. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2179. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2180. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2181. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2182. }
  2183. break;
  2184. case S_REASSIGN_CHECK:
  2185. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2186. {
  2187. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  2188. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2189. }
  2190. break;
  2191. case S_REASSIGN:
  2192. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2193. {
  2194. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  2195. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2196. }
  2197. break;
  2198. case S_PREPARNING:
  2199. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2200. {
  2201. printf("\r\nGun %d S_PREPARNING", gun);
  2202. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2203. }
  2204. break;
  2205. case S_PREPARING_FOR_EV:
  2206. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2207. {
  2208. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  2209. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2210. }
  2211. break;
  2212. case S_PREPARING_FOR_EVSE:
  2213. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2214. {
  2215. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  2216. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2217. }
  2218. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2219. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2220. {
  2221. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2222. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2223. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2224. }
  2225. break;
  2226. case S_CHARGING:
  2227. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2228. {
  2229. printf("\r\nGun %d S_CHARGING", gun);
  2230. if(PreviousSystemStatus == 0xFF)
  2231. {
  2232. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2233. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2234. printf("\r\nGun %d Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2235. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2236. {
  2237. printf("\r\nSet Gun %d Force Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2238. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2239. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2240. }
  2241. }
  2242. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2243. GetClockTime(&_Wait_time);
  2244. }
  2245. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2246. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2247. {
  2248. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2249. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2250. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2251. }
  2252. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2253. if(time >= 3)
  2254. {
  2255. wait = false;
  2256. printf("\r\nDone");
  2257. }
  2258. break;
  2259. case S_TERMINATING:
  2260. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2261. {
  2262. printf("\r\nGun %d S_TERMINATING", gun);
  2263. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2264. }
  2265. wait = false;
  2266. break;
  2267. case S_COMPLETE:
  2268. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2269. {
  2270. printf("\r\nGun %d S_COMPLETE", gun);
  2271. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2272. }
  2273. wait = false;
  2274. break;
  2275. case S_ALARM:
  2276. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2277. {
  2278. printf("\r\nGun %d S_ALARM", gun);
  2279. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2280. }
  2281. wait = false;
  2282. break;
  2283. default:
  2284. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2285. {
  2286. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2287. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2288. }
  2289. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2290. wait = false;
  2291. break;
  2292. }
  2293. char word[128];
  2294. char newString[7][10];
  2295. int i,j,ctr;
  2296. memset(word, 0x00, sizeof(word));
  2297. get_char(word);
  2298. if (strlen(word) == 0)
  2299. {
  2300. continue;
  2301. }
  2302. j=0; ctr=0;
  2303. strcpy(newString[1], "-1");
  2304. strcpy(newString[2], "-1");
  2305. for (i = 0; i <= (strlen(word)); i++)
  2306. {
  2307. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2308. {
  2309. newString[ctr][j] = '\0';
  2310. ctr++;
  2311. j = 0;
  2312. }
  2313. else
  2314. {
  2315. newString[ctr][j] = word[i];
  2316. j++;
  2317. }
  2318. }
  2319. if(strcmp(newString[0], "c") == 0)
  2320. {
  2321. printf("\r\nStop");
  2322. wait = false;
  2323. }
  2324. usleep(100000);
  2325. }
  2326. printf("\r\n\r\n");
  2327. }
  2328. // v1: gun
  2329. void SetGunStopCharging(char *v1)
  2330. {
  2331. int gun = 0;
  2332. gun = atoi(v1);
  2333. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2334. {
  2335. printf("\r\nGun Stop Charging Input parameter %s over range", v1);
  2336. printf("\r\n\r\n");
  2337. return;
  2338. }
  2339. /*
  2340. if(_chargingData[gun - 1]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[gun - 1]->SystemStatus <= S_CHARGING)
  2341. {
  2342. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2343. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2344. }
  2345. else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2346. {
  2347. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2348. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2349. }
  2350. else
  2351. {
  2352. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2353. }
  2354. printf("\r\n\r\n");
  2355. */
  2356. bool wait = true;
  2357. int time = 0;
  2358. struct timespec _Wait_time;
  2359. unsigned char PreviousSystemStatus = 0xFF;
  2360. while(wait)
  2361. {
  2362. switch(_chargingData[gun - 1]->SystemStatus)
  2363. {
  2364. case S_IDLE:
  2365. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2366. {
  2367. printf("\r\nGun %d S_IDLE", gun);
  2368. if(PreviousSystemStatus == 0xFF)
  2369. {
  2370. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2371. {
  2372. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2373. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2374. }
  2375. }
  2376. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2377. GetClockTime(&_Wait_time);
  2378. }
  2379. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2380. if(time >= 3)
  2381. {
  2382. wait = false;
  2383. printf("\r\nDone");
  2384. }
  2385. break;
  2386. case S_REASSIGN_CHECK:
  2387. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2388. {
  2389. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  2390. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2391. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2392. {
  2393. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2394. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2395. }
  2396. }
  2397. break;
  2398. case S_REASSIGN:
  2399. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2400. {
  2401. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  2402. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2403. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2404. {
  2405. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2406. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2407. }
  2408. }
  2409. break;
  2410. case S_PREPARNING:
  2411. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2412. {
  2413. printf("\r\nGun %d S_PREPARNING", gun);
  2414. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2415. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2416. {
  2417. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2418. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2419. }
  2420. }
  2421. break;
  2422. case S_PREPARING_FOR_EV:
  2423. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2424. {
  2425. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  2426. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2427. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2428. {
  2429. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2430. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2431. }
  2432. }
  2433. break;
  2434. case S_PREPARING_FOR_EVSE:
  2435. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2436. {
  2437. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  2438. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2439. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2440. {
  2441. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2442. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2443. }
  2444. }
  2445. break;
  2446. case S_CHARGING:
  2447. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2448. {
  2449. printf("\r\nGun %d S_CHARGING", gun);
  2450. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2451. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2452. {
  2453. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2454. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2455. }
  2456. }
  2457. break;
  2458. case S_TERMINATING:
  2459. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2460. {
  2461. printf("\r\nGun %d S_TERMINATING", gun);
  2462. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2463. }
  2464. break;
  2465. case S_COMPLETE:
  2466. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2467. {
  2468. printf("\r\nGun %d S_COMPLETE", gun);
  2469. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2470. }
  2471. break;
  2472. case S_ALARM:
  2473. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2474. {
  2475. printf("\r\nGun %d S_ALARM", gun);
  2476. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2477. }
  2478. break;
  2479. default:
  2480. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2481. {
  2482. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2483. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2484. }
  2485. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2486. wait = false;
  2487. break;
  2488. }
  2489. char word[128];
  2490. char newString[7][10];
  2491. int i,j,ctr;
  2492. memset(word, 0x00, sizeof(word));
  2493. get_char(word);
  2494. if (strlen(word) == 0)
  2495. {
  2496. continue;
  2497. }
  2498. j=0; ctr=0;
  2499. strcpy(newString[1], "-1");
  2500. strcpy(newString[2], "-1");
  2501. for (i = 0; i <= (strlen(word)); i++)
  2502. {
  2503. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2504. {
  2505. newString[ctr][j] = '\0';
  2506. ctr++;
  2507. j = 0;
  2508. }
  2509. else
  2510. {
  2511. newString[ctr][j] = word[i];
  2512. j++;
  2513. }
  2514. }
  2515. if(strcmp(newString[0], "c") == 0)
  2516. {
  2517. printf("\r\nStop");
  2518. wait = false;
  2519. }
  2520. usleep(100000);
  2521. }
  2522. printf("\r\n\r\n");
  2523. }
  2524. void SetGunExtend(char *v1)
  2525. {
  2526. int gun = 0;
  2527. gun = atoi(v1);
  2528. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2529. {
  2530. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2531. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2532. }
  2533. else
  2534. {
  2535. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2536. }
  2537. printf("\r\n\r\n");
  2538. }
  2539. // 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 ...
  2540. // 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
  2541. void ShowGunOutput(void)
  2542. {
  2543. byte target = 0;
  2544. unsigned short voltage = 0, current = 0;
  2545. 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 ...");
  2546. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2547. {
  2548. target = ShmPsuGrouping->Layout[i];
  2549. // "\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"
  2550. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2551. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2552. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2553. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2554. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2555. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2556. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2557. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2558. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2559. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2560. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2561. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2562. /*
  2563. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2564. {
  2565. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2566. }
  2567. */
  2568. }
  2569. printf("\r\n\r\n");
  2570. }
  2571. void SetGpio(char *v1, char *v2)
  2572. {
  2573. int testItem = 0;
  2574. int testItemLen = 1;
  2575. int ioOutput = 0;
  2576. char strTest[32][32] = {"4g"};
  2577. char strItem[32][32] = {"4G Reset"};
  2578. ioOutput = atoi(v2);
  2579. if(ioOutput < 0)
  2580. {
  2581. return;
  2582. }
  2583. for(int i = 0; i < testItemLen; i++)
  2584. {
  2585. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2586. {
  2587. testItem = i + 1;
  2588. break;
  2589. }
  2590. }
  2591. if(testItem != 0)
  2592. {
  2593. if(ioOutput)
  2594. {
  2595. system("echo 1 > /sys/class/gpio/gpio104/value");
  2596. }
  2597. else
  2598. {
  2599. system("echo 0 > /sys/class/gpio/gpio104/value");
  2600. }
  2601. printf("Set %s %s\n",
  2602. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2603. }
  2604. else
  2605. {
  2606. printf("Gpio Item %s Not Found\n", v1);
  2607. }
  2608. printf("\r\n");
  2609. }
  2610. void ShowStatus(void)
  2611. {
  2612. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2613. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2614. {
  2615. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2616. i + 1,
  2617. _chargingData[i]->SystemStatus,
  2618. _chargingData[i]->IsAvailable,
  2619. ShmChargerInfo->Control.GunAvailable[i]);
  2620. printf("\r\nAlarmCode");
  2621. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2622. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2623. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2624. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2625. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2626. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2627. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2628. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2629. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2630. }
  2631. printf("\r\n");
  2632. printf("\r\nPower Cabinet Role: %s, Switch Value: %d",
  2633. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2634. ShmChargerInfo->Control.CabinetSwitch);
  2635. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2636. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2637. {
  2638. printf("\r\n WarningCode:");
  2639. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2640. {
  2641. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2642. }
  2643. }
  2644. printf("\r\n\r\n");
  2645. }
  2646. void ShowWhiteCardList(void)
  2647. {
  2648. printf("\r\nWhite Card List");
  2649. for(int i = 0; i < 10; i++)
  2650. {
  2651. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2652. }
  2653. printf("\r\n\r\n");
  2654. }
  2655. void WriteWhiteCard(char *v1, char *v2)
  2656. {
  2657. int cardIndex = 0;
  2658. cardIndex = atoi(v1);
  2659. if(cardIndex < 1 || cardIndex > 10)
  2660. {
  2661. printf("\r\n White Card Index Fail\r\n\r\n");
  2662. return;
  2663. }
  2664. if(strlen(v2) == 0 || strlen(v2) > 31)
  2665. {
  2666. printf("\r\n White Card Fail\r\n\r\n");
  2667. return;
  2668. }
  2669. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2670. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2671. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2672. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2673. printf("\r\n\r\n");
  2674. }
  2675. void EraseWhiteCard(char *v1)
  2676. {
  2677. int cardIndex = 0;
  2678. cardIndex = atoi(v1);
  2679. if(cardIndex < 1 || cardIndex > 10)
  2680. {
  2681. printf("\r\n White Card Index Fail\r\n\r\n");
  2682. return;
  2683. }
  2684. printf("\r\n Erase White Card Index = %d", cardIndex);
  2685. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2686. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2687. printf("\r\n\r\n");
  2688. }
  2689. void ShowChargerLimit(void)
  2690. {
  2691. int limitPower = -1;
  2692. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2693. unsigned char inUsingCnt = 0;
  2694. printf("\r\nCharger Limit");
  2695. printf("\r\n System Psu Cnt: %2d", ShmPsuData->SystemPresentPsuQuantity);
  2696. printf("\r\n Charger Max ChargingProfile Power: %d kW", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ?
  2697. (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2698. printf("\r\n Max Total Current: %d A, Max Total Power: %d kW, Total Energy: %d kW, Total Duration %d",
  2699. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent, ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2700. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2701. printf("\r\n\r\n Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur");
  2702. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2703. {
  2704. inUsingCnt = 0;
  2705. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  2706. {
  2707. if(ShmChargerInfo->PsuGrouping.GroupCollection[j].Role == _GROLE_MASTER)
  2708. {
  2709. inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
  2710. }
  2711. }
  2712. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
  2713. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
  2714. // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
  2715. printf("\r\n %d %d ", i + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable);
  2716. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable)
  2717. {
  2718. printf(" %7s %2d",
  2719. _chargingData[i]->Type <= _Type_GB ? str_gun_type[_chargingData[i]->Type] : "???",
  2720. ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity);
  2721. printf(" %4d V %4d A",
  2722. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage / 10),
  2723. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent / 10));
  2724. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
  2725. {
  2726. limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
  2727. if(inUsingCnt > 0)
  2728. {
  2729. limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity) / inUsingCnt;
  2730. }
  2731. }
  2732. else
  2733. {
  2734. limitPower = -1;
  2735. }
  2736. printf(" %4d / %4d / %4d kW",
  2737. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingPower / 10),
  2738. _chargingData[i]->ChargingProfilePower == -1 ? (int)_chargingData[i]->ChargingProfilePower : ((int)_chargingData[i]->ChargingProfilePower / 1000),
  2739. limitPower == -1 ? limitPower : (limitPower / 1000));
  2740. printf(" %4d / %4d A",
  2741. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingCurrent / 10),
  2742. _chargingData[i]->ChargingProfileCurrent == -1 ? (int)_chargingData[i]->ChargingProfileCurrent : ((int)_chargingData[i]->ChargingProfileCurrent / 10));
  2743. }
  2744. }
  2745. printf("\r\n\r\n");
  2746. }
  2747. void SetGunCommand(char *v1, char *v2, char *v3)
  2748. {
  2749. int cmdItem = 0;
  2750. int cmdItemLen = 2;
  2751. int gunID = 0;
  2752. int enable = 0;
  2753. char strGunCmd[32][32] = {"enable", "operative"};
  2754. char strDescription[32][32] = {"Available", "Operative"};
  2755. gunID = atoi(v2);
  2756. enable = atoi(v3);
  2757. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2758. {
  2759. return;
  2760. }
  2761. for(int i = 0; i < cmdItemLen; i++)
  2762. {
  2763. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2764. {
  2765. cmdItem = i + 1;
  2766. break;
  2767. }
  2768. }
  2769. if(cmdItem != 0)
  2770. {
  2771. switch(cmdItem)
  2772. {
  2773. case 1:
  2774. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2775. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunID - 1].Parameter.bits.AvailabilityRequest = true;
  2776. break;
  2777. case 2:
  2778. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2779. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunID - 1].Parameter.bits.AvailabilityRequest = true;
  2780. break;
  2781. }
  2782. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2783. }
  2784. else
  2785. {
  2786. printf("Gun cmd %s not found\n", v1);
  2787. for(int i = 0; i < cmdItemLen; i++)
  2788. {
  2789. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2790. }
  2791. }
  2792. printf("\r\n");
  2793. }
  2794. void ShowWebSystemInfo(void)
  2795. {
  2796. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2797. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2798. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2799. printf("\r\n");
  2800. printf("Web [System]\r\n");
  2801. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2802. printf(" *AuthorisationMode[%7s]\r\n",
  2803. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2804. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2805. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2806. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2807. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2808. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2809. {
  2810. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2811. }
  2812. else
  2813. {
  2814. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2815. }
  2816. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2817. {
  2818. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2819. }
  2820. else
  2821. {
  2822. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2823. }
  2824. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2825. {
  2826. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2827. }
  2828. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2829. {
  2830. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2831. }
  2832. else
  2833. {
  2834. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2835. }
  2836. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  2837. {
  2838. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  2839. }
  2840. else
  2841. {
  2842. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  2843. }
  2844. }
  2845. void ShowWebChargingInfo(void)
  2846. {
  2847. printf("\r\n");
  2848. printf("Web [Charging]\r\n");
  2849. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  2850. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  2851. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  2852. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2853. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  2854. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  2855. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  2856. }
  2857. void ShowWebNetworkInfo(void)
  2858. {
  2859. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  2860. printf("\r\n");
  2861. printf("Web [Network]\r\n");
  2862. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2863. printf(" *DHCP Client[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  2864. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  2865. {
  2866. printf(" *WiFi Mode [%7s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  2867. }
  2868. else
  2869. {
  2870. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  2871. }
  2872. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  2873. printf(" *3G/4G Mode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  2874. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  2875. printf(" - APN : %s\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  2876. printf(" - RSSI: %d dBm\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  2877. }
  2878. void ShowWebBackendInfo(void)
  2879. {
  2880. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  2881. char *str_security_profile[] = {
  2882. "None security",
  2883. "Unsecured Transport with Basic Atuentication",
  2884. "TLS with Basic Authentication",
  2885. "TLS with Client Side Certificates"
  2886. };
  2887. printf("\r\n");
  2888. printf("Web [Backend]\r\n");
  2889. printf(" *Common\r\n");
  2890. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  2891. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  2892. {
  2893. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  2894. }
  2895. else
  2896. {
  2897. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  2898. }
  2899. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  2900. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  2901. printf(" *OCPP\r\n");
  2902. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  2903. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  2904. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2905. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2906. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  2907. {
  2908. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  2909. }
  2910. else
  2911. {
  2912. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2913. }
  2914. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  2915. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  2916. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  2917. {
  2918. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  2919. }
  2920. else
  2921. {
  2922. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  2923. }
  2924. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  2925. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  2926. {
  2927. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  2928. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  2929. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  2930. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  2931. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  2932. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  2933. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  2934. }
  2935. }
  2936. void ShowWebAllInfo(void)
  2937. {
  2938. ShowWebSystemInfo();
  2939. ShowWebChargingInfo();
  2940. ShowWebNetworkInfo();
  2941. ShowWebBackendInfo();
  2942. }
  2943. void ShowWebInfo(char *v1)
  2944. {
  2945. bool find = false;
  2946. int showItem = 0;
  2947. int itemLen = 5;
  2948. char strItem[32][32] = {"system", "charging", "network", "backend", "all"};
  2949. void *actionList[32] = {&ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo, &ShowWebAllInfo};
  2950. void (*ItemAction)();
  2951. for(showItem = 0; showItem < itemLen; showItem++)
  2952. {
  2953. if(strcmp((char *)&strItem[showItem][0], v1) == 0)
  2954. {
  2955. find = true;
  2956. break;
  2957. }
  2958. }
  2959. if(find)
  2960. {
  2961. ItemAction = actionList[showItem];
  2962. ItemAction();
  2963. }
  2964. else
  2965. {
  2966. printf("\r\n");
  2967. printf ("Input cmd fail ------ web [cmd]\r\n");
  2968. for(int i = 0; i < itemLen; i++)
  2969. {
  2970. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  2971. }
  2972. }
  2973. printf("\r\n");
  2974. }
  2975. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXX.X kWh, IdTag [XXXXXXXXXXXXXXXX] Transaction [0]
  2976. // Gun 1 ( CCS ) IdTag: XXXXXXXXXXXXXXXX, Soc: XXX %, Energy: XXXX.X kWh
  2977. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW
  2978. // Output: XXXX V, XXXX A, Limit: XXXX A, XXXX kW
  2979. void ShowGunInfo(int gun)
  2980. {
  2981. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  2982. char acceptId[128];
  2983. Get_Ocpp_TransactionId(gun, acceptId);
  2984. printf(" Gun %d (%s) Soc: %3d %s, Energy: %7.1f kWh, IdTag [%16s] Transaction [%s]\r\n",
  2985. gun + 1,
  2986. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2987. _chargingData[gun]->EvBatterySoc, "%",
  2988. _chargingData[gun]->PresentChargedEnergy,
  2989. _chargingData[gun]->StartUserId,
  2990. acceptId);
  2991. //printf(" Gun %d (%s) IdTag [%16s] Soc: %3d %s, Energy: %4.1f kWh\r\n",
  2992. // i + 1,
  2993. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? str_gun_type[_chargingData[i]->Type] : "Disable",
  2994. // _chargingData[i]->StartUserId,
  2995. // _chargingData[i]->EvBatterySoc, "%",
  2996. // _chargingData[i]->PresentChargedEnergy);
  2997. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW\r\n",
  2998. _chargingData[gun]->SystemStatus,
  2999. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  3000. (int)_chargingData[gun]->EvBatterytargetVoltage,
  3001. (int)_chargingData[gun]->EvBatterytargetCurrent,
  3002. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  3003. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  3004. printf(" Output: %4d V, %4d A, Limit: %4d A, %4d kW\r\n",
  3005. (int)(_chargingData[gun]->PresentChargingVoltage),
  3006. (int)(_chargingData[gun]->PresentChargingCurrent),
  3007. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  3008. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10));
  3009. }
  3010. void ShowInfo(char *inputCmd, unsigned int opt)
  3011. {
  3012. bool keepRun = false;
  3013. bool reflash = false;
  3014. int time = 0;
  3015. struct timespec _Loop_time;
  3016. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  3017. {
  3018. keepRun = true;
  3019. }
  3020. do
  3021. {
  3022. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  3023. if(time >= 1000)
  3024. {
  3025. if(reflash)
  3026. {
  3027. ConsoleReflash(CONNECTOR_QUANTITY, 4);
  3028. }
  3029. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  3030. {
  3031. printf("\r\n");
  3032. ShowGunInfo(i);
  3033. }
  3034. GetClockTime(&_Loop_time);
  3035. if((opt & OPTION_REFLASH) > 0)
  3036. {
  3037. reflash = true;
  3038. }
  3039. }
  3040. if(keepRun)
  3041. {
  3042. keepRun = IsLoopStopCmd() ? false : true;
  3043. usleep(10000);
  3044. }
  3045. }while(keepRun);
  3046. printf("\r\n");
  3047. }
  3048. int main(void)
  3049. {
  3050. char newString[32][32];
  3051. char inputString[128], normalCmd[128], mainCmd[128], subCmd[128], multiCmd[128];
  3052. int cmdCnt = 0, parseCnt = 0;
  3053. unsigned int option = 0;
  3054. if(InitShareMemory() == FAIL)
  3055. {
  3056. printf ("InitShareMemory = FAIL \n");
  3057. if(ShmStatusCodeData != NULL)
  3058. {
  3059. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3060. }
  3061. sleep(5);
  3062. return 0;
  3063. }
  3064. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3065. {
  3066. if (!FindChargingInfoData(i, &_chargingData[0]))
  3067. {
  3068. return 0;
  3069. }
  3070. }
  3071. // clean command
  3072. memset(mainCmd, 0x00, sizeof(mainCmd));
  3073. memset(subCmd, 0x00, sizeof(subCmd));
  3074. for(int i = 0; i < 32; i++)
  3075. {
  3076. memset(&newString[i], 0x00, 32);
  3077. }
  3078. for(;;)
  3079. {
  3080. memset(inputString, 0x00, sizeof(inputString));
  3081. memset(normalCmd, 0x00, sizeof(normalCmd));
  3082. get_char(inputString);
  3083. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  3084. if(cmdCnt > 0)
  3085. {
  3086. // clean command
  3087. memset(mainCmd, 0x00, sizeof(mainCmd));
  3088. memset(subCmd, 0x00, sizeof(subCmd));
  3089. for(int i = 0; i < 32; i++)
  3090. {
  3091. memset(&newString[i], 0x00, 32);
  3092. }
  3093. //printf("CmdCnt: %d\r\n", cmdCnt);
  3094. //printf("Input: %s", inputString);
  3095. //printf("Normalize: %s\r\n", normalCmd);
  3096. //printf("option: %08X\r\n", option);
  3097. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  3098. //printf("MainCmd: %s\r\n", mainCmd);
  3099. //printf("SubCmd: %s\r\n", subCmd);
  3100. parseCnt = 0;
  3101. strcpy(multiCmd, normalCmd);
  3102. do
  3103. {
  3104. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  3105. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  3106. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  3107. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  3108. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  3109. parseCnt++;
  3110. }while(parseCnt < cmdCnt - 1);
  3111. //printf("\r\n");
  3112. //for(int i = 0; i < cmdCnt; i++)
  3113. //{
  3114. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  3115. //}
  3116. }
  3117. else
  3118. {
  3119. usleep(100000);
  3120. continue;
  3121. }
  3122. if(strcmp(newString[0], "state") == 0)
  3123. {
  3124. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3125. continue;
  3126. // 槍狀態
  3127. RunStatusProc(newString[1], newString[2]);
  3128. }
  3129. else if(strcmp(newString[0], "card") == 0)
  3130. {
  3131. // 刷卡狀態
  3132. RunCardProc(newString[1], newString[2]);
  3133. }
  3134. else if(strcmp(newString[0], "gun") == 0)
  3135. {
  3136. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3137. continue;
  3138. // 插槍狀態
  3139. RunGunPlugitProc(newString[1], newString[2]);
  3140. }
  3141. else if(strcmp(newString[0], "lock") == 0)
  3142. {
  3143. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3144. continue;
  3145. // 插槍狀態
  3146. GetGunLockStatusProc(newString[1], newString[2]);
  3147. }
  3148. else if(strcmp(newString[0], "sysid") == 0)
  3149. {
  3150. // 測試 sys id
  3151. SetSystemIDProc();
  3152. }
  3153. else if(strcmp(newString[0], "self") == 0)
  3154. {
  3155. // CSU 自我檢測狀態
  3156. RunSelfProc(newString[1]);
  3157. }
  3158. else if(strcmp(newString[0], "ver") == 0)
  3159. {
  3160. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3161. // continue;
  3162. // 取 FW 版號
  3163. //GetFwVerProc(newString[1]);
  3164. ShowFwVer();
  3165. }
  3166. else if (strcmp(newString[0], "update") == 0)
  3167. {
  3168. // 更新
  3169. FwUpdateFlagProc(newString[1]);
  3170. }
  3171. else if (strcmp(newString[0], "ac") == 0)
  3172. {
  3173. // AC contactor 狀態
  3174. CheckAcStatus(newString[1]);
  3175. }
  3176. else if (strcmp(newString[0], "cable") == 0)
  3177. {
  3178. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3179. continue;
  3180. // cable check pass
  3181. SetCableChkStatus(newString[1], newString[2]);
  3182. }
  3183. else if (strcmp(newString[0], "pow") == 0)
  3184. {
  3185. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3186. continue;
  3187. // cable check pass
  3188. SetPowerValue(newString[1], newString[2]);
  3189. }
  3190. else if (strcmp(newString[0], "model") == 0)
  3191. {
  3192. GetSystemInfo();
  3193. }
  3194. else if(strcmp(newString[0], "fan") == 0)
  3195. {
  3196. // 設定風扇速度
  3197. SetFanSpeed(newString[1]);
  3198. }
  3199. else if(strcmp(newString[0], "speed") == 0)
  3200. {
  3201. // 取得風扇速度
  3202. GetFanSpeed();
  3203. }
  3204. else if(strcmp(newString[0], "debug") == 0)
  3205. {
  3206. // 設定 debug mode
  3207. SetDebugMode(newString[1]);
  3208. }
  3209. else if (strcmp(newString[0], "gfd") == 0)
  3210. {
  3211. // 設定盲沖使用 GFD 功能
  3212. SetGFDMode(newString[1]);
  3213. }
  3214. else if(strcmp(mainCmd, "temp") == 0)
  3215. {
  3216. // 取得溫度
  3217. GetTemperature(subCmd, option);
  3218. }
  3219. else if(strcmp(mainCmd, "acin") == 0)
  3220. {
  3221. // 取得三向輸入電壓
  3222. GetInputVol(subCmd, option);
  3223. }
  3224. else if(strcmp(newString[0], "psu") == 0)
  3225. {
  3226. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3227. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3228. {
  3229. printf ("PSU : Param fail..Please retry again......\n");
  3230. continue;
  3231. }
  3232. // 取得 PSU 資訊
  3233. GetPsuInformation(newString[1], newString[2], newString[3]);
  3234. }
  3235. else if (strcmp(newString[0], "cap") == 0)
  3236. {
  3237. GetConnectorCapInfo(newString[1]);
  3238. }
  3239. else if(strcmp(newString[0], "error") == 0)
  3240. {
  3241. CreateOneError(newString[1]);
  3242. }
  3243. else if (strcmp(newString[0], "auth") == 0)
  3244. {
  3245. GetAuthorizeFlag(newString[1]);
  3246. }
  3247. else if (strcmp(newString[0], "id") == 0)
  3248. {
  3249. GetOrClearId(newString[1]);
  3250. }
  3251. #if 0
  3252. else if(strcmp(newString[0], "strchg") == 0)
  3253. {
  3254. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3255. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3256. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3257. {
  3258. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  3259. continue;
  3260. }
  3261. // 槍狀態
  3262. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  3263. }
  3264. else if(strcmp(newString[0], "str2chg") == 0)
  3265. {
  3266. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3267. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3268. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3269. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  3270. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  3271. {
  3272. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  3273. continue;
  3274. }
  3275. // 槍狀態
  3276. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  3277. }
  3278. #endif
  3279. else if(strcmp(newString[0], "wiring") == 0)
  3280. {
  3281. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  3282. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  3283. {
  3284. SetWiringInfo(newString[1], newString[2]);
  3285. }
  3286. ShowWiringInfo();
  3287. }
  3288. else if(strcmp(newString[0], "cwiring") == 0)
  3289. {
  3290. CleanWiringInfo();
  3291. }
  3292. else if(strcmp(newString[0], "reset") == 0)
  3293. {
  3294. SetSystemSoftRest();
  3295. }
  3296. else if(strcmp(newString[0], "reboot") == 0)
  3297. {
  3298. SetSystemHardReboot();
  3299. }
  3300. else if(strcmp(newString[0], "sgroup") == 0)
  3301. {
  3302. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3303. {
  3304. ShowGroupingInfo();
  3305. continue;
  3306. }
  3307. RunSimplePsuGrouping(newString[1], newString[2]);
  3308. }
  3309. else if(strcmp(newString[0], "cabinet") == 0)
  3310. {
  3311. ShowCabinetInfo();
  3312. }
  3313. else if(strcmp(newString[0], "tctl") == 0)
  3314. {
  3315. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3316. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3317. {
  3318. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  3319. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  3320. continue;
  3321. }
  3322. SetTestControl(newString[1], newString[2]);
  3323. }
  3324. else if(strcmp(newString[0], "group") == 0)
  3325. {
  3326. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3327. {
  3328. ShowGroupingInfo();
  3329. continue;
  3330. }
  3331. }
  3332. else if(strcmp(newString[0], "gdmd") == 0)
  3333. {
  3334. ShowGroupingDemand();
  3335. }
  3336. else if(strcmp(newString[0], "gunchg") == 0)
  3337. {
  3338. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3339. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3340. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  3341. {
  3342. printf ("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\n\n");
  3343. continue;
  3344. }
  3345. SetGunStartCharging(newString[1], newString[2], newString[3]);
  3346. }
  3347. else if(strcmp(newString[0], "gunstp") == 0)
  3348. {
  3349. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3350. {
  3351. printf ("Input cmd fail ------ gunstp [gun 1-4]\n\n");
  3352. continue;
  3353. }
  3354. SetGunStopCharging(newString[1]);
  3355. }
  3356. else if(strcmp(newString[0], "gunext") == 0)
  3357. {
  3358. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3359. {
  3360. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  3361. continue;
  3362. }
  3363. SetGunExtend(newString[1]);
  3364. }
  3365. else if(strcmp(newString[0], "output") == 0)
  3366. {
  3367. ShowGunOutput();
  3368. }
  3369. else if(strcmp(newString[0], "gio") == 0)
  3370. {
  3371. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3372. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3373. {
  3374. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  3375. continue;
  3376. }
  3377. SetGpio(newString[1], newString[2]);
  3378. }
  3379. else if(strcmp(newString[0], "status") == 0)
  3380. {
  3381. ShowStatus();
  3382. }
  3383. else if(strcmp(newString[0], "whiteR") == 0)
  3384. {
  3385. ShowWhiteCardList();
  3386. }
  3387. else if(strcmp(newString[0], "whiteW") == 0)
  3388. {
  3389. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3390. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3391. {
  3392. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  3393. continue;
  3394. }
  3395. WriteWhiteCard(newString[1], newString[2]);
  3396. }
  3397. else if(strcmp(newString[0], "whiteE") == 0)
  3398. {
  3399. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3400. {
  3401. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  3402. continue;
  3403. }
  3404. EraseWhiteCard(newString[1]);
  3405. }
  3406. else if(strcmp(newString[0], "limit") == 0)
  3407. {
  3408. ShowChargerLimit();
  3409. }
  3410. else if(strcmp(newString[0], "pcmd") == 0)
  3411. {
  3412. }
  3413. else if(strcmp(newString[0], "gcmd") == 0)
  3414. {
  3415. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3416. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3417. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  3418. {
  3419. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  3420. continue;
  3421. }
  3422. SetGunCommand(newString[1], newString[2], newString[3]);
  3423. }
  3424. else if(strcmp(newString[0], "web") == 0)
  3425. {
  3426. ShowWebInfo(newString[1]);
  3427. }
  3428. else if(strcmp(mainCmd, "info") == 0)
  3429. {
  3430. ShowInfo(subCmd, option);
  3431. }
  3432. else
  3433. {
  3434. printf ("%s\n", msg);
  3435. }
  3436. usleep(100000);
  3437. }
  3438. return 0;
  3439. }