ReadCmdline.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319
  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. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  72. {
  73. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  74. {
  75. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  76. {
  77. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  78. return true;
  79. }
  80. }
  81. for (byte index = 0; index < CCS_QUANTITY; index++)
  82. {
  83. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  84. {
  85. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  86. return true;
  87. }
  88. }
  89. for (byte index = 0; index < GB_QUANTITY; index++)
  90. {
  91. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  92. {
  93. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  94. return true;
  95. }
  96. }
  97. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  98. {
  99. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  100. return true;
  101. }
  102. return false;
  103. }
  104. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  105. {
  106. if (target < AC_QUANTITY)
  107. {
  108. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  109. return true;
  110. }
  111. return false;
  112. }
  113. int InitShareMemory()
  114. {
  115. int result = PASS;
  116. int MeterSMId;
  117. //initial ShmSysConfigAndInfo
  118. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  119. {
  120. result = FAIL;
  121. }
  122. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  123. {
  124. result = FAIL;
  125. }
  126. else
  127. {}
  128. //initial ShmStatusCodeData
  129. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  130. {
  131. result = FAIL;
  132. }
  133. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  134. {
  135. result = FAIL;
  136. }
  137. else
  138. {}
  139. if (CHAdeMO_QUANTITY > 0) {
  140. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  141. IPC_CREAT | 0777)) < 0) {
  142. result = FAIL;
  143. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  144. == (void *) -1) {
  145. result = FAIL;
  146. } else {
  147. }
  148. }
  149. if (CCS_QUANTITY > 0) {
  150. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  151. IPC_CREAT | 0777)) < 0) {
  152. result = FAIL;
  153. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  154. result = FAIL;
  155. } else {
  156. }
  157. }
  158. if (GB_QUANTITY > 0) {
  159. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  160. IPC_CREAT | 0777)) < 0) {
  161. return 0;
  162. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  163. return 0;
  164. }
  165. memset(ShmGBTData, 0, sizeof(struct GBTData));
  166. }
  167. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  168. {
  169. result = FAIL;
  170. }
  171. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  172. {
  173. result = FAIL;
  174. }
  175. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  176. {
  177. result = FAIL;
  178. }
  179. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  180. {
  181. result = FAIL;
  182. }
  183. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  184. {
  185. result = FAIL;
  186. }
  187. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  188. {
  189. result = FAIL;
  190. }
  191. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  192. {
  193. result = FAIL;
  194. }
  195. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  196. {
  197. result = FAIL;
  198. }
  199. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  200. {
  201. result = FAIL;
  202. }
  203. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  204. {
  205. result = FAIL;
  206. }
  207. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  208. {
  209. result = FAIL;
  210. }
  211. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  212. {
  213. result = FAIL;
  214. }
  215. if(result == PASS)
  216. {
  217. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  218. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  219. ShmGroupCollection = &ShmChargerInfo->PsuGrouping.GroupCollection[0];
  220. }
  221. return result;
  222. }
  223. unsigned long GetTimeoutValue(struct timeval _sour_time)
  224. {
  225. struct timeval _end_time;
  226. gettimeofday(&_end_time, NULL);
  227. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  228. }
  229. void RunStatusProc(char *v1, char *v2)
  230. {
  231. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  232. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  233. if (strcmp(v1, "ac") == 0)
  234. {
  235. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  236. {
  237. printf("FindChargingInfoData (AC) false \n");
  238. }
  239. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  240. return;
  241. }
  242. int _index = atoi(v1);
  243. if (_index <= 1)
  244. {
  245. if (!FindChargingInfoData(_index, &_chargingData[0]))
  246. {
  247. printf ("FindChargingInfoData error\n");
  248. return;
  249. }
  250. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  251. {
  252. // get
  253. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  254. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  255. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  256. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  257. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  258. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  259. //printf("ConnectorAlarmCode = %s \n", ShmOCPP16Data->StatusNotification[index].ErrorCode);
  260. //printf("ConnectorAlarmCode = %s \n", ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
  261. }
  262. else
  263. {
  264. // set
  265. _chargingData[_index]->SystemStatus = atoi(v2);
  266. }
  267. }
  268. else
  269. {
  270. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  271. {
  272. printf("FindChargingInfoData (AC) false \n");
  273. }
  274. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  275. {
  276. // get
  277. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  278. }
  279. else
  280. {
  281. // set
  282. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  283. }
  284. }
  285. }
  286. void RunCardProc(char *v1, char *v2)
  287. {
  288. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  289. {
  290. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  291. {
  292. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  293. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  294. }
  295. else
  296. {
  297. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  298. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  299. }
  300. }
  301. else
  302. {
  303. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  304. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  305. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  306. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  307. }
  308. }
  309. void RunGunPlugitProc(char *v1, char *v2)
  310. {
  311. if (strcmp(v1, "ac") == 0)
  312. {
  313. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  314. {
  315. printf("FindChargingInfoData (AC) false \n");
  316. }
  317. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  318. {
  319. // get
  320. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  321. }
  322. else
  323. {
  324. // set
  325. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  326. }
  327. return;
  328. }
  329. int _index = atoi(v1);
  330. if (!FindChargingInfoData(_index, &_chargingData[0]))
  331. {
  332. printf("FindChargingInfoData error\n");
  333. return;
  334. }
  335. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  336. {
  337. // get
  338. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  339. }
  340. else
  341. {
  342. // set
  343. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  344. }
  345. }
  346. void GetGunLockStatusProc(char *v1, char *v2)
  347. {
  348. int _index = atoi(v1);
  349. if (!FindChargingInfoData(_index, &_chargingData[0]))
  350. {
  351. printf("FindChargingInfoData error\n");
  352. return;
  353. }
  354. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  355. {
  356. _chargingData[_index]->GunLocked = atoi(v2);
  357. }
  358. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  359. }
  360. void SetSystemIDProc()
  361. {
  362. char *systemId = "Alston_Test";
  363. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  364. }
  365. void RunSelfProc()
  366. {
  367. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  368. }
  369. void GetFwVerProc(char *v1)
  370. {
  371. if (strcmp(v1, "407") == 0)
  372. {
  373. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  374. }
  375. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  376. {
  377. int _index = atoi(v1);
  378. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  379. {
  380. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  381. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  382. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  383. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  384. {
  385. if(ParentIndex == 0)
  386. {
  387. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  388. }
  389. else
  390. {
  391. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  392. }
  393. }
  394. }
  395. else
  396. {
  397. printf("Gun %d is disable\r\n", _index);
  398. }
  399. }
  400. else if (strcmp(v1, "rb") == 0)
  401. {
  402. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  403. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  404. }
  405. else if (strcmp(v1, "fan") == 0)
  406. {
  407. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  408. }
  409. else if (strcmp(v1, "dc") == 0)
  410. {
  411. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  412. }
  413. else if (strcmp(v1, "led") == 0)
  414. {
  415. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  416. }
  417. }
  418. void CreateOneError(char *v1)
  419. {
  420. int value = atoi(v1);
  421. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  422. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  423. }
  424. void GetAuthorizeFlag(char *v1)
  425. {
  426. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  427. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  428. else
  429. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  430. }
  431. void GetOrClearId(char *v1)
  432. {
  433. int _index = atoi(v1);
  434. if (!FindChargingInfoData(_index, &_chargingData[0]))
  435. {
  436. printf("FindChargingInfoData error\n");
  437. return;
  438. }
  439. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  440. }
  441. void FwUpdateFlagProc()
  442. {
  443. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  444. }
  445. void CheckAcStatus(char *v1)
  446. {
  447. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  448. {
  449. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  450. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  451. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  452. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  453. }
  454. else
  455. {
  456. if(system("pidof -s main > /dev/null") != 0)
  457. {
  458. if(strcmp(v1, "0") == 0)
  459. {
  460. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  461. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  462. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  463. printf("Set AC Contactor Off\r\n");
  464. }
  465. else
  466. {
  467. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  468. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  469. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  470. printf("Set AC Contactor On\r\n");
  471. }
  472. }
  473. else
  474. {
  475. printf("main task is running\r\n");
  476. }
  477. }
  478. }
  479. void SetCableChkStatus(char *v1, char *v2)
  480. {
  481. int _index = atoi(v1);
  482. if (!FindChargingInfoData(_index, &_chargingData[0]))
  483. {
  484. printf ("FindChargingInfoData error\n");
  485. return;
  486. }
  487. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  488. }
  489. void SetPowerValue(char *v1, char *v2)
  490. {
  491. int _index = atoi(v1);
  492. float _Current = atof(v2);
  493. // 盲沖的時候才允許使用~
  494. if (_chargingData[_index]->Type != 9)
  495. return;
  496. if (!FindChargingInfoData(_index, &_chargingData[0]))
  497. {
  498. printf ("FindChargingInfoData error\n");
  499. return;
  500. }
  501. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  502. }
  503. void GetSystemInfo()
  504. {
  505. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  506. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  507. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  508. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  509. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  510. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  511. }
  512. void ChangeGunNum()
  513. {
  514. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  515. {
  516. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  517. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  518. }
  519. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  520. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  521. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  522. else
  523. {
  524. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  525. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  526. }
  527. }
  528. void GetGunSelectedNum(char *v1)
  529. {
  530. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  531. {
  532. if (AC_QUANTITY > 0 &&
  533. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  534. {
  535. printf("connector select changed = AC \n");
  536. }
  537. else
  538. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  539. }
  540. else
  541. {
  542. int _index = atoi(v1);
  543. if (_index <= 1)
  544. {
  545. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  546. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  547. printf("connector select changed = %d \n", _index);
  548. }
  549. else if (AC_QUANTITY > 0)
  550. {
  551. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  552. printf("connector select changed = AC \n");
  553. }
  554. }
  555. }
  556. void SetFanSpeed(char *v1)
  557. {
  558. int speed = atoi(v1);
  559. ShmFanModuleData->TestFanSpeed = speed;
  560. }
  561. void GetFanSpeed()
  562. {
  563. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  564. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  565. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  566. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  567. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  568. }
  569. void SetDebugMode(char *v1)
  570. {
  571. int mode = atoi(v1);
  572. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  573. }
  574. void SetGFDMode(char *v1)
  575. {
  576. int mode = atoi(v1);
  577. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  578. }
  579. void GetPsuTemp()
  580. {
  581. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  582. {
  583. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  584. {
  585. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  586. }
  587. }
  588. }
  589. void GetAcInputVol()
  590. {
  591. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  592. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  593. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  594. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  595. }
  596. void GetPsuInformation(char *v1, char *v2, char *v3)
  597. {
  598. printf("**********************AC Contact needed*************************\n");
  599. if(strcmp(v1, "count") == 0)
  600. {
  601. for (int i = 0; i < 4; i++)
  602. {
  603. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  604. }
  605. }
  606. else if(strcmp(v1, "ver") == 0)
  607. {
  608. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  609. {
  610. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  611. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  612. }
  613. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  614. {
  615. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  616. {
  617. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  618. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  619. }
  620. }
  621. }
  622. else if(strcmp(v1, "cap") == 0)
  623. {
  624. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  625. {
  626. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  627. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  628. }
  629. }
  630. else if(strcmp(v1, "input") == 0)
  631. {
  632. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  633. {
  634. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  635. {
  636. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  637. i, count,
  638. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  639. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  640. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  641. }
  642. }
  643. }
  644. else if (strcmp(v1, "output") == 0)
  645. {
  646. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  647. {
  648. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  649. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  650. }
  651. }
  652. else if (strcmp(v1, "test") == 0)
  653. {
  654. int mode = atoi(v2);
  655. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  656. {
  657. ShmPsuData->Work_Step = mode;
  658. }
  659. }
  660. else if (strcmp(v1, "out") == 0)
  661. {
  662. float vol = atof(v2);
  663. float cur = atof(v3);
  664. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  665. {
  666. if (!FindChargingInfoData(0, &_chargingData[0]))
  667. {
  668. printf ("FindChargingInfoData error\n");
  669. return;
  670. }
  671. _chargingData[0]->EvBatterytargetVoltage = vol;
  672. _chargingData[0]->EvBatterytargetCurrent = cur;
  673. }
  674. }
  675. printf("*************************************************\n");
  676. }
  677. void GetConnectorCapInfo(char *v1)
  678. {
  679. int _GunIndex = atoi(v1);
  680. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  681. {
  682. printf ("FindChargingInfoData error\n");
  683. return;
  684. }
  685. printf ("Charger Max Current = %d, Max Power = %d \n",
  686. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  687. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  688. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  689. _GunIndex,
  690. _chargingData[_GunIndex]->RealMaxPower,
  691. _chargingData[_GunIndex]->RealMaxVoltage,
  692. _chargingData[_GunIndex]->RealMaxCurrent);
  693. }
  694. static void get_char(char *word)
  695. {
  696. fd_set rfds;
  697. struct timeval tv;
  698. FD_ZERO(&rfds);
  699. FD_SET(0, &rfds);
  700. tv.tv_sec = 0;
  701. tv.tv_usec = 10; //wait input timout time
  702. //if input
  703. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  704. {
  705. fgets(word, 128, stdin);
  706. }
  707. }
  708. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  709. {
  710. int _GunIndex = atoi(v1);
  711. float _Voltage = atof(v2);
  712. float _Current = atof(v3);
  713. unsigned char PreviousSystemStatus = 0xff;
  714. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  715. {
  716. printf ("FindChargingInfoData error\n");
  717. return;
  718. }
  719. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  720. if(_Voltage > 1000 || _Voltage < 50)
  721. {
  722. printf ("Input Voltage over range\n");
  723. return;
  724. }
  725. // if(_Current > 100 || _Current < 2){
  726. //
  727. // printf ("Input Current over range\n");
  728. // return;
  729. // }
  730. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  731. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  732. //kill ev task
  733. system("killall Module_EvComm");
  734. //_Voltage = (_Voltage * 10);
  735. //_Current = (_Current * 10);
  736. //system(STTY_US TTY_PATH);
  737. while(true)
  738. {
  739. //fix gun 1
  740. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  741. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  742. {
  743. case S_IDLE:
  744. {
  745. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  746. {
  747. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  748. printf ("[UnconditionalCharge - S_IDLE]\n");
  749. }
  750. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  751. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  752. }
  753. break;
  754. case S_PREPARNING:
  755. {
  756. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  757. {
  758. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  759. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  760. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  761. printf ("wait find module\n");
  762. }
  763. //main 會在此階段判斷以下資料跳到下一個 state
  764. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  765. //ShmPsuData->SystemPresentPsuQuantity;
  766. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  767. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  768. //_chargingData[gun_index]->AvailableChargingPower;
  769. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  770. //sleep(10);
  771. //清除 main timeout 機制
  772. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  773. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  774. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  775. }
  776. break;
  777. case S_PREPARING_FOR_EV:
  778. {
  779. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  780. {
  781. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  782. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  783. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  784. }
  785. //清除 main timeout 機制
  786. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  787. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  788. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  789. //充電電壓電流
  790. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  791. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  792. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  793. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  794. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  795. //確定模組己升壓完成
  796. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  797. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  798. {
  799. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  800. //EV done
  801. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  802. }
  803. }
  804. break;
  805. case S_PREPARING_FOR_EVSE:
  806. {
  807. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  808. {
  809. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  810. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  811. }
  812. //printf ("tar vol = %d \n", _Voltage);
  813. //printf ("tar cur = %d \n", _Current);
  814. //清除 main timeout 機制
  815. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  816. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  817. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  818. //充電電壓電流
  819. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  820. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  821. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  822. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  823. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  824. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  825. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  826. //確定模組己升壓完成
  827. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  828. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  829. //{
  830. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  831. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  832. sleep(5);
  833. //EV done
  834. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  835. //}
  836. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  837. //{
  838. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  839. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  840. //}
  841. }
  842. break;
  843. case S_CHARGING:
  844. {
  845. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  846. {
  847. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  848. //充電電壓電流
  849. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  850. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  851. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  852. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  853. printf ("[UnconditionalCharge - S_CHARGING]\n");
  854. }
  855. //ev task do this
  856. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  857. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  858. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  859. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  860. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  861. }
  862. }
  863. break;
  864. case S_TERMINATING:
  865. {
  866. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  867. {
  868. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  869. system("/root/Module_EvComm &");
  870. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  871. //無阻塞偵測 keybaord 結束
  872. system(STTY_DEF TTY_PATH);
  873. }
  874. sleep(3);
  875. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  876. return;
  877. }
  878. break;
  879. case S_COMPLETE:
  880. {
  881. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  882. {
  883. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  884. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  885. }
  886. sleep(3);
  887. return;
  888. }
  889. break;
  890. }
  891. char word[128];
  892. char newString[7][10];
  893. int i,j,ctr;
  894. memset(word, 0x00, sizeof(word));
  895. get_char(word);
  896. if (strlen(word) == 0)
  897. {
  898. continue;
  899. }
  900. j=0; ctr=0;
  901. strcpy(newString[1], "-1");
  902. strcpy(newString[2], "-1");
  903. for (i = 0; i <= (strlen(word)); i++)
  904. {
  905. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  906. {
  907. newString[ctr][j] = '\0';
  908. ctr++;
  909. j = 0;
  910. }
  911. else
  912. {
  913. newString[ctr][j] = word[i];
  914. j++;
  915. }
  916. }
  917. if(strcmp(newString[0], "chg") == 0)
  918. {
  919. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  920. continue;
  921. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  922. continue;
  923. float _vol = atof(newString[1]);
  924. float _cur = atof(newString[2]);
  925. if (_cur <= 0 || _cur <= 0)
  926. continue;
  927. printf("vol = %f, cur = %f \n", _vol, _cur);
  928. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  929. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  930. }
  931. else if (strcmp(newString[0], "c") == 0)
  932. {
  933. printf("stop \n\r");
  934. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  935. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  936. }
  937. usleep(100000);
  938. }
  939. }
  940. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  941. {
  942. float _Voltage[2], _Current[2];
  943. _Voltage[0] = atof(v1);
  944. _Current[0] = atof(v2);
  945. _Voltage[1] = atof(v3);
  946. _Current[1] = atof(v4);
  947. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  948. if(!FindChargingInfoData(0, &_chargingData[0]))
  949. {
  950. printf ("FindChargingInfoData 0 error\n");
  951. return;
  952. }
  953. if(!FindChargingInfoData(1, &_chargingData[0]))
  954. {
  955. printf ("FindChargingInfoData 1 error\n");
  956. return;
  957. }
  958. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  959. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  960. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  961. {
  962. printf ("Input Voltage over range\n");
  963. return;
  964. }
  965. //kill ev task
  966. system("killall Module_EvComm");
  967. while(true)
  968. {
  969. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  970. {
  971. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  972. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  973. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  974. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  975. }
  976. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  977. {
  978. system(STTY_DEF TTY_PATH);
  979. sleep(5);
  980. return;
  981. }
  982. for(int i = 0; i < 2; i++)
  983. {
  984. switch(_chargingData[i]->SystemStatus)
  985. {
  986. case S_IDLE:
  987. {
  988. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  989. {
  990. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  991. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  992. }
  993. }
  994. break;
  995. case S_PREPARNING:
  996. {
  997. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  998. {
  999. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1000. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1001. printf ("wait find module\n");
  1002. }
  1003. //清除 main timeout 機制
  1004. _chargingData[i]->TimeoutFlag = 0;
  1005. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1006. _chargingData[i]->Type = 9;
  1007. }
  1008. break;
  1009. case S_PREPARING_FOR_EV:
  1010. {
  1011. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1012. {
  1013. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1014. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1015. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1016. }
  1017. //清除 main timeout 機制
  1018. _chargingData[i]->TimeoutFlag = 0;
  1019. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1020. _chargingData[i]->Type = 9;
  1021. //充電電壓電流
  1022. _chargingData[i]->EvBatterySoc = 50;
  1023. _chargingData[i]->EvBatterytargetVoltage = 500;
  1024. _chargingData[i]->EvBatterytargetCurrent = 2;
  1025. _chargingData[i]->AvailableChargingCurrent = 1000;
  1026. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1027. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1028. }
  1029. break;
  1030. case S_PREPARING_FOR_EVSE:
  1031. {
  1032. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1033. {
  1034. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1035. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1036. }
  1037. //清除 main timeout 機制
  1038. _chargingData[i]->TimeoutFlag = 0;
  1039. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1040. _chargingData[i]->Type = 9;
  1041. //充電電壓電流
  1042. _chargingData[i]->EvBatterySoc = 50;
  1043. _chargingData[i]->EvBatterytargetVoltage = 500;
  1044. _chargingData[i]->EvBatterytargetCurrent = 2;
  1045. _chargingData[i]->AvailableChargingCurrent = 1000;
  1046. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1047. sleep(5);
  1048. //EV done
  1049. _chargingData[i]->SystemStatus = S_CHARGING;
  1050. }
  1051. break;
  1052. case S_CHARGING:
  1053. {
  1054. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1055. {
  1056. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1057. //充電電壓電流
  1058. _chargingData[i]->EvBatterySoc = 50;
  1059. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1060. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1061. _chargingData[i]->AvailableChargingCurrent = 1000;
  1062. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1063. }
  1064. }
  1065. break;
  1066. case S_TERMINATING:
  1067. {
  1068. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1069. {
  1070. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1071. system("/root/Module_EvComm &");
  1072. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1073. }
  1074. sleep(3);
  1075. _chargingData[i]->SystemStatus = S_COMPLETE;
  1076. }
  1077. break;
  1078. case S_COMPLETE:
  1079. {
  1080. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1081. {
  1082. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1083. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1084. }
  1085. }
  1086. break;
  1087. }
  1088. }
  1089. char word[128];
  1090. char newString[7][10];
  1091. int i,j,ctr;
  1092. memset(word, 0x00, sizeof(word));
  1093. get_char(word);
  1094. if (strlen(word) == 0)
  1095. {
  1096. continue;
  1097. }
  1098. j=0; ctr=0;
  1099. strcpy(newString[1], "-1");
  1100. strcpy(newString[2], "-1");
  1101. for (i = 0; i <= (strlen(word)); i++)
  1102. {
  1103. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1104. {
  1105. newString[ctr][j] = '\0';
  1106. ctr++;
  1107. j = 0;
  1108. }
  1109. else
  1110. {
  1111. newString[ctr][j] = word[i];
  1112. j++;
  1113. }
  1114. }
  1115. if(strcmp(newString[0], "chg") == 0)
  1116. {
  1117. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1118. continue;
  1119. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1120. continue;
  1121. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1122. continue;
  1123. int _gun = atoi(newString[1]);
  1124. float _vol = atof(newString[2]);
  1125. float _cur = atof(newString[3]);
  1126. if(_gun >= 2 || _gun < 0)
  1127. continue;
  1128. if (_cur <= 0 || _cur <= 0)
  1129. continue;
  1130. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1131. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1132. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1133. }
  1134. else if (strcmp(newString[0], "c") == 0)
  1135. {
  1136. printf("stop \n\r");
  1137. _chargingData[0]->SystemStatus = S_TERMINATING;
  1138. _chargingData[1]->SystemStatus = S_TERMINATING;
  1139. }
  1140. usleep(100000);
  1141. }
  1142. }
  1143. void SetWiringInfo(char *v1, char *v2)
  1144. {
  1145. int dispenser = atoi(v1);
  1146. int connector = atoi(v2);
  1147. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1148. {
  1149. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1150. {
  1151. printf("\r\n");
  1152. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1153. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1154. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1155. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1156. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
  1157. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1158. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1159. }
  1160. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1161. {
  1162. printf("\r\n");
  1163. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1164. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1165. int quantity = 0;
  1166. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1167. {
  1168. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1169. }
  1170. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1171. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
  1172. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1173. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1174. }
  1175. }
  1176. }
  1177. void ShowWiringInfo(void)
  1178. {
  1179. printf("\r\n");
  1180. printf("********** Wiring Info **********\r\n");
  1181. printf("Dispenser = %d, Connector = %d\r\n",
  1182. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1183. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1184. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1185. {
  1186. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1187. {
  1188. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1189. }
  1190. }
  1191. printf("\r\n");
  1192. }
  1193. void CleanWiringInfo(void)
  1194. {
  1195. printf("\r\n");
  1196. printf("******* Clean Wiring Info *******\r\n");
  1197. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1198. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
  1199. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
  1200. printf("\r\n");
  1201. }
  1202. void SetSystemSoftRest(void)
  1203. {
  1204. printf("********* Set Soft Reset ********\r\n");
  1205. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1206. }
  1207. void SetSystemHardReboot(void)
  1208. {
  1209. printf("******** Set Hard Reboot ********\r\n");
  1210. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1211. }
  1212. void SetGroupRole(byte group, byte role)
  1213. {
  1214. if(group < GENERAL_GUN_QUANTITY)
  1215. {
  1216. if(ShmGroupCollection[group].Role != role)
  1217. {
  1218. //printf("\r\nSet Group %d Role = %d", group, role);
  1219. }
  1220. ShmGroupCollection[group].Role = role;
  1221. }
  1222. }
  1223. void SetGroupToIdle(byte group)
  1224. {
  1225. if(group < GENERAL_GUN_QUANTITY)
  1226. {
  1227. SetGroupRole(group, _GROLE_IDLE);
  1228. ShmGroupCollection[group].Partner.Quantity = 0;
  1229. memset(ShmGroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
  1230. ShmGroupCollection[group].TargetGroup = 0;
  1231. //printf("\r\n Reset Group %02X To Idle", group);
  1232. }
  1233. }
  1234. void SetGroupToMaster(byte group)
  1235. {
  1236. if(group < GENERAL_GUN_QUANTITY)
  1237. {
  1238. SetGroupRole(group, _GROLE_MASTER);
  1239. ShmGroupCollection[group].TargetGroup = group + 1;
  1240. //printf("\r\n Set Group %02X As Master", group);
  1241. }
  1242. }
  1243. void SetGroupToSlave(byte group, byte target)
  1244. {
  1245. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1246. {
  1247. SetGroupRole(group, _GROLE_SLAVE);
  1248. ShmGroupCollection[group].TargetGroup = target + 1;
  1249. //printf("\r\n Set Group %02X As Slave", group);
  1250. }
  1251. }
  1252. // group: group index, target: target index
  1253. // add group to target's member
  1254. void AddGroupCollection(byte group, byte target)
  1255. {
  1256. int ParallelConfig = 0;
  1257. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1258. {
  1259. if(ShmGroupCollection[target].Role != _GROLE_MASTER)
  1260. {
  1261. return;
  1262. }
  1263. if(ShmGroupCollection[group].Role != _GROLE_IDLE &&
  1264. ShmGroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1265. ShmGroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1266. {
  1267. return;
  1268. }
  1269. SetGroupToSlave(group, target);
  1270. ShmGroupCollection[target].Partner.Member[ShmGroupCollection[target].Partner.Quantity++] = group;
  1271. ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
  1272. if(ParallelConfig != 0)
  1273. {
  1274. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1275. }
  1276. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
  1277. }
  1278. }
  1279. // group: group index, target: target index
  1280. // remove group out of target's member
  1281. void RemoveGroupCollection(byte group, byte target)
  1282. {
  1283. int location = 0, slave = 0;
  1284. bool find = false;
  1285. int ParallelConfig = 0;
  1286. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1287. {
  1288. for(int i = 0; i < ShmGroupCollection[target].Partner.Quantity; i++)
  1289. {
  1290. if(group == ShmGroupCollection[target].Partner.Member[i])
  1291. {
  1292. ShmGroupCollection[target].Partner.Member[i] = 0;
  1293. location = i;
  1294. find = true;
  1295. break;
  1296. }
  1297. }
  1298. if(find)
  1299. {
  1300. for(int i = location + 1; i < ShmGroupCollection[target].Partner.Quantity; i++)
  1301. {
  1302. slave = ShmGroupCollection[target].Partner.Member[i];
  1303. ShmGroupCollection[target].Partner.Member[i] = 0;
  1304. ShmGroupCollection[target].Partner.Member[i - 1] = slave;
  1305. }
  1306. ShmGroupCollection[target].Partner.Quantity--;
  1307. SetGroupToIdle(group);
  1308. ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
  1309. if(ParallelConfig != 0)
  1310. {
  1311. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1312. }
  1313. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
  1314. }
  1315. }
  1316. }
  1317. // Gun Role Quantity Master Member OutputVoltage OutputCurrent AvailablePower AvailableCurrent StableCurrent OutputRelay ParallelRelay
  1318. // 1 00 3 00 00 00 00 0000 V 0000 A 000 kW 0000 A 0000 A 00 XX
  1319. void ShowGroupingInfo(void)
  1320. {
  1321. byte target = 0;
  1322. printf("\r\n Gun Role Quantity Master Member OutputVoltage OutputCurrent AvailablePower AvailableCurrent StableCurrent OutputRelay ParallelRelay");
  1323. for(int i = 0; i < 4; i++)
  1324. {
  1325. target = ShmPsuGrouping->Layout[i];
  1326. printf("\r\n %d %2d %d %02X ",
  1327. target + 1, ShmGroupCollection[target].Role, ShmGroupCollection[target].Partner.Quantity, ShmGroupCollection[target].TargetGroup);
  1328. for(int j = 0; j < 3; j++)
  1329. {
  1330. if(ShmGroupCollection[target].Role == 1 && j < ShmGroupCollection[target].Partner.Quantity)
  1331. {
  1332. printf("%02X ", ShmGroupCollection[target].Partner.Member[j]);
  1333. }
  1334. else
  1335. {
  1336. printf(" ");
  1337. }
  1338. }
  1339. printf(" %4d V %4d A %3d kW %4d A %4d A ",
  1340. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1341. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1342. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1343. printf(" %02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1344. }
  1345. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1346. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1347. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1348. printf("\r\n\r\n");
  1349. }
  1350. void PsuGroupSwitchToIdle(byte group)
  1351. {
  1352. int master = 0, quantity = 0, location = 0, total = 0;
  1353. if(ShmGroupCollection[group].Role != _GROLE_SLAVE)
  1354. {
  1355. return;
  1356. }
  1357. master = ShmGroupCollection[group].TargetGroup - 1;
  1358. quantity = ShmGroupCollection[master].Partner.Quantity;
  1359. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1360. for(int i = 0; i < quantity; i++)
  1361. {
  1362. if(total == 0)
  1363. {
  1364. if(group == ShmGroupCollection[master].Partner.Member[i])
  1365. {
  1366. location = i;
  1367. total++;
  1368. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1369. }
  1370. }
  1371. else
  1372. {
  1373. // find other group in the same direction
  1374. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1375. {
  1376. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1377. {
  1378. total++;
  1379. //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
  1380. }
  1381. }
  1382. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1383. {
  1384. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1385. {
  1386. total++;
  1387. //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
  1388. }
  1389. }
  1390. }
  1391. }
  1392. if(total > 0)
  1393. {
  1394. unsigned char collection[GENERAL_GUN_QUANTITY];
  1395. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1396. memcpy(collection, ShmGroupCollection[master].Partner.Member, ARRAY_SIZE(ShmGroupCollection[master].Partner.Member));
  1397. for(int i = 0; i < total; i++)
  1398. {
  1399. //printf(" %02X", collection[i + location]);
  1400. }
  1401. for(int i = 0; i < total; i++)
  1402. {
  1403. RemoveGroupCollection(collection[i + location], master);
  1404. }
  1405. }
  1406. }
  1407. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1408. {
  1409. int slave = 0, location = 0;
  1410. PsuGroupPartner partner;
  1411. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1412. // search from left
  1413. location = ShmGroupCollection[master].Location - 1;
  1414. for(int i = location; i >= 0; i--)
  1415. {
  1416. if(partner.Quantity >= quantity)
  1417. {
  1418. break;
  1419. }
  1420. slave = ShmPsuGrouping->Layout[i];
  1421. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1422. {
  1423. //printf("\r\n Find Group %02X From Left", slave);
  1424. partner.Member[partner.Quantity++] = slave;
  1425. }
  1426. else
  1427. {
  1428. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
  1429. {
  1430. continue;
  1431. }
  1432. break;
  1433. }
  1434. }
  1435. // search from right
  1436. location = ShmGroupCollection[master].Location + 1;
  1437. for(int i = location; i < 4; i++)
  1438. {
  1439. if(partner.Quantity >= quantity)
  1440. {
  1441. break;
  1442. }
  1443. slave = ShmPsuGrouping->Layout[i];
  1444. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1445. {
  1446. //printf("\r\n Find Group %02X From Right", slave);
  1447. partner.Member[partner.Quantity++] = slave;
  1448. }
  1449. else
  1450. {
  1451. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
  1452. {
  1453. continue;
  1454. }
  1455. break;
  1456. }
  1457. }
  1458. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1459. }
  1460. int GetPsuGroupAvailable(byte group)
  1461. {
  1462. //int slave = 0, location = 0, available = 0;
  1463. PsuGroupPartner partner;
  1464. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1465. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1466. return partner.Quantity;
  1467. #if 0
  1468. // search from left
  1469. location = ShmGroupCollection[group].Location - 1;
  1470. for(int i = location; i >= 0; i--)
  1471. {
  1472. slave = ShmPsuGrouping->Layout[i];
  1473. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1474. {
  1475. available++;
  1476. }
  1477. else
  1478. {
  1479. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1480. {
  1481. continue;
  1482. }
  1483. break;
  1484. }
  1485. }
  1486. // search from right
  1487. location = ShmGroupCollection[group].Location + 1;
  1488. for(int i = location; i < 4; i++)
  1489. {
  1490. slave = ShmPsuGrouping->Layout[i];
  1491. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1492. {
  1493. available++;
  1494. }
  1495. else
  1496. {
  1497. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1498. {
  1499. continue;
  1500. }
  1501. break;
  1502. }
  1503. }
  1504. return available;
  1505. #endif
  1506. }
  1507. void PsuGroupShareCheck(byte group)
  1508. {
  1509. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1510. total = GetPsuGroupAvailable(group) + 1;
  1511. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1512. // search from left
  1513. location = ShmGroupCollection[group].Location - 1;
  1514. for(int i = location; i >= 0; i--)
  1515. {
  1516. slave = ShmPsuGrouping->Layout[i];
  1517. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
  1518. {
  1519. target = ShmGroupCollection[slave].TargetGroup - 1;
  1520. if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
  1521. {
  1522. share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1523. }
  1524. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
  1525. break;
  1526. }
  1527. else
  1528. {
  1529. break;
  1530. }
  1531. }
  1532. if(share == 0)
  1533. {
  1534. // search from right
  1535. location = ShmGroupCollection[group].Location + 1;
  1536. for(int i = location; i < 4; i++)
  1537. {
  1538. slave = ShmPsuGrouping->Layout[i];
  1539. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
  1540. {
  1541. target = ShmGroupCollection[slave].TargetGroup - 1;
  1542. if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
  1543. {
  1544. share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1545. }
  1546. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
  1547. break;
  1548. }
  1549. else
  1550. {
  1551. break;
  1552. }
  1553. }
  1554. }
  1555. if(share > 0)
  1556. {
  1557. //printf("\r\n Grab %02X", slave);
  1558. PsuGroupSwitchToIdle(slave);
  1559. }
  1560. else
  1561. {
  1562. //printf("\r\n No Need To Grab");
  1563. }
  1564. }
  1565. void SimplePsuGroupStartCharging(byte group)
  1566. {
  1567. //int slave = 0, location = 0;
  1568. int available = 0;
  1569. PsuGroupPartner partner;
  1570. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1571. {
  1572. return;
  1573. }
  1574. if(ShmGroupCollection[group].Role != _GROLE_IDLE && ShmGroupCollection[group].Role != _GROLE_MASTER)
  1575. {
  1576. return;
  1577. }
  1578. if(ShmGroupCollection[group].Role == _GROLE_IDLE)
  1579. {
  1580. SetGroupToMaster(group);
  1581. PsuGroupShareCheck(group);
  1582. }
  1583. else
  1584. {
  1585. available = GetPsuGroupAvailable(group);
  1586. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1587. if(available == 0)
  1588. {
  1589. return;
  1590. }
  1591. }
  1592. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1593. for(int i = 0; i < partner.Quantity; i++)
  1594. {
  1595. AddGroupCollection(partner.Member[i], group);
  1596. }
  1597. #if 0
  1598. // search from left
  1599. location = ShmGroupCollection[group].Location - 1;
  1600. for(int i = location; i >= 0; i--)
  1601. {
  1602. slave = ShmPsuGrouping->Layout[i];
  1603. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1604. {
  1605. //printf("\r\n Find %02X From Left", slave);
  1606. AddGroupCollection(slave, group);
  1607. }
  1608. else
  1609. {
  1610. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1611. {
  1612. continue;
  1613. }
  1614. break;
  1615. }
  1616. }
  1617. // search from right
  1618. location = ShmGroupCollection[group].Location + 1;
  1619. for(int i = location; i < 4; i++)
  1620. {
  1621. slave = ShmPsuGrouping->Layout[i];
  1622. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1623. {
  1624. //printf("\r\n Find %02X From Right", slave);
  1625. AddGroupCollection(slave, group);
  1626. }
  1627. else
  1628. {
  1629. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1630. {
  1631. continue;
  1632. }
  1633. break;
  1634. }
  1635. }
  1636. #endif
  1637. }
  1638. void PsuGroupStopCharging(byte group)
  1639. {
  1640. int total = 0;
  1641. if(ShmGroupCollection[group].Role != _GROLE_MASTER)
  1642. {
  1643. return;
  1644. }
  1645. total = ShmGroupCollection[group].Partner.Quantity;
  1646. if(total > 0)
  1647. {
  1648. unsigned char collection[GENERAL_GUN_QUANTITY];
  1649. //printf("\r\n There are %d Group Need To Stop:", ShmGroupCollection[group].Partner.Quantity);
  1650. memcpy(collection, ShmGroupCollection[group].Partner.Member, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
  1651. for(int i = 0; i < total; i++)
  1652. {
  1653. //printf(" %02X", collection[i]);
  1654. }
  1655. for(int i = 0; i < total; i++)
  1656. {
  1657. RemoveGroupCollection(collection[i], group);
  1658. }
  1659. }
  1660. SetGroupToIdle(group);
  1661. }
  1662. void RunSimplePsuGrouping(char *v1, char *v2)
  1663. {
  1664. int group = 0, charging = 0;
  1665. group = atoi(v1);
  1666. charging = atoi(v2);
  1667. group -= 1;
  1668. if(group >= 0 && group < 4)
  1669. {
  1670. if(charging > 0)
  1671. {
  1672. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1673. {
  1674. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1675. PsuGroupSwitchToIdle(group);
  1676. }
  1677. SimplePsuGroupStartCharging(group);
  1678. }
  1679. if(charging == 0)
  1680. {
  1681. if(ShmGroupCollection[group].Role == _GROLE_MASTER)
  1682. {
  1683. PsuGroupStopCharging(group);
  1684. }
  1685. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1686. {
  1687. PsuGroupSwitchToIdle(group);
  1688. }
  1689. }
  1690. ShowGroupingInfo();
  1691. }
  1692. }
  1693. void ShowCabinetInfo(void)
  1694. {
  1695. int ipAddress = 0;
  1696. printf("\r\nPower Cabinet Charging Mode = %d, ReAssignedFlag = %d",
  1697. ShmSysConfigAndInfo->SysInfo.MainChargingMode, ShmSysConfigAndInfo->SysInfo.ReAssignedFlag);
  1698. printf("\r\n Dispenser: %d / %d, Connector: %d / %d",
  1699. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1700. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1701. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1702. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1703. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  1704. {
  1705. printf("\r\n Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  1706. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  1707. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  1708. {
  1709. ipAddress = 0;
  1710. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  1711. {
  1712. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
  1713. i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
  1714. {
  1715. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
  1716. }
  1717. }
  1718. printf(", ModelName: %s, IP: %d.%d.%d.%d", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
  1719. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  1720. for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
  1721. {
  1722. printf("\r\n - Connector[%d] Gun %d", j, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j]);
  1723. }
  1724. }
  1725. else
  1726. {
  1727. printf(", No Information");
  1728. }
  1729. }
  1730. printf("\r\n\r\n");
  1731. }
  1732. void SetTestControl(char *v1, char *v2)
  1733. {
  1734. int testItem = 0;
  1735. int testItemLen = 2;
  1736. int enable = 0;
  1737. char strTest[32][32] = {"tbl", "tfsb"};
  1738. char strItem[32][32] = {"Balance", "Fast Standby Time"};
  1739. enable = atoi(v2);
  1740. if(enable < 0)
  1741. {
  1742. return;
  1743. }
  1744. for(int i = 0; i < testItemLen; i++)
  1745. {
  1746. if(strcmp((char *)&strTest[i][0], v1) == 0)
  1747. {
  1748. testItem = i + 1;
  1749. break;
  1750. }
  1751. }
  1752. if(testItem != 0)
  1753. {
  1754. if(enable)
  1755. {
  1756. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  1757. }
  1758. else
  1759. {
  1760. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  1761. }
  1762. printf("%s %s Test Item, Test Control Value = %08X\n",
  1763. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  1764. }
  1765. else
  1766. {
  1767. printf("Test Item %s Not Found\n", v1);
  1768. for(int i = 0; i < testItemLen; i++)
  1769. {
  1770. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  1771. }
  1772. }
  1773. printf("\r\n");
  1774. }
  1775. int main(void)
  1776. {
  1777. if(InitShareMemory() == FAIL)
  1778. {
  1779. printf ("InitShareMemory = FAIL \n");
  1780. if(ShmStatusCodeData != NULL)
  1781. {
  1782. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1783. }
  1784. sleep(5);
  1785. return 0;
  1786. }
  1787. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  1788. {
  1789. if (!FindChargingInfoData(i, &_chargingData[0]))
  1790. {
  1791. return 0;
  1792. }
  1793. }
  1794. /*
  1795. memset(&ShmGroupCollection[0], 0x00, sizeof(PsuGroupCollectionData));
  1796. memset(&ShmGroupCollection[1], 0x00, sizeof(PsuGroupCollectionData));
  1797. memset(&ShmGroupCollection[2], 0x00, sizeof(PsuGroupCollectionData));
  1798. memset(&ShmGroupCollection[3], 0x00, sizeof(PsuGroupCollectionData));
  1799. ShmGroupCollection[0].Index = 0;
  1800. ShmGroupCollection[1].Index = 1;
  1801. ShmGroupCollection[2].Index = 2;
  1802. ShmGroupCollection[3].Index = 3;
  1803. ShmGroupCollection[0].Location = 0;
  1804. ShmGroupCollection[1].Location = 3;
  1805. ShmGroupCollection[2].Location = 1;
  1806. ShmGroupCollection[3].Location = 2;
  1807. */
  1808. for(;;)
  1809. {
  1810. char word[128];
  1811. char newString[7][10];
  1812. int i,j,ctr;
  1813. fgets(word, sizeof(word), stdin);
  1814. j=0; ctr=0;
  1815. strcpy(newString[1], "-1");
  1816. strcpy(newString[2], "-1");
  1817. for (i = 0; i <= (strlen(word)); i++)
  1818. {
  1819. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1820. {
  1821. newString[ctr][j] = '\0';
  1822. ctr++;
  1823. j = 0;
  1824. }
  1825. else
  1826. {
  1827. newString[ctr][j] = word[i];
  1828. j++;
  1829. }
  1830. }
  1831. if(strcmp(newString[0], "state") == 0)
  1832. {
  1833. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1834. continue;
  1835. // 槍狀態
  1836. RunStatusProc(newString[1], newString[2]);
  1837. }
  1838. else if(strcmp(newString[0], "card") == 0)
  1839. {
  1840. // 刷卡狀態
  1841. RunCardProc(newString[1], newString[2]);
  1842. }
  1843. else if(strcmp(newString[0], "gun") == 0)
  1844. {
  1845. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1846. continue;
  1847. // 插槍狀態
  1848. RunGunPlugitProc(newString[1], newString[2]);
  1849. }
  1850. else if(strcmp(newString[0], "lock") == 0)
  1851. {
  1852. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1853. continue;
  1854. // 插槍狀態
  1855. GetGunLockStatusProc(newString[1], newString[2]);
  1856. }
  1857. else if(strcmp(newString[0], "sysid") == 0)
  1858. {
  1859. // 測試 sys id
  1860. SetSystemIDProc();
  1861. }
  1862. else if(strcmp(newString[0], "self") == 0)
  1863. {
  1864. // CSU 自我檢測狀態
  1865. RunSelfProc(newString[1]);
  1866. }
  1867. else if(strcmp(newString[0], "ver") == 0)
  1868. {
  1869. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1870. continue;
  1871. // 取 FW 版號
  1872. GetFwVerProc(newString[1]);
  1873. }
  1874. else if (strcmp(newString[0], "update") == 0)
  1875. {
  1876. // 更新
  1877. FwUpdateFlagProc(newString[1]);
  1878. }
  1879. else if (strcmp(newString[0], "ac") == 0)
  1880. {
  1881. // AC contactor 狀態
  1882. CheckAcStatus(newString[1]);
  1883. }
  1884. else if (strcmp(newString[0], "cable") == 0)
  1885. {
  1886. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1887. continue;
  1888. // cable check pass
  1889. SetCableChkStatus(newString[1], newString[2]);
  1890. }
  1891. else if (strcmp(newString[0], "pow") == 0)
  1892. {
  1893. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1894. continue;
  1895. // cable check pass
  1896. SetPowerValue(newString[1], newString[2]);
  1897. }
  1898. else if (strcmp(newString[0], "model") == 0)
  1899. {
  1900. GetSystemInfo();
  1901. }
  1902. else if(strcmp(newString[0], "select") == 0)
  1903. {
  1904. // 取得 / 設定 當前選的槍號
  1905. GetGunSelectedNum(newString[1]);
  1906. }
  1907. else if(strcmp(newString[0], "change") == 0)
  1908. {
  1909. // 模擬按鈕改變選槍
  1910. ChangeGunNum();
  1911. }
  1912. else if(strcmp(newString[0], "fan") == 0)
  1913. {
  1914. // 設定風扇速度
  1915. SetFanSpeed(newString[1]);
  1916. }
  1917. else if(strcmp(newString[0], "speed") == 0)
  1918. {
  1919. // 取得風扇速度
  1920. GetFanSpeed();
  1921. }
  1922. else if(strcmp(newString[0], "debug") == 0)
  1923. {
  1924. // 設定 debug mode
  1925. SetDebugMode(newString[1]);
  1926. }
  1927. else if (strcmp(newString[0], "gfd") == 0)
  1928. {
  1929. // 設定盲沖使用 GFD 功能
  1930. SetGFDMode(newString[1]);
  1931. }
  1932. else if(strcmp(newString[0], "temp") == 0)
  1933. {
  1934. // 取得 PSU 溫度
  1935. GetPsuTemp();
  1936. }
  1937. else if(strcmp(newString[0], "acin") == 0)
  1938. {
  1939. // 取得三向輸入電壓
  1940. GetAcInputVol();
  1941. }
  1942. else if(strcmp(newString[0], "psu") == 0)
  1943. {
  1944. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1945. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1946. {
  1947. printf ("PSU : Param fail..Please retry again......\n");
  1948. continue;
  1949. }
  1950. // 取得 PSU 資訊
  1951. GetPsuInformation(newString[1], newString[2], newString[3]);
  1952. }
  1953. else if (strcmp(newString[0], "cap") == 0)
  1954. {
  1955. GetConnectorCapInfo(newString[1]);
  1956. }
  1957. else if(strcmp(newString[0], "error") == 0)
  1958. {
  1959. CreateOneError(newString[1]);
  1960. }
  1961. else if (strcmp(newString[0], "auth") == 0)
  1962. {
  1963. GetAuthorizeFlag(newString[1]);
  1964. }
  1965. else if (strcmp(newString[0], "id") == 0)
  1966. {
  1967. GetOrClearId(newString[1]);
  1968. }
  1969. else if(strcmp(newString[0], "strchg") == 0)
  1970. {
  1971. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1972. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1973. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1974. {
  1975. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1976. continue;
  1977. }
  1978. // 槍狀態
  1979. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1980. }
  1981. else if(strcmp(newString[0], "str2chg") == 0)
  1982. {
  1983. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1984. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1985. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  1986. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  1987. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  1988. {
  1989. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1990. continue;
  1991. }
  1992. // 槍狀態
  1993. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  1994. }
  1995. else if(strcmp(newString[0], "wiring") == 0)
  1996. {
  1997. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  1998. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  1999. {
  2000. // wiring dispenser_id quantity
  2001. SetWiringInfo(newString[1], newString[2]);
  2002. }
  2003. ShowWiringInfo();
  2004. }
  2005. else if(strcmp(newString[0], "cwiring") == 0)
  2006. {
  2007. CleanWiringInfo();
  2008. }
  2009. else if(strcmp(newString[0], "reset") == 0)
  2010. {
  2011. SetSystemSoftRest();
  2012. }
  2013. else if(strcmp(newString[0], "reboot") == 0)
  2014. {
  2015. SetSystemHardReboot();
  2016. }
  2017. else if(strcmp(newString[0], "sgroup") == 0)
  2018. {
  2019. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2020. {
  2021. ShowGroupingInfo();
  2022. continue;
  2023. }
  2024. RunSimplePsuGrouping(newString[1], newString[2]);
  2025. }
  2026. else if(strcmp(newString[0], "cabinet") == 0)
  2027. {
  2028. ShowCabinetInfo();
  2029. }
  2030. else if(strcmp(newString[0], "tctl") == 0)
  2031. {
  2032. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2033. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2034. {
  2035. continue;
  2036. }
  2037. SetTestControl(newString[1], newString[2]);
  2038. }
  2039. else
  2040. printf ("%s\n", msg);
  2041. usleep(100000);
  2042. }
  2043. return 0;
  2044. }