ReadCmdline.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069
  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. typedef unsigned char byte;
  40. #define PASS 1
  41. #define FAIL -1
  42. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  43. #define NO_DEFINE 255
  44. #define DEFAULT_AC_INDEX 2
  45. #define TTY_PATH "/dev/tty"
  46. #define STTY_US "stty raw -echo -F "
  47. #define STTY_DEF "stty -raw echo -F "
  48. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  49. struct StatusCodeData *ShmStatusCodeData;
  50. struct PrimaryMcuData *ShmPrimaryMcuData;
  51. struct CHAdeMOData *ShmCHAdeMOData;
  52. struct CcsData *ShmCcsData;
  53. struct GBTData *ShmGBTData;
  54. struct FanModuleData *ShmFanModuleData;
  55. struct RelayModuleData *ShmRelayModuleData;
  56. struct LedModuleData *ShmLedModuleData;
  57. struct PsuData *ShmPsuData;
  58. ChargerInfoData *ShmChargerInfo;
  59. PsuPositionInfoData *ShmPsuPosition;
  60. PsuGroupingInfoData *ShmPsuGrouping;
  61. PsuGroupCollectionData *ShmGroupCollection;
  62. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  63. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  64. char *msg = "state : get gun state (index) \n"
  65. "card : scanning card (x) : \n"
  66. "gun : get gun plugit state (index) \n"
  67. "lock : get gun locked state (index) \n"
  68. "self : self test state (x) \n"
  69. "ver : ver of board (407 or index or rb or fan) \n"
  70. "ac : get ac relay state (x) \n"
  71. "gunchg: set gun start charging \n"
  72. "gunstp: set gun stop charging \n"
  73. "gunext: extend gun capability \n";
  74. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  75. {
  76. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  77. {
  78. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  79. {
  80. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  81. return true;
  82. }
  83. }
  84. for (byte index = 0; index < CCS_QUANTITY; index++)
  85. {
  86. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  87. {
  88. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  89. return true;
  90. }
  91. }
  92. for (byte index = 0; index < GB_QUANTITY; index++)
  93. {
  94. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  95. {
  96. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  97. return true;
  98. }
  99. }
  100. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  101. {
  102. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  103. return true;
  104. }
  105. return false;
  106. }
  107. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  108. {
  109. if (target < AC_QUANTITY)
  110. {
  111. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  112. return true;
  113. }
  114. return false;
  115. }
  116. int InitShareMemory()
  117. {
  118. int result = PASS;
  119. int MeterSMId;
  120. //initial ShmSysConfigAndInfo
  121. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  122. {
  123. result = FAIL;
  124. }
  125. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  126. {
  127. result = FAIL;
  128. }
  129. else
  130. {}
  131. //initial ShmStatusCodeData
  132. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  133. {
  134. result = FAIL;
  135. }
  136. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  137. {
  138. result = FAIL;
  139. }
  140. else
  141. {}
  142. if (CHAdeMO_QUANTITY > 0) {
  143. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  144. IPC_CREAT | 0777)) < 0) {
  145. result = FAIL;
  146. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  147. == (void *) -1) {
  148. result = FAIL;
  149. } else {
  150. }
  151. }
  152. if (CCS_QUANTITY > 0) {
  153. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  154. IPC_CREAT | 0777)) < 0) {
  155. result = FAIL;
  156. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  157. result = FAIL;
  158. } else {
  159. }
  160. }
  161. if (GB_QUANTITY > 0) {
  162. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  163. IPC_CREAT | 0777)) < 0) {
  164. return 0;
  165. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  166. return 0;
  167. }
  168. memset(ShmGBTData, 0, sizeof(struct GBTData));
  169. }
  170. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  171. {
  172. result = FAIL;
  173. }
  174. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  175. {
  176. result = FAIL;
  177. }
  178. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  179. {
  180. result = FAIL;
  181. }
  182. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  183. {
  184. result = FAIL;
  185. }
  186. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  187. {
  188. result = FAIL;
  189. }
  190. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  191. {
  192. result = FAIL;
  193. }
  194. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  195. {
  196. result = FAIL;
  197. }
  198. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  199. {
  200. result = FAIL;
  201. }
  202. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  203. {
  204. result = FAIL;
  205. }
  206. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  207. {
  208. result = FAIL;
  209. }
  210. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  211. {
  212. result = FAIL;
  213. }
  214. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  215. {
  216. result = FAIL;
  217. }
  218. if(result == PASS)
  219. {
  220. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  221. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  222. ShmGroupCollection = &ShmChargerInfo->PsuGrouping.GroupCollection[0];
  223. }
  224. return result;
  225. }
  226. unsigned long GetTimeoutValue(struct timeval _sour_time)
  227. {
  228. struct timeval _end_time;
  229. gettimeofday(&_end_time, NULL);
  230. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  231. }
  232. void RunStatusProc(char *v1, char *v2)
  233. {
  234. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  235. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  236. if (strcmp(v1, "ac") == 0)
  237. {
  238. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  239. {
  240. printf("FindChargingInfoData (AC) false \n");
  241. }
  242. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  243. return;
  244. }
  245. int _index = atoi(v1);
  246. if (_index <= 1)
  247. {
  248. if (!FindChargingInfoData(_index, &_chargingData[0]))
  249. {
  250. printf ("FindChargingInfoData error\n");
  251. return;
  252. }
  253. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  254. {
  255. // get
  256. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  257. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  258. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  259. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  260. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  261. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  262. }
  263. else
  264. {
  265. // set
  266. _chargingData[_index]->SystemStatus = atoi(v2);
  267. }
  268. }
  269. else
  270. {
  271. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  272. {
  273. printf("FindChargingInfoData (AC) false \n");
  274. }
  275. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  276. {
  277. // get
  278. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  279. }
  280. else
  281. {
  282. // set
  283. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  284. }
  285. }
  286. }
  287. void RunCardProc(char *v1, char *v2)
  288. {
  289. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  290. {
  291. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  292. {
  293. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  294. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  295. }
  296. else
  297. {
  298. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  299. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  300. }
  301. }
  302. else
  303. {
  304. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  305. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  306. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  307. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  308. }
  309. }
  310. void RunGunPlugitProc(char *v1, char *v2)
  311. {
  312. if (strcmp(v1, "ac") == 0)
  313. {
  314. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  315. {
  316. printf("FindChargingInfoData (AC) false \n");
  317. }
  318. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  319. {
  320. // get
  321. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  322. }
  323. else
  324. {
  325. // set
  326. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  327. }
  328. return;
  329. }
  330. int _index = atoi(v1);
  331. if (!FindChargingInfoData(_index, &_chargingData[0]))
  332. {
  333. printf("FindChargingInfoData error\n");
  334. return;
  335. }
  336. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  337. {
  338. // get
  339. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  340. }
  341. else
  342. {
  343. // set
  344. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  345. }
  346. }
  347. void GetGunLockStatusProc(char *v1, char *v2)
  348. {
  349. int _index = atoi(v1);
  350. if (!FindChargingInfoData(_index, &_chargingData[0]))
  351. {
  352. printf("FindChargingInfoData error\n");
  353. return;
  354. }
  355. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  356. {
  357. _chargingData[_index]->GunLocked = atoi(v2);
  358. }
  359. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  360. }
  361. void SetSystemIDProc()
  362. {
  363. char *systemId = "Alston_Test";
  364. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  365. }
  366. void RunSelfProc()
  367. {
  368. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  369. }
  370. void GetFwVerProc(char *v1)
  371. {
  372. if (strcmp(v1, "407") == 0)
  373. {
  374. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  375. }
  376. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  377. {
  378. int _index = atoi(v1);
  379. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  380. {
  381. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  382. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  383. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  384. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  385. {
  386. if(ParentIndex == 0)
  387. {
  388. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  389. }
  390. else
  391. {
  392. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  393. }
  394. }
  395. }
  396. else
  397. {
  398. printf("Gun %d is disable\r\n", _index);
  399. }
  400. }
  401. else if (strcmp(v1, "rb") == 0)
  402. {
  403. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  404. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  405. }
  406. else if (strcmp(v1, "fan") == 0)
  407. {
  408. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  409. }
  410. else if (strcmp(v1, "dc") == 0)
  411. {
  412. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  413. }
  414. else if (strcmp(v1, "led") == 0)
  415. {
  416. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  417. }
  418. }
  419. void CreateOneError(char *v1)
  420. {
  421. int value = atoi(v1);
  422. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  423. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  424. }
  425. void GetAuthorizeFlag(char *v1)
  426. {
  427. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  428. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  429. else
  430. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  431. }
  432. void GetOrClearId(char *v1)
  433. {
  434. int _index = atoi(v1);
  435. if (!FindChargingInfoData(_index, &_chargingData[0]))
  436. {
  437. printf("FindChargingInfoData error\n");
  438. return;
  439. }
  440. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  441. }
  442. void FwUpdateFlagProc()
  443. {
  444. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  445. }
  446. void CheckAcStatus(char *v1)
  447. {
  448. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  449. {
  450. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  451. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  452. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  453. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  454. }
  455. else
  456. {
  457. if(system("pidof -s main > /dev/null") != 0)
  458. {
  459. if(strcmp(v1, "0") == 0)
  460. {
  461. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  462. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  463. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  464. printf("Set AC Contactor Off\r\n");
  465. }
  466. else
  467. {
  468. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  469. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  470. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  471. printf("Set AC Contactor On\r\n");
  472. }
  473. }
  474. else
  475. {
  476. printf("main task is running\r\n");
  477. }
  478. }
  479. }
  480. void SetCableChkStatus(char *v1, char *v2)
  481. {
  482. int _index = atoi(v1);
  483. if (!FindChargingInfoData(_index, &_chargingData[0]))
  484. {
  485. printf ("FindChargingInfoData error\n");
  486. return;
  487. }
  488. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  489. }
  490. void SetPowerValue(char *v1, char *v2)
  491. {
  492. int _index = atoi(v1);
  493. float _Current = atof(v2);
  494. // 盲沖的時候才允許使用~
  495. if (_chargingData[_index]->Type != 9)
  496. return;
  497. if (!FindChargingInfoData(_index, &_chargingData[0]))
  498. {
  499. printf ("FindChargingInfoData error\n");
  500. return;
  501. }
  502. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  503. }
  504. void GetSystemInfo()
  505. {
  506. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  507. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  508. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  509. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  510. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  511. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  512. }
  513. void ChangeGunNum()
  514. {
  515. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  516. {
  517. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  518. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  519. }
  520. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  521. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  522. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  523. else
  524. {
  525. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  526. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  527. }
  528. }
  529. void GetGunSelectedNum(char *v1)
  530. {
  531. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  532. {
  533. if (AC_QUANTITY > 0 &&
  534. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  535. {
  536. printf("connector select changed = AC \n");
  537. }
  538. else
  539. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  540. }
  541. else
  542. {
  543. int _index = atoi(v1);
  544. if (_index <= 1)
  545. {
  546. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  547. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  548. printf("connector select changed = %d \n", _index);
  549. }
  550. else if (AC_QUANTITY > 0)
  551. {
  552. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  553. printf("connector select changed = AC \n");
  554. }
  555. }
  556. }
  557. void SetFanSpeed(char *v1)
  558. {
  559. int speed = atoi(v1);
  560. ShmFanModuleData->TestFanSpeed = speed;
  561. }
  562. void GetFanSpeed()
  563. {
  564. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  565. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  566. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  567. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  568. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  569. }
  570. void SetDebugMode(char *v1)
  571. {
  572. int mode = atoi(v1);
  573. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  574. }
  575. void SetGFDMode(char *v1)
  576. {
  577. int mode = atoi(v1);
  578. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  579. }
  580. // Gun Temp Chiller PSU 0 PSU 1 PSU 2 ...
  581. // 1 XXX XXX XXX XXX XXX XXX
  582. void GetTemperature(char *v1)
  583. {
  584. bool show = false;
  585. char strGunTemp[16], strChillerTemp[16];
  586. if(strcmp(v1, "c") == 0)
  587. {
  588. printf("\r\n Get c Parameter");
  589. show = true;
  590. }
  591. do
  592. {
  593. printf("\r\n Gun Temp Chiller PSU 0 PSU 1 PSU 2 ...");
  594. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  595. {
  596. sprintf(strGunTemp, "N/A");
  597. sprintf(strChillerTemp, "N/A");
  598. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  599. {
  600. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  601. }
  602. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  603. {
  604. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  605. }
  606. printf("\r\n %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  607. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  608. {
  609. printf(" %3d ", ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp);
  610. }
  611. }
  612. printf("\r\n");
  613. if(show)
  614. {
  615. sleep(1);
  616. }
  617. }while(show);
  618. }
  619. void GetAcInputVol()
  620. {
  621. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  622. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  623. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  624. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  625. }
  626. void GetPsuInformation(char *v1, char *v2, char *v3)
  627. {
  628. printf("**********************AC Contact needed*************************\n");
  629. if(strcmp(v1, "count") == 0)
  630. {
  631. for (int i = 0; i < 4; i++)
  632. {
  633. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  634. }
  635. }
  636. else if(strcmp(v1, "ver") == 0)
  637. {
  638. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  639. {
  640. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  641. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  642. }
  643. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  644. {
  645. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  646. {
  647. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  648. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  649. }
  650. }
  651. }
  652. else if(strcmp(v1, "cap") == 0)
  653. {
  654. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  655. {
  656. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  657. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  658. }
  659. }
  660. else if(strcmp(v1, "input") == 0)
  661. {
  662. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  663. {
  664. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  665. {
  666. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  667. i, count,
  668. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  669. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  670. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  671. }
  672. }
  673. }
  674. else if (strcmp(v1, "output") == 0)
  675. {
  676. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  677. {
  678. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  679. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  680. }
  681. }
  682. else if (strcmp(v1, "test") == 0)
  683. {
  684. int mode = atoi(v2);
  685. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  686. {
  687. ShmPsuData->Work_Step = mode;
  688. }
  689. }
  690. else if (strcmp(v1, "out") == 0)
  691. {
  692. float vol = atof(v2);
  693. float cur = atof(v3);
  694. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  695. {
  696. if (!FindChargingInfoData(0, &_chargingData[0]))
  697. {
  698. printf ("FindChargingInfoData error\n");
  699. return;
  700. }
  701. _chargingData[0]->EvBatterytargetVoltage = vol;
  702. _chargingData[0]->EvBatterytargetCurrent = cur;
  703. }
  704. }
  705. printf("*************************************************\n");
  706. }
  707. void GetConnectorCapInfo(char *v1)
  708. {
  709. int _GunIndex = atoi(v1);
  710. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  711. {
  712. printf ("FindChargingInfoData error\n");
  713. return;
  714. }
  715. printf ("Charger Max Current = %d, Max Power = %d \n",
  716. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  717. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  718. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  719. _GunIndex,
  720. _chargingData[_GunIndex]->RealMaxPower,
  721. _chargingData[_GunIndex]->RealMaxVoltage,
  722. _chargingData[_GunIndex]->RealMaxCurrent);
  723. }
  724. static void get_char(char *word)
  725. {
  726. fd_set rfds;
  727. struct timeval tv;
  728. FD_ZERO(&rfds);
  729. FD_SET(0, &rfds);
  730. tv.tv_sec = 0;
  731. tv.tv_usec = 10; //wait input timout time
  732. //if input
  733. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  734. {
  735. fgets(word, 128, stdin);
  736. }
  737. }
  738. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  739. {
  740. int _GunIndex = atoi(v1);
  741. float _Voltage = atof(v2);
  742. float _Current = atof(v3);
  743. unsigned char PreviousSystemStatus = 0xff;
  744. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  745. {
  746. printf ("FindChargingInfoData error\n");
  747. return;
  748. }
  749. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  750. if(_Voltage > 1000 || _Voltage < 50)
  751. {
  752. printf ("Input Voltage over range\n");
  753. return;
  754. }
  755. // if(_Current > 100 || _Current < 2){
  756. //
  757. // printf ("Input Current over range\n");
  758. // return;
  759. // }
  760. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  761. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  762. //kill ev task
  763. system("killall Module_EvComm");
  764. //_Voltage = (_Voltage * 10);
  765. //_Current = (_Current * 10);
  766. //system(STTY_US TTY_PATH);
  767. while(true)
  768. {
  769. //fix gun 1
  770. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  771. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  772. {
  773. case S_IDLE:
  774. {
  775. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  776. {
  777. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  778. printf ("[UnconditionalCharge - S_IDLE]\n");
  779. }
  780. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  781. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  782. }
  783. break;
  784. case S_PREPARNING:
  785. {
  786. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  787. {
  788. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  789. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  790. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  791. printf ("wait find module\n");
  792. }
  793. //main 會在此階段判斷以下資料跳到下一個 state
  794. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  795. //ShmPsuData->SystemPresentPsuQuantity;
  796. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  797. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  798. //_chargingData[gun_index]->AvailableChargingPower;
  799. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  800. //sleep(10);
  801. //清除 main timeout 機制
  802. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  803. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  804. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  805. }
  806. break;
  807. case S_PREPARING_FOR_EV:
  808. {
  809. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  810. {
  811. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  812. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  813. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  814. }
  815. //清除 main timeout 機制
  816. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  817. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  818. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  819. //充電電壓電流
  820. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  821. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  822. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  823. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  824. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  825. //確定模組己升壓完成
  826. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  827. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  828. {
  829. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  830. //EV done
  831. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  832. }
  833. }
  834. break;
  835. case S_PREPARING_FOR_EVSE:
  836. {
  837. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  838. {
  839. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  840. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  841. }
  842. //printf ("tar vol = %d \n", _Voltage);
  843. //printf ("tar cur = %d \n", _Current);
  844. //清除 main timeout 機制
  845. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  846. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  847. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  848. //充電電壓電流
  849. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  850. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  851. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  852. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  853. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  854. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  855. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  856. //確定模組己升壓完成
  857. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  858. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  859. //{
  860. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  861. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  862. sleep(5);
  863. //EV done
  864. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  865. //}
  866. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  867. //{
  868. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  869. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  870. //}
  871. }
  872. break;
  873. case S_CHARGING:
  874. {
  875. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  876. {
  877. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  878. //充電電壓電流
  879. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  880. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  881. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  882. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  883. printf ("[UnconditionalCharge - S_CHARGING]\n");
  884. }
  885. //ev task do this
  886. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  887. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  888. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  889. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  890. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  891. }
  892. }
  893. break;
  894. case S_TERMINATING:
  895. {
  896. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  897. {
  898. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  899. system("/root/Module_EvComm &");
  900. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  901. //無阻塞偵測 keybaord 結束
  902. system(STTY_DEF TTY_PATH);
  903. }
  904. sleep(3);
  905. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  906. return;
  907. }
  908. break;
  909. case S_COMPLETE:
  910. {
  911. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  912. {
  913. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  914. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  915. }
  916. sleep(3);
  917. return;
  918. }
  919. break;
  920. }
  921. char word[128];
  922. char newString[7][10];
  923. int i,j,ctr;
  924. memset(word, 0x00, sizeof(word));
  925. get_char(word);
  926. if (strlen(word) == 0)
  927. {
  928. continue;
  929. }
  930. j=0; ctr=0;
  931. strcpy(newString[1], "-1");
  932. strcpy(newString[2], "-1");
  933. for (i = 0; i <= (strlen(word)); i++)
  934. {
  935. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  936. {
  937. newString[ctr][j] = '\0';
  938. ctr++;
  939. j = 0;
  940. }
  941. else
  942. {
  943. newString[ctr][j] = word[i];
  944. j++;
  945. }
  946. }
  947. if(strcmp(newString[0], "chg") == 0)
  948. {
  949. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  950. continue;
  951. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  952. continue;
  953. float _vol = atof(newString[1]);
  954. float _cur = atof(newString[2]);
  955. if (_cur <= 0 || _cur <= 0)
  956. continue;
  957. printf("vol = %f, cur = %f \n", _vol, _cur);
  958. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  959. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  960. }
  961. else if (strcmp(newString[0], "c") == 0)
  962. {
  963. printf("stop \n\r");
  964. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  965. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  966. }
  967. usleep(100000);
  968. }
  969. }
  970. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  971. {
  972. float _Voltage[2], _Current[2];
  973. _Voltage[0] = atof(v1);
  974. _Current[0] = atof(v2);
  975. _Voltage[1] = atof(v3);
  976. _Current[1] = atof(v4);
  977. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  978. if(!FindChargingInfoData(0, &_chargingData[0]))
  979. {
  980. printf ("FindChargingInfoData 0 error\n");
  981. return;
  982. }
  983. if(!FindChargingInfoData(1, &_chargingData[0]))
  984. {
  985. printf ("FindChargingInfoData 1 error\n");
  986. return;
  987. }
  988. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  989. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  990. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  991. {
  992. printf ("Input Voltage over range\n");
  993. return;
  994. }
  995. //kill ev task
  996. system("killall Module_EvComm");
  997. while(true)
  998. {
  999. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  1000. {
  1001. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  1002. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  1003. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1004. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1005. }
  1006. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  1007. {
  1008. system(STTY_DEF TTY_PATH);
  1009. sleep(5);
  1010. return;
  1011. }
  1012. for(int i = 0; i < 2; i++)
  1013. {
  1014. switch(_chargingData[i]->SystemStatus)
  1015. {
  1016. case S_IDLE:
  1017. {
  1018. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1019. {
  1020. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1021. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  1022. }
  1023. }
  1024. break;
  1025. case S_PREPARNING:
  1026. {
  1027. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1028. {
  1029. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1030. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1031. printf ("wait find module\n");
  1032. }
  1033. //清除 main timeout 機制
  1034. _chargingData[i]->TimeoutFlag = 0;
  1035. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1036. _chargingData[i]->Type = 9;
  1037. }
  1038. break;
  1039. case S_PREPARING_FOR_EV:
  1040. {
  1041. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1042. {
  1043. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1044. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1045. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1046. }
  1047. //清除 main timeout 機制
  1048. _chargingData[i]->TimeoutFlag = 0;
  1049. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1050. _chargingData[i]->Type = 9;
  1051. //充電電壓電流
  1052. _chargingData[i]->EvBatterySoc = 50;
  1053. _chargingData[i]->EvBatterytargetVoltage = 500;
  1054. _chargingData[i]->EvBatterytargetCurrent = 2;
  1055. _chargingData[i]->AvailableChargingCurrent = 1000;
  1056. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1057. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1058. }
  1059. break;
  1060. case S_PREPARING_FOR_EVSE:
  1061. {
  1062. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1063. {
  1064. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1065. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1066. }
  1067. //清除 main timeout 機制
  1068. _chargingData[i]->TimeoutFlag = 0;
  1069. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1070. _chargingData[i]->Type = 9;
  1071. //充電電壓電流
  1072. _chargingData[i]->EvBatterySoc = 50;
  1073. _chargingData[i]->EvBatterytargetVoltage = 500;
  1074. _chargingData[i]->EvBatterytargetCurrent = 2;
  1075. _chargingData[i]->AvailableChargingCurrent = 1000;
  1076. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1077. sleep(5);
  1078. //EV done
  1079. _chargingData[i]->SystemStatus = S_CHARGING;
  1080. }
  1081. break;
  1082. case S_CHARGING:
  1083. {
  1084. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1085. {
  1086. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1087. //充電電壓電流
  1088. _chargingData[i]->EvBatterySoc = 50;
  1089. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1090. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1091. _chargingData[i]->AvailableChargingCurrent = 1000;
  1092. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1093. }
  1094. }
  1095. break;
  1096. case S_TERMINATING:
  1097. {
  1098. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1099. {
  1100. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1101. system("/root/Module_EvComm &");
  1102. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1103. }
  1104. sleep(3);
  1105. _chargingData[i]->SystemStatus = S_COMPLETE;
  1106. }
  1107. break;
  1108. case S_COMPLETE:
  1109. {
  1110. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1111. {
  1112. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1113. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1114. }
  1115. }
  1116. break;
  1117. }
  1118. }
  1119. char word[128];
  1120. char newString[7][10];
  1121. int i,j,ctr;
  1122. memset(word, 0x00, sizeof(word));
  1123. get_char(word);
  1124. if (strlen(word) == 0)
  1125. {
  1126. continue;
  1127. }
  1128. j=0; ctr=0;
  1129. strcpy(newString[1], "-1");
  1130. strcpy(newString[2], "-1");
  1131. for (i = 0; i <= (strlen(word)); i++)
  1132. {
  1133. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1134. {
  1135. newString[ctr][j] = '\0';
  1136. ctr++;
  1137. j = 0;
  1138. }
  1139. else
  1140. {
  1141. newString[ctr][j] = word[i];
  1142. j++;
  1143. }
  1144. }
  1145. if(strcmp(newString[0], "chg") == 0)
  1146. {
  1147. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1148. continue;
  1149. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1150. continue;
  1151. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1152. continue;
  1153. int _gun = atoi(newString[1]);
  1154. float _vol = atof(newString[2]);
  1155. float _cur = atof(newString[3]);
  1156. if(_gun >= 2 || _gun < 0)
  1157. continue;
  1158. if (_cur <= 0 || _cur <= 0)
  1159. continue;
  1160. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1161. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1162. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1163. }
  1164. else if (strcmp(newString[0], "c") == 0)
  1165. {
  1166. printf("stop \n\r");
  1167. _chargingData[0]->SystemStatus = S_TERMINATING;
  1168. _chargingData[1]->SystemStatus = S_TERMINATING;
  1169. }
  1170. usleep(100000);
  1171. }
  1172. }
  1173. void SetWiringInfo(char *v1, char *v2)
  1174. {
  1175. int dispenser = atoi(v1);
  1176. int connector = atoi(v2);
  1177. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1178. {
  1179. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1180. {
  1181. printf("\r\n");
  1182. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1183. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1184. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1185. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1186. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
  1187. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1188. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1189. }
  1190. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1191. {
  1192. printf("\r\n");
  1193. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1194. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1195. int quantity = 0;
  1196. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1197. {
  1198. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1199. }
  1200. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1201. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
  1202. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1203. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1204. }
  1205. }
  1206. }
  1207. void ShowWiringInfo(void)
  1208. {
  1209. printf("\r\n");
  1210. printf("********** Wiring Info **********\r\n");
  1211. printf("Dispenser = %d, Connector = %d\r\n",
  1212. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1213. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1214. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1215. {
  1216. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1217. {
  1218. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1219. }
  1220. }
  1221. printf("\r\n");
  1222. }
  1223. void CleanWiringInfo(void)
  1224. {
  1225. printf("\r\n");
  1226. printf("******* Clean Wiring Info *******\r\n");
  1227. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1228. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
  1229. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
  1230. printf("\r\n");
  1231. }
  1232. void SetSystemSoftRest(void)
  1233. {
  1234. printf("********* Set Soft Reset ********\r\n");
  1235. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1236. }
  1237. void SetSystemHardReboot(void)
  1238. {
  1239. printf("******** Set Hard Reboot ********\r\n");
  1240. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1241. }
  1242. void SetGroupRole(byte group, byte role)
  1243. {
  1244. if(group < GENERAL_GUN_QUANTITY)
  1245. {
  1246. if(ShmGroupCollection[group].Role != role)
  1247. {
  1248. //printf("\r\nSet Group %d Role = %d", group, role);
  1249. }
  1250. ShmGroupCollection[group].Role = role;
  1251. }
  1252. }
  1253. void SetGroupToIdle(byte group)
  1254. {
  1255. if(group < GENERAL_GUN_QUANTITY)
  1256. {
  1257. SetGroupRole(group, _GROLE_IDLE);
  1258. ShmGroupCollection[group].Partner.Quantity = 0;
  1259. memset(ShmGroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
  1260. ShmGroupCollection[group].TargetGroup = 0;
  1261. //printf("\r\n Reset Group %02X To Idle", group);
  1262. }
  1263. }
  1264. void SetGroupToMaster(byte group)
  1265. {
  1266. if(group < GENERAL_GUN_QUANTITY)
  1267. {
  1268. SetGroupRole(group, _GROLE_MASTER);
  1269. ShmGroupCollection[group].TargetGroup = group + 1;
  1270. //printf("\r\n Set Group %02X As Master", group);
  1271. }
  1272. }
  1273. void SetGroupToSlave(byte group, byte target)
  1274. {
  1275. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1276. {
  1277. SetGroupRole(group, _GROLE_SLAVE);
  1278. ShmGroupCollection[group].TargetGroup = target + 1;
  1279. //printf("\r\n Set Group %02X As Slave", group);
  1280. }
  1281. }
  1282. // group: group index, target: target index
  1283. // add group to target's member
  1284. void AddGroupCollection(byte group, byte target)
  1285. {
  1286. int ParallelConfig = 0;
  1287. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1288. {
  1289. if(ShmGroupCollection[target].Role != _GROLE_MASTER)
  1290. {
  1291. return;
  1292. }
  1293. if(ShmGroupCollection[group].Role != _GROLE_IDLE &&
  1294. ShmGroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1295. ShmGroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1296. {
  1297. return;
  1298. }
  1299. SetGroupToSlave(group, target);
  1300. ShmGroupCollection[target].Partner.Member[ShmGroupCollection[target].Partner.Quantity++] = group;
  1301. ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
  1302. if(ParallelConfig != 0)
  1303. {
  1304. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1305. }
  1306. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
  1307. }
  1308. }
  1309. // group: group index, target: target index
  1310. // remove group out of target's member
  1311. void RemoveGroupCollection(byte group, byte target)
  1312. {
  1313. int location = 0, slave = 0;
  1314. bool find = false;
  1315. int ParallelConfig = 0;
  1316. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1317. {
  1318. for(int i = 0; i < ShmGroupCollection[target].Partner.Quantity; i++)
  1319. {
  1320. if(group == ShmGroupCollection[target].Partner.Member[i])
  1321. {
  1322. ShmGroupCollection[target].Partner.Member[i] = 0;
  1323. location = i;
  1324. find = true;
  1325. break;
  1326. }
  1327. }
  1328. if(find)
  1329. {
  1330. for(int i = location + 1; i < ShmGroupCollection[target].Partner.Quantity; i++)
  1331. {
  1332. slave = ShmGroupCollection[target].Partner.Member[i];
  1333. ShmGroupCollection[target].Partner.Member[i] = 0;
  1334. ShmGroupCollection[target].Partner.Member[i - 1] = slave;
  1335. }
  1336. ShmGroupCollection[target].Partner.Quantity--;
  1337. SetGroupToIdle(group);
  1338. ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
  1339. if(ParallelConfig != 0)
  1340. {
  1341. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1342. }
  1343. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
  1344. }
  1345. }
  1346. }
  1347. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1348. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1349. void ShowGroupingInfo(void)
  1350. {
  1351. byte target = 0;
  1352. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1353. for(int i = 0; i < 4; i++)
  1354. {
  1355. target = ShmPsuGrouping->Layout[i];
  1356. printf("\r\n %d (%2d) %2d %d %02X ",
  1357. target + 1, _chargingData[target]->SystemStatus, ShmGroupCollection[target].Role,
  1358. ShmGroupCollection[target].Partner.Quantity, ShmGroupCollection[target].TargetGroup);
  1359. for(int j = 0; j < 3; j++)
  1360. {
  1361. if(ShmGroupCollection[target].Role == 1 && j < ShmGroupCollection[target].Partner.Quantity)
  1362. {
  1363. printf("[%02X] ", ShmGroupCollection[target].Partner.Member[j]);
  1364. }
  1365. else
  1366. {
  1367. printf(" ");
  1368. }
  1369. }
  1370. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1371. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1372. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1373. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1374. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1375. }
  1376. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1377. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1378. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1379. printf("\r\n\r\n");
  1380. }
  1381. void PsuGroupSwitchToIdle(byte group)
  1382. {
  1383. int master = 0, quantity = 0, location = 0, total = 0;
  1384. if(ShmGroupCollection[group].Role != _GROLE_SLAVE)
  1385. {
  1386. return;
  1387. }
  1388. master = ShmGroupCollection[group].TargetGroup - 1;
  1389. quantity = ShmGroupCollection[master].Partner.Quantity;
  1390. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1391. for(int i = 0; i < quantity; i++)
  1392. {
  1393. if(total == 0)
  1394. {
  1395. if(group == ShmGroupCollection[master].Partner.Member[i])
  1396. {
  1397. location = i;
  1398. total++;
  1399. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1400. }
  1401. }
  1402. else
  1403. {
  1404. // find other group in the same direction
  1405. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1406. {
  1407. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1408. {
  1409. total++;
  1410. //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
  1411. }
  1412. }
  1413. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1414. {
  1415. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1416. {
  1417. total++;
  1418. //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. if(total > 0)
  1424. {
  1425. unsigned char collection[GENERAL_GUN_QUANTITY];
  1426. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1427. memcpy(collection, ShmGroupCollection[master].Partner.Member, ARRAY_SIZE(ShmGroupCollection[master].Partner.Member));
  1428. for(int i = 0; i < total; i++)
  1429. {
  1430. //printf(" %02X", collection[i + location]);
  1431. }
  1432. for(int i = 0; i < total; i++)
  1433. {
  1434. RemoveGroupCollection(collection[i + location], master);
  1435. }
  1436. }
  1437. }
  1438. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1439. {
  1440. int slave = 0, location = 0;
  1441. PsuGroupPartner partner;
  1442. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1443. // search from left
  1444. location = ShmGroupCollection[master].Location - 1;
  1445. for(int i = location; i >= 0; i--)
  1446. {
  1447. if(partner.Quantity >= quantity)
  1448. {
  1449. break;
  1450. }
  1451. slave = ShmPsuGrouping->Layout[i];
  1452. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1453. {
  1454. //printf("\r\n Find Group %02X From Left", slave);
  1455. partner.Member[partner.Quantity++] = slave;
  1456. }
  1457. else
  1458. {
  1459. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
  1460. {
  1461. continue;
  1462. }
  1463. break;
  1464. }
  1465. }
  1466. // search from right
  1467. location = ShmGroupCollection[master].Location + 1;
  1468. for(int i = location; i < 4; i++)
  1469. {
  1470. if(partner.Quantity >= quantity)
  1471. {
  1472. break;
  1473. }
  1474. slave = ShmPsuGrouping->Layout[i];
  1475. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1476. {
  1477. //printf("\r\n Find Group %02X From Right", slave);
  1478. partner.Member[partner.Quantity++] = slave;
  1479. }
  1480. else
  1481. {
  1482. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
  1483. {
  1484. continue;
  1485. }
  1486. break;
  1487. }
  1488. }
  1489. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1490. }
  1491. int GetPsuGroupAvailable(byte group)
  1492. {
  1493. //int slave = 0, location = 0, available = 0;
  1494. PsuGroupPartner partner;
  1495. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1496. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1497. return partner.Quantity;
  1498. #if 0
  1499. // search from left
  1500. location = ShmGroupCollection[group].Location - 1;
  1501. for(int i = location; i >= 0; i--)
  1502. {
  1503. slave = ShmPsuGrouping->Layout[i];
  1504. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1505. {
  1506. available++;
  1507. }
  1508. else
  1509. {
  1510. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1511. {
  1512. continue;
  1513. }
  1514. break;
  1515. }
  1516. }
  1517. // search from right
  1518. location = ShmGroupCollection[group].Location + 1;
  1519. for(int i = location; i < 4; i++)
  1520. {
  1521. slave = ShmPsuGrouping->Layout[i];
  1522. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1523. {
  1524. available++;
  1525. }
  1526. else
  1527. {
  1528. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1529. {
  1530. continue;
  1531. }
  1532. break;
  1533. }
  1534. }
  1535. return available;
  1536. #endif
  1537. }
  1538. void PsuGroupShareCheck(byte group)
  1539. {
  1540. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1541. total = GetPsuGroupAvailable(group) + 1;
  1542. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1543. // search from left
  1544. location = ShmGroupCollection[group].Location - 1;
  1545. for(int i = location; i >= 0; i--)
  1546. {
  1547. slave = ShmPsuGrouping->Layout[i];
  1548. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
  1549. {
  1550. target = ShmGroupCollection[slave].TargetGroup - 1;
  1551. if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
  1552. {
  1553. share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1554. }
  1555. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
  1556. break;
  1557. }
  1558. else
  1559. {
  1560. break;
  1561. }
  1562. }
  1563. if(share == 0)
  1564. {
  1565. // search from right
  1566. location = ShmGroupCollection[group].Location + 1;
  1567. for(int i = location; i < 4; i++)
  1568. {
  1569. slave = ShmPsuGrouping->Layout[i];
  1570. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
  1571. {
  1572. target = ShmGroupCollection[slave].TargetGroup - 1;
  1573. if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
  1574. {
  1575. share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1576. }
  1577. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
  1578. break;
  1579. }
  1580. else
  1581. {
  1582. break;
  1583. }
  1584. }
  1585. }
  1586. if(share > 0)
  1587. {
  1588. //printf("\r\n Grab %02X", slave);
  1589. PsuGroupSwitchToIdle(slave);
  1590. }
  1591. else
  1592. {
  1593. //printf("\r\n No Need To Grab");
  1594. }
  1595. }
  1596. void SimplePsuGroupStartCharging(byte group)
  1597. {
  1598. //int slave = 0, location = 0;
  1599. int available = 0;
  1600. PsuGroupPartner partner;
  1601. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1602. {
  1603. return;
  1604. }
  1605. if(ShmGroupCollection[group].Role != _GROLE_IDLE && ShmGroupCollection[group].Role != _GROLE_MASTER)
  1606. {
  1607. return;
  1608. }
  1609. if(ShmGroupCollection[group].Role == _GROLE_IDLE)
  1610. {
  1611. SetGroupToMaster(group);
  1612. PsuGroupShareCheck(group);
  1613. }
  1614. else
  1615. {
  1616. available = GetPsuGroupAvailable(group);
  1617. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1618. if(available == 0)
  1619. {
  1620. return;
  1621. }
  1622. }
  1623. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1624. for(int i = 0; i < partner.Quantity; i++)
  1625. {
  1626. AddGroupCollection(partner.Member[i], group);
  1627. }
  1628. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1629. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1630. #if 0
  1631. // search from left
  1632. location = ShmGroupCollection[group].Location - 1;
  1633. for(int i = location; i >= 0; i--)
  1634. {
  1635. slave = ShmPsuGrouping->Layout[i];
  1636. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1637. {
  1638. //printf("\r\n Find %02X From Left", slave);
  1639. AddGroupCollection(slave, group);
  1640. }
  1641. else
  1642. {
  1643. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1644. {
  1645. continue;
  1646. }
  1647. break;
  1648. }
  1649. }
  1650. // search from right
  1651. location = ShmGroupCollection[group].Location + 1;
  1652. for(int i = location; i < 4; i++)
  1653. {
  1654. slave = ShmPsuGrouping->Layout[i];
  1655. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1656. {
  1657. //printf("\r\n Find %02X From Right", slave);
  1658. AddGroupCollection(slave, group);
  1659. }
  1660. else
  1661. {
  1662. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1663. {
  1664. continue;
  1665. }
  1666. break;
  1667. }
  1668. }
  1669. #endif
  1670. }
  1671. void PsuGroupStopCharging(byte group)
  1672. {
  1673. int total = 0;
  1674. if(ShmGroupCollection[group].Role != _GROLE_MASTER)
  1675. {
  1676. return;
  1677. }
  1678. total = ShmGroupCollection[group].Partner.Quantity;
  1679. if(total > 0)
  1680. {
  1681. unsigned char collection[GENERAL_GUN_QUANTITY];
  1682. //printf("\r\n There are %d Group Need To Stop:", ShmGroupCollection[group].Partner.Quantity);
  1683. memcpy(collection, ShmGroupCollection[group].Partner.Member, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
  1684. for(int i = 0; i < total; i++)
  1685. {
  1686. //printf(" %02X", collection[i]);
  1687. }
  1688. for(int i = 0; i < total; i++)
  1689. {
  1690. RemoveGroupCollection(collection[i], group);
  1691. }
  1692. }
  1693. SetGroupToIdle(group);
  1694. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1695. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1696. }
  1697. void RunSimplePsuGrouping(char *v1, char *v2)
  1698. {
  1699. int group = 0, charging = 0;
  1700. group = atoi(v1);
  1701. charging = atoi(v2);
  1702. group -= 1;
  1703. if(group >= 0 && group < 4)
  1704. {
  1705. if(charging > 0)
  1706. {
  1707. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1708. {
  1709. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1710. PsuGroupSwitchToIdle(group);
  1711. }
  1712. SimplePsuGroupStartCharging(group);
  1713. }
  1714. if(charging == 0)
  1715. {
  1716. if(ShmGroupCollection[group].Role == _GROLE_MASTER)
  1717. {
  1718. PsuGroupStopCharging(group);
  1719. }
  1720. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1721. {
  1722. PsuGroupSwitchToIdle(group);
  1723. }
  1724. }
  1725. ShowGroupingInfo();
  1726. }
  1727. }
  1728. void ShowCabinetInfo(void)
  1729. {
  1730. int ipAddress = 0;
  1731. printf("\r\nPower Cabinet Charging Mode = %d, ReAssignedFlag = %d, Psu Work Step = %d",
  1732. ShmSysConfigAndInfo->SysInfo.MainChargingMode, ShmSysConfigAndInfo->SysInfo.ReAssignedFlag, ShmPsuData->Work_Step);
  1733. printf("\r\n Dispenser: %d / %d, Connector: %d / %d",
  1734. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1735. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1736. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1737. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1738. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1739. {
  1740. printf("\r\n Connector[%d] Index: %d, Status = %2d , %s", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
  1741. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? "Enable" : "Disable");
  1742. }
  1743. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  1744. {
  1745. printf("\r\n Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  1746. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  1747. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  1748. {
  1749. ipAddress = 0;
  1750. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  1751. {
  1752. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
  1753. i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
  1754. {
  1755. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
  1756. }
  1757. }
  1758. printf(", ModelName: %s, IP: %d.%d.%d.%d", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
  1759. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  1760. for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
  1761. {
  1762. printf("\r\n - Connector[%d] Gun %d", j, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j]);
  1763. }
  1764. }
  1765. else
  1766. {
  1767. printf(", No Information");
  1768. }
  1769. }
  1770. printf("\r\n\r\n");
  1771. }
  1772. void SetTestControl(char *v1, char *v2)
  1773. {
  1774. int testItem = 0;
  1775. int testItemLen = 3;
  1776. int enable = 0;
  1777. char strTest[32][32] = {"tbl", "tfsb", "chgsm"};
  1778. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation"};
  1779. enable = atoi(v2);
  1780. if(enable < 0)
  1781. {
  1782. return;
  1783. }
  1784. for(int i = 0; i < testItemLen; i++)
  1785. {
  1786. if(strcmp((char *)&strTest[i][0], v1) == 0)
  1787. {
  1788. testItem = i + 1;
  1789. break;
  1790. }
  1791. }
  1792. if(testItem != 0)
  1793. {
  1794. if(enable)
  1795. {
  1796. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  1797. }
  1798. else
  1799. {
  1800. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  1801. }
  1802. printf("%s %s Test Item, Test Control Value = %08X\n",
  1803. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  1804. }
  1805. else
  1806. {
  1807. printf("Test Item %s Not Found\n", v1);
  1808. for(int i = 0; i < testItemLen; i++)
  1809. {
  1810. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  1811. }
  1812. }
  1813. printf("\r\n");
  1814. }
  1815. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading
  1816. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX
  1817. void ShowGroupingDemand(void)
  1818. {
  1819. byte target = 0;
  1820. unsigned char k1k2 = 0;
  1821. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading");
  1822. for(int i = 0; i < 4; i++)
  1823. {
  1824. target = ShmPsuGrouping->Layout[i];
  1825. if(ShmGroupCollection[target].TargetGroup != 0)
  1826. {
  1827. k1k2 = _chargingData[ShmGroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  1828. }
  1829. else
  1830. {
  1831. k1k2 = _chargingData[target]->RelayK1K2Status;
  1832. }
  1833. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  1834. target + 1, ShmGroupCollection[target].Role, ShmGroupCollection[target].TargetGroup, k1k2,
  1835. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  1836. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  1837. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  1838. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1839. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  1840. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  1841. if(ShmGroupCollection[target].TargetGroup == target + 1)
  1842. {
  1843. printf(" %3d.%02d", (ShmGroupCollection[target].GunLoading / 100), (ShmGroupCollection[target].GunLoading % 100));
  1844. }
  1845. }
  1846. printf("\r\n\r\n");
  1847. }
  1848. // v1: gun
  1849. // v2: voltage
  1850. // v3: current
  1851. void SetGunStartCharging(char *v1, char *v2, char *v3)
  1852. {
  1853. int gun = 0;
  1854. float _voltage = 0, _current = 0;
  1855. gun = atoi(v1);
  1856. _voltage = atof(v2);
  1857. _current = atof(v3);
  1858. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  1859. {
  1860. printf("\r\nGun Start Charging Input parameter %s, %s, %s over range", v1, v2, v3);
  1861. printf("\r\n\r\n");
  1862. return;
  1863. }
  1864. /*
  1865. if(_chargingData[gun - 1]->SystemStatus == S_IDLE)
  1866. {
  1867. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1868. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  1869. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  1870. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1871. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1872. }
  1873. else if(ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
  1874. {
  1875. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  1876. {
  1877. printf("\r\nSet Gun %d > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1878. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1879. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1880. }
  1881. else
  1882. {
  1883. printf("\r\nGun %d Force Charging Is Disable", gun);
  1884. }
  1885. }
  1886. else
  1887. {
  1888. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  1889. }
  1890. printf("\r\n\r\n");
  1891. */
  1892. bool wait = true;
  1893. int time = 0;
  1894. struct timeval _Wait_time;
  1895. unsigned char PreviousSystemStatus = 0xFF;
  1896. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  1897. while(wait)
  1898. {
  1899. switch(_chargingData[gun - 1]->SystemStatus)
  1900. {
  1901. case S_IDLE:
  1902. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1903. {
  1904. printf("\r\nGun %d S_IDLE", gun);
  1905. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1906. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  1907. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  1908. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1909. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1910. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1911. }
  1912. break;
  1913. case S_REASSIGN_CHECK:
  1914. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1915. {
  1916. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  1917. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1918. }
  1919. break;
  1920. case S_REASSIGN:
  1921. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1922. {
  1923. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  1924. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1925. }
  1926. break;
  1927. case S_PREPARNING:
  1928. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1929. {
  1930. printf("\r\nGun %d S_PREPARNING", gun);
  1931. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1932. }
  1933. break;
  1934. case S_PREPARING_FOR_EV:
  1935. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1936. {
  1937. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  1938. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1939. }
  1940. break;
  1941. case S_PREPARING_FOR_EVSE:
  1942. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1943. {
  1944. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  1945. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1946. }
  1947. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1948. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1949. {
  1950. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1951. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1952. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  1953. }
  1954. break;
  1955. case S_CHARGING:
  1956. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1957. {
  1958. printf("\r\nGun %d S_CHARGING", gun);
  1959. if(PreviousSystemStatus == 0xFF)
  1960. {
  1961. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1962. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1963. printf("\r\nGun %d Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  1964. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  1965. {
  1966. printf("\r\nSet Gun %d Force Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1967. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1968. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1969. }
  1970. }
  1971. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1972. gettimeofday(&_Wait_time, NULL);
  1973. }
  1974. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1975. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1976. {
  1977. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1978. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1979. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  1980. }
  1981. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  1982. if(time >= 3)
  1983. {
  1984. wait = false;
  1985. printf("\r\nDone");
  1986. }
  1987. break;
  1988. case S_TERMINATING:
  1989. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1990. {
  1991. printf("\r\nGun %d S_TERMINATING", gun);
  1992. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1993. }
  1994. wait = false;
  1995. break;
  1996. case S_COMPLETE:
  1997. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1998. {
  1999. printf("\r\nGun %d S_COMPLETE", gun);
  2000. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2001. }
  2002. wait = false;
  2003. break;
  2004. case S_ALARM:
  2005. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2006. {
  2007. printf("\r\nGun %d S_ALARM", gun);
  2008. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2009. }
  2010. wait = false;
  2011. break;
  2012. default:
  2013. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2014. {
  2015. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2016. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2017. }
  2018. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2019. wait = false;
  2020. break;
  2021. }
  2022. char word[128];
  2023. char newString[7][10];
  2024. int i,j,ctr;
  2025. memset(word, 0x00, sizeof(word));
  2026. get_char(word);
  2027. if (strlen(word) == 0)
  2028. {
  2029. continue;
  2030. }
  2031. j=0; ctr=0;
  2032. strcpy(newString[1], "-1");
  2033. strcpy(newString[2], "-1");
  2034. for (i = 0; i <= (strlen(word)); i++)
  2035. {
  2036. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2037. {
  2038. newString[ctr][j] = '\0';
  2039. ctr++;
  2040. j = 0;
  2041. }
  2042. else
  2043. {
  2044. newString[ctr][j] = word[i];
  2045. j++;
  2046. }
  2047. }
  2048. if(strcmp(newString[0], "c") == 0)
  2049. {
  2050. printf("\r\nStop");
  2051. wait = false;
  2052. }
  2053. usleep(100000);
  2054. }
  2055. printf("\r\n\r\n");
  2056. }
  2057. // v1: gun
  2058. void SetGunStopCharging(char *v1)
  2059. {
  2060. int gun = 0;
  2061. gun = atoi(v1);
  2062. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2063. {
  2064. printf("\r\nGun Stop Charging Input parameter %s over range", v1);
  2065. printf("\r\n\r\n");
  2066. return;
  2067. }
  2068. /*
  2069. if(_chargingData[gun - 1]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[gun - 1]->SystemStatus <= S_CHARGING)
  2070. {
  2071. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2072. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2073. }
  2074. else if(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2075. {
  2076. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2077. ShmGroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2078. }
  2079. else
  2080. {
  2081. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2082. }
  2083. printf("\r\n\r\n");
  2084. */
  2085. bool wait = true;
  2086. int time = 0;
  2087. struct timeval _Wait_time;
  2088. unsigned char PreviousSystemStatus = 0xFF;
  2089. while(wait)
  2090. {
  2091. switch(_chargingData[gun - 1]->SystemStatus)
  2092. {
  2093. case S_IDLE:
  2094. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2095. {
  2096. printf("\r\nGun %d S_IDLE", gun);
  2097. if(PreviousSystemStatus == 0xFF)
  2098. {
  2099. if(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2100. {
  2101. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2102. ShmGroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2103. }
  2104. }
  2105. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2106. gettimeofday(&_Wait_time, NULL);
  2107. }
  2108. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2109. if(time >= 3)
  2110. {
  2111. wait = false;
  2112. printf("\r\nDone");
  2113. }
  2114. break;
  2115. case S_REASSIGN_CHECK:
  2116. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2117. {
  2118. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  2119. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2120. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2121. {
  2122. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2123. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2124. }
  2125. }
  2126. break;
  2127. case S_REASSIGN:
  2128. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2129. {
  2130. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  2131. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2132. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2133. {
  2134. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2135. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2136. }
  2137. }
  2138. break;
  2139. case S_PREPARNING:
  2140. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2141. {
  2142. printf("\r\nGun %d S_PREPARNING", gun);
  2143. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2144. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2145. {
  2146. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2147. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2148. }
  2149. }
  2150. break;
  2151. case S_PREPARING_FOR_EV:
  2152. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2153. {
  2154. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  2155. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2156. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2157. {
  2158. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2159. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2160. }
  2161. }
  2162. break;
  2163. case S_PREPARING_FOR_EVSE:
  2164. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2165. {
  2166. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  2167. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2168. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2169. {
  2170. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2171. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2172. }
  2173. }
  2174. break;
  2175. case S_CHARGING:
  2176. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2177. {
  2178. printf("\r\nGun %d S_CHARGING", gun);
  2179. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2180. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2181. {
  2182. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2183. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2184. }
  2185. }
  2186. break;
  2187. case S_TERMINATING:
  2188. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2189. {
  2190. printf("\r\nGun %d S_TERMINATING", gun);
  2191. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2192. }
  2193. break;
  2194. case S_COMPLETE:
  2195. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2196. {
  2197. printf("\r\nGun %d S_COMPLETE", gun);
  2198. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2199. }
  2200. break;
  2201. case S_ALARM:
  2202. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2203. {
  2204. printf("\r\nGun %d S_ALARM", gun);
  2205. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2206. }
  2207. break;
  2208. default:
  2209. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2210. {
  2211. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2212. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2213. }
  2214. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2215. wait = false;
  2216. break;
  2217. }
  2218. char word[128];
  2219. char newString[7][10];
  2220. int i,j,ctr;
  2221. memset(word, 0x00, sizeof(word));
  2222. get_char(word);
  2223. if (strlen(word) == 0)
  2224. {
  2225. continue;
  2226. }
  2227. j=0; ctr=0;
  2228. strcpy(newString[1], "-1");
  2229. strcpy(newString[2], "-1");
  2230. for (i = 0; i <= (strlen(word)); i++)
  2231. {
  2232. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2233. {
  2234. newString[ctr][j] = '\0';
  2235. ctr++;
  2236. j = 0;
  2237. }
  2238. else
  2239. {
  2240. newString[ctr][j] = word[i];
  2241. j++;
  2242. }
  2243. }
  2244. if(strcmp(newString[0], "c") == 0)
  2245. {
  2246. printf("\r\nStop");
  2247. wait = false;
  2248. }
  2249. usleep(100000);
  2250. }
  2251. printf("\r\n\r\n");
  2252. }
  2253. void SetGunExtend(char *v1)
  2254. {
  2255. int gun = 0;
  2256. gun = atoi(v1);
  2257. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
  2258. {
  2259. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2260. ShmGroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2261. }
  2262. else
  2263. {
  2264. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2265. }
  2266. printf("\r\n\r\n");
  2267. }
  2268. // 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 ...
  2269. // 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
  2270. void ShowGunOutput(void)
  2271. {
  2272. byte target = 0;
  2273. unsigned short voltage = 0, current = 0;
  2274. 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 ...");
  2275. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2276. {
  2277. target = ShmPsuGrouping->Layout[i];
  2278. // "\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"
  2279. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2280. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2281. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2282. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2283. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2284. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2285. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2286. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2287. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2288. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2289. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2290. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2291. /*
  2292. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2293. {
  2294. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2295. }
  2296. */
  2297. }
  2298. printf("\r\n\r\n");
  2299. }
  2300. void SetGpio(char *v1, char *v2)
  2301. {
  2302. int testItem = 0;
  2303. int testItemLen = 1;
  2304. int ioOutput = 0;
  2305. char strTest[32][32] = {"4g"};
  2306. char strItem[32][32] = {"4G Reset"};
  2307. ioOutput = atoi(v2);
  2308. if(ioOutput < 0)
  2309. {
  2310. return;
  2311. }
  2312. for(int i = 0; i < testItemLen; i++)
  2313. {
  2314. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2315. {
  2316. testItem = i + 1;
  2317. break;
  2318. }
  2319. }
  2320. if(testItem != 0)
  2321. {
  2322. if(ioOutput)
  2323. {
  2324. system("echo 1 > /sys/class/gpio/gpio104/value");
  2325. }
  2326. else
  2327. {
  2328. system("echo 0 > /sys/class/gpio/gpio104/value");
  2329. }
  2330. printf("Set %s %s\n",
  2331. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2332. }
  2333. else
  2334. {
  2335. printf("Gpio Item %s Not Found\n", v1);
  2336. }
  2337. printf("\r\n");
  2338. }
  2339. void ShowStatus(void)
  2340. {
  2341. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2342. {
  2343. printf("\r\nGun %d Status = %d, Available = %d", i + 1, _chargingData[i]->SystemStatus, _chargingData[i]->IsAvailable);
  2344. printf("\r\nAlarmCode");
  2345. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s",
  2346. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2347. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2348. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2349. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2350. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2351. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err");
  2352. }
  2353. printf("\r\n");
  2354. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2355. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2356. {
  2357. printf("\r\n WarningCode:");
  2358. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2359. {
  2360. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2361. }
  2362. }
  2363. printf("\r\n\r\n");
  2364. }
  2365. int main(void)
  2366. {
  2367. if(InitShareMemory() == FAIL)
  2368. {
  2369. printf ("InitShareMemory = FAIL \n");
  2370. if(ShmStatusCodeData != NULL)
  2371. {
  2372. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2373. }
  2374. sleep(5);
  2375. return 0;
  2376. }
  2377. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2378. {
  2379. if (!FindChargingInfoData(i, &_chargingData[0]))
  2380. {
  2381. return 0;
  2382. }
  2383. }
  2384. /*
  2385. memset(&ShmGroupCollection[0], 0x00, sizeof(PsuGroupCollectionData));
  2386. memset(&ShmGroupCollection[1], 0x00, sizeof(PsuGroupCollectionData));
  2387. memset(&ShmGroupCollection[2], 0x00, sizeof(PsuGroupCollectionData));
  2388. memset(&ShmGroupCollection[3], 0x00, sizeof(PsuGroupCollectionData));
  2389. ShmGroupCollection[0].Index = 0;
  2390. ShmGroupCollection[1].Index = 1;
  2391. ShmGroupCollection[2].Index = 2;
  2392. ShmGroupCollection[3].Index = 3;
  2393. ShmGroupCollection[0].Location = 0;
  2394. ShmGroupCollection[1].Location = 3;
  2395. ShmGroupCollection[2].Location = 1;
  2396. ShmGroupCollection[3].Location = 2;
  2397. */
  2398. for(;;)
  2399. {
  2400. char word[128];
  2401. char newString[7][10];
  2402. int i,j,ctr;
  2403. fgets(word, sizeof(word), stdin);
  2404. j=0; ctr=0;
  2405. strcpy(newString[1], "-1");
  2406. strcpy(newString[2], "-1");
  2407. for (i = 0; i <= (strlen(word)); i++)
  2408. {
  2409. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2410. {
  2411. newString[ctr][j] = '\0';
  2412. ctr++;
  2413. j = 0;
  2414. }
  2415. else
  2416. {
  2417. newString[ctr][j] = word[i];
  2418. j++;
  2419. }
  2420. }
  2421. if(strcmp(newString[0], "state") == 0)
  2422. {
  2423. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2424. continue;
  2425. // 槍狀態
  2426. RunStatusProc(newString[1], newString[2]);
  2427. }
  2428. else if(strcmp(newString[0], "card") == 0)
  2429. {
  2430. // 刷卡狀態
  2431. RunCardProc(newString[1], newString[2]);
  2432. }
  2433. else if(strcmp(newString[0], "gun") == 0)
  2434. {
  2435. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2436. continue;
  2437. // 插槍狀態
  2438. RunGunPlugitProc(newString[1], newString[2]);
  2439. }
  2440. else if(strcmp(newString[0], "lock") == 0)
  2441. {
  2442. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2443. continue;
  2444. // 插槍狀態
  2445. GetGunLockStatusProc(newString[1], newString[2]);
  2446. }
  2447. else if(strcmp(newString[0], "sysid") == 0)
  2448. {
  2449. // 測試 sys id
  2450. SetSystemIDProc();
  2451. }
  2452. else if(strcmp(newString[0], "self") == 0)
  2453. {
  2454. // CSU 自我檢測狀態
  2455. RunSelfProc(newString[1]);
  2456. }
  2457. else if(strcmp(newString[0], "ver") == 0)
  2458. {
  2459. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2460. continue;
  2461. // 取 FW 版號
  2462. GetFwVerProc(newString[1]);
  2463. }
  2464. else if (strcmp(newString[0], "update") == 0)
  2465. {
  2466. // 更新
  2467. FwUpdateFlagProc(newString[1]);
  2468. }
  2469. else if (strcmp(newString[0], "ac") == 0)
  2470. {
  2471. // AC contactor 狀態
  2472. CheckAcStatus(newString[1]);
  2473. }
  2474. else if (strcmp(newString[0], "cable") == 0)
  2475. {
  2476. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2477. continue;
  2478. // cable check pass
  2479. SetCableChkStatus(newString[1], newString[2]);
  2480. }
  2481. else if (strcmp(newString[0], "pow") == 0)
  2482. {
  2483. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2484. continue;
  2485. // cable check pass
  2486. SetPowerValue(newString[1], newString[2]);
  2487. }
  2488. else if (strcmp(newString[0], "model") == 0)
  2489. {
  2490. GetSystemInfo();
  2491. }
  2492. else if(strcmp(newString[0], "select") == 0)
  2493. {
  2494. // 取得 / 設定 當前選的槍號
  2495. GetGunSelectedNum(newString[1]);
  2496. }
  2497. else if(strcmp(newString[0], "change") == 0)
  2498. {
  2499. // 模擬按鈕改變選槍
  2500. ChangeGunNum();
  2501. }
  2502. else if(strcmp(newString[0], "fan") == 0)
  2503. {
  2504. // 設定風扇速度
  2505. SetFanSpeed(newString[1]);
  2506. }
  2507. else if(strcmp(newString[0], "speed") == 0)
  2508. {
  2509. // 取得風扇速度
  2510. GetFanSpeed();
  2511. }
  2512. else if(strcmp(newString[0], "debug") == 0)
  2513. {
  2514. // 設定 debug mode
  2515. SetDebugMode(newString[1]);
  2516. }
  2517. else if (strcmp(newString[0], "gfd") == 0)
  2518. {
  2519. // 設定盲沖使用 GFD 功能
  2520. SetGFDMode(newString[1]);
  2521. }
  2522. else if(strcmp(newString[0], "temp") == 0)
  2523. {
  2524. // 取得溫度
  2525. GetTemperature(newString[1]);
  2526. }
  2527. else if(strcmp(newString[0], "acin") == 0)
  2528. {
  2529. // 取得三向輸入電壓
  2530. GetAcInputVol();
  2531. }
  2532. else if(strcmp(newString[0], "psu") == 0)
  2533. {
  2534. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  2535. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2536. {
  2537. printf ("PSU : Param fail..Please retry again......\n");
  2538. continue;
  2539. }
  2540. // 取得 PSU 資訊
  2541. GetPsuInformation(newString[1], newString[2], newString[3]);
  2542. }
  2543. else if (strcmp(newString[0], "cap") == 0)
  2544. {
  2545. GetConnectorCapInfo(newString[1]);
  2546. }
  2547. else if(strcmp(newString[0], "error") == 0)
  2548. {
  2549. CreateOneError(newString[1]);
  2550. }
  2551. else if (strcmp(newString[0], "auth") == 0)
  2552. {
  2553. GetAuthorizeFlag(newString[1]);
  2554. }
  2555. else if (strcmp(newString[0], "id") == 0)
  2556. {
  2557. GetOrClearId(newString[1]);
  2558. }
  2559. #if 0
  2560. else if(strcmp(newString[0], "strchg") == 0)
  2561. {
  2562. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  2563. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2564. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2565. {
  2566. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  2567. continue;
  2568. }
  2569. // 槍狀態
  2570. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  2571. }
  2572. else if(strcmp(newString[0], "str2chg") == 0)
  2573. {
  2574. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  2575. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2576. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  2577. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  2578. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  2579. {
  2580. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  2581. continue;
  2582. }
  2583. // 槍狀態
  2584. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  2585. }
  2586. #endif
  2587. else if(strcmp(newString[0], "wiring") == 0)
  2588. {
  2589. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  2590. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  2591. {
  2592. SetWiringInfo(newString[1], newString[2]);
  2593. }
  2594. ShowWiringInfo();
  2595. }
  2596. else if(strcmp(newString[0], "cwiring") == 0)
  2597. {
  2598. CleanWiringInfo();
  2599. }
  2600. else if(strcmp(newString[0], "reset") == 0)
  2601. {
  2602. SetSystemSoftRest();
  2603. }
  2604. else if(strcmp(newString[0], "reboot") == 0)
  2605. {
  2606. SetSystemHardReboot();
  2607. }
  2608. else if(strcmp(newString[0], "sgroup") == 0)
  2609. {
  2610. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2611. {
  2612. ShowGroupingInfo();
  2613. continue;
  2614. }
  2615. RunSimplePsuGrouping(newString[1], newString[2]);
  2616. }
  2617. else if(strcmp(newString[0], "cabinet") == 0)
  2618. {
  2619. ShowCabinetInfo();
  2620. }
  2621. else if(strcmp(newString[0], "tctl") == 0)
  2622. {
  2623. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2624. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2625. {
  2626. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  2627. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  2628. continue;
  2629. }
  2630. SetTestControl(newString[1], newString[2]);
  2631. }
  2632. else if(strcmp(newString[0], "group") == 0)
  2633. {
  2634. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2635. {
  2636. ShowGroupingInfo();
  2637. continue;
  2638. }
  2639. }
  2640. else if(strcmp(newString[0], "gdmd") == 0)
  2641. {
  2642. ShowGroupingDemand();
  2643. }
  2644. else if(strcmp(newString[0], "gunchg") == 0)
  2645. {
  2646. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2647. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  2648. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  2649. {
  2650. printf ("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\n\n");
  2651. continue;
  2652. }
  2653. SetGunStartCharging(newString[1], newString[2], newString[3]);
  2654. }
  2655. else if(strcmp(newString[0], "gunstp") == 0)
  2656. {
  2657. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2658. {
  2659. printf ("Input cmd fail ------ gunstp [gun 1-4]\n\n");
  2660. continue;
  2661. }
  2662. SetGunStopCharging(newString[1]);
  2663. }
  2664. else if(strcmp(newString[0], "gunext") == 0)
  2665. {
  2666. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2667. {
  2668. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  2669. continue;
  2670. }
  2671. SetGunExtend(newString[1]);
  2672. }
  2673. else if(strcmp(newString[0], "output") == 0)
  2674. {
  2675. ShowGunOutput();
  2676. }
  2677. else if(strcmp(newString[0], "gio") == 0)
  2678. {
  2679. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2680. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2681. {
  2682. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  2683. continue;
  2684. }
  2685. SetGpio(newString[1], newString[2]);
  2686. }
  2687. else if(strcmp(newString[0], "status") == 0)
  2688. {
  2689. ShowStatus();
  2690. }
  2691. else
  2692. printf ("%s\n", msg);
  2693. usleep(100000);
  2694. }
  2695. return 0;
  2696. }