ReadCmdline.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863
  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 "../Module_CSU/Config.h"
  38. typedef unsigned char byte;
  39. #define PASS 1
  40. #define FAIL -1
  41. #define EQUAL 0
  42. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  43. #define NO_DEFINE 255
  44. #define DEFAULT_AC_INDEX 2
  45. #define YES 1
  46. #define NO 0
  47. #define AUTORUN_STEP1_TIME_START 140 // Minutes
  48. #define AUTORUN_STEP1_TIME_END 150
  49. #define AUTORUN_STEP2_TIME_START 210
  50. #define AUTORUN_STEP2_TIME_END 410
  51. #define AUTORUN_END_TIME 480
  52. #define AUTORUN_CYCLE_COUNT 30
  53. #define TTY_PATH "/dev/tty"
  54. #define STTY_US "stty raw -echo -F "
  55. #define STTY_DEF "stty -raw echo -F "
  56. byte _curAutoRunCount = 0;
  57. byte _usingAutoRun = 0;
  58. struct timeval _autoTime;
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PrimaryMcuData *ShmPrimaryMcuData;
  62. struct CHAdeMOData *ShmCHAdeMOData;
  63. struct CcsData *ShmCcsData;
  64. struct GBTData *ShmGBTData;
  65. struct FanModuleData *ShmFanModuleData;
  66. struct RelayModuleData *ShmRelayModuleData;
  67. struct LedModuleData *ShmLedModuleData;
  68. struct PsuData *ShmPsuData;
  69. struct DcCommonInformation *ShmDcCommonData;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  72. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  73. char *msg = "state : get gun state (index) \n"
  74. "card : scanning card (x) : \n"
  75. "gun : get gun plugit state (index) \n"
  76. "lock : get gun locked state (index) \n"
  77. "self : self test state (x) \n"
  78. "ver : ver of board (407 or index or rb or fan) \n"
  79. "ac : get ac relay state (x) \n";
  80. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  81. {
  82. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  83. {
  84. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  85. {
  86. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  87. return true;
  88. }
  89. }
  90. for (byte index = 0; index < CCS_QUANTITY; index++)
  91. {
  92. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  93. {
  94. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  95. return true;
  96. }
  97. }
  98. for (byte index = 0; index < GB_QUANTITY; index++)
  99. {
  100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  101. {
  102. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  103. return true;
  104. }
  105. }
  106. return false;
  107. }
  108. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  109. {
  110. if (target < AC_QUANTITY)
  111. {
  112. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  113. return true;
  114. }
  115. return false;
  116. }
  117. int InitShareMemory()
  118. {
  119. int result = PASS;
  120. int MeterSMId;
  121. //initial ShmSysConfigAndInfo
  122. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  123. {
  124. result = FAIL;
  125. }
  126. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  127. {
  128. result = FAIL;
  129. }
  130. //initial ShmStatusCodeData
  131. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  132. {
  133. result = FAIL;
  134. }
  135. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  136. {
  137. result = FAIL;
  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. }
  166. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  167. {
  168. result = FAIL;
  169. }
  170. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  171. {
  172. result = FAIL;
  173. }
  174. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  175. {
  176. result = FAIL;
  177. }
  178. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  179. {
  180. result = FAIL;
  181. }
  182. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  183. {
  184. result = FAIL;
  185. }
  186. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  187. {
  188. result = FAIL;
  189. }
  190. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  191. {
  192. result = FAIL;
  193. }
  194. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  195. {
  196. result = FAIL;
  197. }
  198. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  199. {
  200. result = FAIL;
  201. }
  202. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  203. {
  204. result = FAIL;
  205. }
  206. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  207. {
  208. result = FAIL;
  209. }
  210. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  211. {
  212. result = FAIL;
  213. }
  214. if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
  215. {
  216. result = FAIL;
  217. }
  218. else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  219. {
  220. result = FAIL;
  221. }
  222. return result;
  223. }
  224. unsigned long GetTimeoutValue(struct timeval _sour_time)
  225. {
  226. struct timeval _end_time;
  227. gettimeofday(&_end_time, NULL);
  228. return (_end_time.tv_sec - _sour_time.tv_sec);
  229. }
  230. void RunStatusProc(char *v1, char *v2)
  231. {
  232. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  233. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  234. if (strcmp(v1, "ac") == 0)
  235. {
  236. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  237. {
  238. printf("FindChargingInfoData (AC) false \n");
  239. }
  240. printf("AC Status = %d \n", ac_chargingInfo[0]->SystemStatus);
  241. printf("AC ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  242. return;
  243. }
  244. int _index = atoi(v1);
  245. if (_index <= 1)
  246. {
  247. if (!FindChargingInfoData(_index, &_chargingData[0]))
  248. {
  249. printf ("FindChargingInfoData error\n");
  250. return;
  251. }
  252. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  253. {
  254. // get
  255. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  256. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  257. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  258. printf ("SOC = %d \n", _chargingData[_index]->EvBatterySoc);
  259. printf ("Maximum battery Voltage = %f \n", _chargingData[_index]->EvBatteryMaxVoltage);
  260. printf("Charging mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
  261. printf("maxTemp = %d, temp-I = %d, temp-II = %d \n",
  262. _chargingData[_index]->ConnectorTemp - 60,
  263. ShmDcCommonData->ConnectorTemp1[_index] - 60,
  264. ShmDcCommonData->ConnectorTemp2[_index] - 60);
  265. }
  266. else
  267. {
  268. // set
  269. _chargingData[_index]->SystemStatus = atoi(v2);
  270. }
  271. }
  272. else
  273. {
  274. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  275. {
  276. printf("FindChargingInfoData (AC) false \n");
  277. }
  278. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  279. {
  280. // get
  281. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  282. }
  283. else
  284. {
  285. // set
  286. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  287. }
  288. }
  289. }
  290. void RunCardProc(char *v1, char *v2)
  291. {
  292. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  293. {
  294. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  295. {
  296. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  297. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  298. }
  299. else
  300. {
  301. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  302. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  303. }
  304. }
  305. else
  306. {
  307. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  308. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  309. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  310. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  311. }
  312. }
  313. void RunGunPlugitProc(char *v1, char *v2)
  314. {
  315. if (strcmp(v1, "ac") == 0)
  316. {
  317. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  318. {
  319. printf("FindChargingInfoData (AC) false \n");
  320. }
  321. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  322. {
  323. // get
  324. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  325. }
  326. else
  327. {
  328. // set
  329. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  330. }
  331. return;
  332. }
  333. int _index = atoi(v1);
  334. if (!FindChargingInfoData(_index, &_chargingData[0]))
  335. {
  336. printf("FindChargingInfoData error\n");
  337. return;
  338. }
  339. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  340. {
  341. // get
  342. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  343. }
  344. else
  345. {
  346. // set
  347. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  348. }
  349. }
  350. void GetGunLockStatusProc(char *v1, char *v2)
  351. {
  352. int _index = atoi(v1);
  353. if (!FindChargingInfoData(_index, &_chargingData[0]))
  354. {
  355. printf("FindChargingInfoData error\n");
  356. return;
  357. }
  358. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  359. {
  360. _chargingData[_index]->GunLocked = atoi(v2);
  361. }
  362. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  363. }
  364. void SetSystemIDProc()
  365. {
  366. char *systemId = "Alston_Test";
  367. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  368. }
  369. void RunSelfProc()
  370. {
  371. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  372. }
  373. void GetFwVerProc(char *v1)
  374. {
  375. if (strcmp(v1, "407") == 0)
  376. {
  377. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  378. }
  379. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
  380. {
  381. int _index = atoi(v1);
  382. if (_index == 0)
  383. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  384. else if (_index == 1)
  385. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  386. }
  387. else if (strcmp(v1, "rb") == 0)
  388. {
  389. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  390. }
  391. else if (strcmp(v1, "fan") == 0)
  392. {
  393. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  394. }
  395. else if (strcmp(v1, "dc") == 0)
  396. {
  397. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  398. }
  399. else if (strcmp(v1, "led") == 0)
  400. {
  401. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  402. }
  403. else if (strcmp(v1, "ac") == 0)
  404. {
  405. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  406. {
  407. printf("FindChargingInfoData (AC) false \n");
  408. }
  409. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  410. }
  411. else if (strcmp(v1, "all") == 0)
  412. {
  413. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  414. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  415. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  416. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  417. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  418. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  419. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  420. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  421. {
  422. printf("FindChargingInfoData (AC) false \n");
  423. }
  424. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  425. }
  426. }
  427. void CreateOneError()
  428. {
  429. for (byte i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  430. {
  431. printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  432. }
  433. }
  434. void GetAuthorizeFlag(char *v1)
  435. {
  436. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  437. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  438. else
  439. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  440. }
  441. void GetRelayStatus(char *v1)
  442. {
  443. int _index = atoi(v1);
  444. if (!FindChargingInfoData(_index, &_chargingData[0]))
  445. {
  446. printf("FindChargingInfoData error\n");
  447. return;
  448. }
  449. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  450. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  451. }
  452. void GetSOC(char *v1)
  453. {
  454. int _index = atoi(v1);
  455. if (!FindChargingInfoData(_index, &_chargingData[0]))
  456. {
  457. printf("FindChargingInfoData error\n");
  458. return;
  459. }
  460. printf("Soc = %d \n", _chargingData[_index]->EvBatterySoc);
  461. }
  462. void FwUpdateFlagProc()
  463. {
  464. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  465. }
  466. void CheckAcStatus(char *v1)
  467. {
  468. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  469. {
  470. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  471. }
  472. }
  473. void SetCableChkStatus(char *v1, char *v2)
  474. {
  475. int _index = atoi(v1);
  476. if (!FindChargingInfoData(_index, &_chargingData[0]))
  477. {
  478. printf ("FindChargingInfoData error\n");
  479. return;
  480. }
  481. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  482. }
  483. void SetChargingInfoCCID(char *v1, char* v2)
  484. {
  485. int _index = atoi(v1);
  486. if (!FindChargingInfoData(_index, &_chargingData[0]))
  487. {
  488. printf ("FindChargingInfoData error\n");
  489. return;
  490. }
  491. memcpy(_chargingData[_index]->EVCCID, v2, 8);
  492. _chargingData[_index]->EVCCID[8] = '\0';
  493. }
  494. void GetGunTemp(char *v1)
  495. {
  496. int _index = atoi(v1);
  497. if (!FindChargingInfoData(_index, &_chargingData[0]))
  498. {
  499. printf ("FindChargingInfoData error\n");
  500. return;
  501. }
  502. printf("Gun_%d, maxTemp = %d, temp 1 = %d, temp 2 = %d \n",
  503. _index,
  504. _chargingData[_index]->ConnectorTemp - 60,
  505. ShmDcCommonData->ConnectorTemp1[_index] - 60,
  506. ShmDcCommonData->ConnectorTemp2[_index] - 60);
  507. }
  508. void GetOffered(char *v1)
  509. {
  510. int _index = atoi(v1);
  511. if (!FindChargingInfoData(_index, &_chargingData[0]))
  512. {
  513. printf ("FindChargingInfoData error\n");
  514. return;
  515. }
  516. printf("Gun_%d, PowerOffered = %f, CurrentOffered = %f \n",
  517. _index,
  518. _chargingData[_index]->PowerOffered,
  519. _chargingData[_index]->CurrentOffered);
  520. }
  521. void GetEvStatus(char *v1)
  522. {
  523. int _index = atoi(v1);
  524. if (!FindChargingInfoData(_index, &_chargingData[0]))
  525. {
  526. printf ("FindChargingInfoData error\n");
  527. return;
  528. }
  529. if (_chargingData[_index]->Type == _Type_Chademo)
  530. printf ("Chademo status= %d \n", ShmCHAdeMOData->evse[_chargingData[_index]->type_index].EvboardStatus);
  531. else if (_chargingData[_index]->Type == _Type_CCS)
  532. printf ("CCS status= %d \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].PresentMsgFlowStatus);
  533. else if (_chargingData[_index]->Type == _Type_GB)
  534. printf ("GBT status = %d \n", ShmGBTData->evse[_chargingData[_index]->type_index].EvboardStatus);
  535. }
  536. void GetDcMeterInfor(char *v1)
  537. {
  538. int _index = atoi(v1);
  539. if (!FindChargingInfoData(_index, &_chargingData[0]))
  540. {
  541. printf ("FindChargingInfoData error\n");
  542. return;
  543. }
  544. printf("Index = %d, LinkStatus = %d presetVoltage = %f, presentCurrent = %f, presentPower = %f, totlizeImportEnergy = %f, totlizeExportEnergy = %f \n",
  545. _index,
  546. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].LinkStatus,
  547. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presetVoltage,
  548. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentCurrent,
  549. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentPower,
  550. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy,
  551. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeExportEnergy);
  552. }
  553. void GetPowerValue()
  554. {
  555. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
  556. {
  557. if (!FindChargingInfoData(index, &_chargingData[0]))
  558. {
  559. printf ("FindChargingInfoData error\n");
  560. return;
  561. }
  562. printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
  563. }
  564. }
  565. void GetSystemInfo()
  566. {
  567. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  568. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  569. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  570. printf ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  571. ShmPsuData->SystemAvailablePower / 10,
  572. ShmPsuData->SystemAvailableCurrent / 10
  573. );
  574. printf ("Config : ChargingPower = %d, ChargingCurrent = %d \n",
  575. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  576. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  577. }
  578. void ChangeGunNum()
  579. {
  580. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  581. {
  582. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  583. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  584. }
  585. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  586. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  587. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  588. else
  589. {
  590. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  591. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  592. }
  593. }
  594. void GetGunSelectedNum(char *v1)
  595. {
  596. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  597. {
  598. if (AC_QUANTITY > 0 &&
  599. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  600. {
  601. printf("connector select changed = AC \n");
  602. }
  603. else
  604. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  605. }
  606. else
  607. {
  608. int _index = atoi(v1);
  609. if (_index <= 1)
  610. {
  611. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  612. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  613. printf("connector select changed = %d \n", _index);
  614. }
  615. else if (AC_QUANTITY > 0)
  616. {
  617. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  618. printf("connector select changed = AC \n");
  619. }
  620. }
  621. }
  622. void SetFanSpeed(char *v1)
  623. {
  624. int speed = atoi(v1);
  625. ShmFanModuleData->TestFanSpeed = speed;
  626. }
  627. void ShowSysInformation()
  628. {
  629. if (!ShmSysConfigAndInfo->SysConfig.ShowInformation)
  630. ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x01;
  631. else
  632. ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x00;
  633. printf("Show inform = %d \n", ShmSysConfigAndInfo->SysConfig.ShowInformation);
  634. }
  635. void GetFanSpeed()
  636. {
  637. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  638. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  639. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  640. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  641. }
  642. void SetDebugMode(char *v1)
  643. {
  644. int mode = atoi(v1);
  645. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  646. }
  647. void SetGFDMode(char *v1)
  648. {
  649. int mode = atoi(v1);
  650. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  651. }
  652. void GetPsuTemp()
  653. {
  654. char _ex_maxTemp = 0;
  655. char _cr_maxTemp = 0;
  656. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  657. {
  658. _ex_maxTemp = 0;
  659. _cr_maxTemp = 0;
  660. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  661. {
  662. if (ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp > _ex_maxTemp)
  663. _ex_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  664. if (ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1 > _cr_maxTemp)
  665. _cr_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1;
  666. }
  667. printf("D.D. Temp = %d ------ Env Temp = %d \n", _ex_maxTemp, _cr_maxTemp);
  668. }
  669. }
  670. void GetAcInputVol()
  671. {
  672. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  673. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  674. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  675. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  676. }
  677. void GetPsuInformation(char *v1, char *v2, char *v3)
  678. {
  679. printf("**********************AC Contact needed*************************\n");
  680. if(strcmp(v1, "count") == 0)
  681. {
  682. for (int i = 0; i < 4; i++)
  683. {
  684. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  685. }
  686. }
  687. else if(strcmp(v1, "ver") == 0)
  688. {
  689. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  690. {
  691. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  692. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  693. }
  694. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  695. {
  696. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  697. {
  698. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  699. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  700. }
  701. }
  702. }
  703. else if(strcmp(v1, "cap") == 0)
  704. {
  705. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  706. {
  707. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  708. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  709. }
  710. }
  711. else if(strcmp(v1, "input") == 0)
  712. {
  713. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  714. {
  715. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  716. {
  717. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  718. i, count,
  719. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  720. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  721. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  722. }
  723. }
  724. }
  725. else if (strcmp(v1, "output") == 0)
  726. {
  727. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  728. {
  729. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  730. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  731. }
  732. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  733. {
  734. if (!FindChargingInfoData(i, &_chargingData[0]))
  735. {
  736. printf ("FindChargingInfoData error\n");
  737. continue;
  738. }
  739. printf("From RB : Group Index = %d, OutputV = %f \n",
  740. i, _chargingData[i]->FireChargingVoltage);
  741. }
  742. }
  743. else if (strcmp(v1, "test") == 0)
  744. {
  745. int mode = atoi(v2);
  746. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  747. {
  748. ShmPsuData->Work_Step = mode;
  749. }
  750. }
  751. else if (strcmp(v1, "out") == 0)
  752. {
  753. float vol = atof(v2);
  754. float cur = atof(v3);
  755. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  756. {
  757. if (!FindChargingInfoData(0, &_chargingData[0]))
  758. {
  759. printf ("FindChargingInfoData error\n");
  760. return;
  761. }
  762. _chargingData[0]->EvBatterytargetVoltage = vol;
  763. _chargingData[0]->EvBatterytargetCurrent = cur;
  764. }
  765. }
  766. printf("*************************************************\n");
  767. }
  768. void GetConnectorCapInfo(char *v1)
  769. {
  770. int _GunIndex = atoi(v1);
  771. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  772. {
  773. printf ("FindChargingInfoData error\n");
  774. return;
  775. }
  776. printf ("Charger Max Current = %d, Max Power = %d \n",
  777. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  778. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  779. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  780. _GunIndex,
  781. _chargingData[_GunIndex]->RealMaxPower,
  782. _chargingData[_GunIndex]->RealMaxVoltage,
  783. _chargingData[_GunIndex]->RealMaxCurrent);
  784. }
  785. static void get_char(char *word)
  786. {
  787. fd_set rfds;
  788. struct timeval tv;
  789. FD_ZERO(&rfds);
  790. FD_SET(0, &rfds);
  791. tv.tv_sec = 0;
  792. tv.tv_usec = 10; //wait input timout time
  793. //if input
  794. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  795. {
  796. fgets(word, 128, stdin);
  797. }
  798. }
  799. void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
  800. {
  801. float _Voltage[2];
  802. float _Current[2];
  803. _Voltage[0] = atof(g1_vol);
  804. _Current[0] = atof(g1_cur);
  805. _Voltage[1] = atof(g2_vol);
  806. _Current[1] = atof(g2_cur);
  807. printf ("g1_vol = %f, g1_cur = %f pow1 = %f (KW) \n", _Voltage[0], _Current[0], (_Voltage[0] * _Current[0]) / 1000);
  808. printf ("g2_vol = %f, g2_cur = %f pow2 = %f (KW) \n", _Voltage[1], _Current[1], (_Voltage[1] * _Current[1]) / 1000);
  809. if(_Voltage[0] > 1000 || _Voltage[0] < 50 ||
  810. _Voltage[1] > 1000 || _Voltage[1] < 50)
  811. {
  812. printf ("Input Voltage over range\n");
  813. return;
  814. }
  815. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
  816. {
  817. if (!FindChargingInfoData(_index, &_chargingData[0]))
  818. {
  819. printf("AverageCharging : FindChargingInfoData false \n");
  820. return;
  821. }
  822. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  823. _chargingData[_index]->Type = 9;
  824. }
  825. sleep(1);
  826. system("killall Module_EvComm");
  827. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  828. bool isComplete[2] = {false, false};
  829. while(1)
  830. {
  831. for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
  832. {
  833. switch(_chargingData[gun_index]->SystemStatus)
  834. {
  835. case SYS_MODE_IDLE:
  836. {
  837. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  838. {
  839. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  840. printf ("[AverageCharging (%d) - S_IDLE] \n", gun_index);
  841. }
  842. _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARING;
  843. }
  844. break;
  845. case SYS_MODE_PREPARING:
  846. {
  847. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  848. {
  849. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  850. printf ("[AverageCharging (%d) - S_PREPARNIN] \n", gun_index);
  851. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  852. printf ("wait find module\n");
  853. }
  854. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  855. //清除 main timeout 機制
  856. _chargingData[gun_index]->TimeoutFlag = 0;
  857. }
  858. break;
  859. case SYS_MODE_PREPARE_FOR_EV:
  860. {
  861. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  862. {
  863. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  864. printf ("[AverageCharging (%d) - S_PREPARING_FOR_EV] \n", gun_index);
  865. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[gun_index] * 10, _Current[gun_index] * 10);
  866. }
  867. //清除 main timeout 機制
  868. _chargingData[gun_index]->TimeoutFlag = 0;
  869. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  870. _chargingData[gun_index]->Type = 9;
  871. //充電電壓電流
  872. _chargingData[gun_index]->EvBatterySoc = 50;
  873. _chargingData[gun_index]->EvBatterytargetVoltage = 500;
  874. _chargingData[gun_index]->EvBatterytargetCurrent = 2;
  875. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  876. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  877. //確定模組己升壓完成
  878. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  879. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  880. {
  881. printf ("Preparing Done = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
  882. //EV done
  883. _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
  884. }
  885. }
  886. break;
  887. case SYS_MODE_PREPARE_FOR_EVSE:
  888. {
  889. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  890. {
  891. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  892. printf("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EVSE]\n", gun_index);
  893. }
  894. //printf ("tar vol = %d \n", _Voltage);
  895. //printf ("tar cur = %d \n", _Current);
  896. //清除 main timeout 機制
  897. _chargingData[gun_index]->TimeoutFlag = 0;
  898. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  899. _chargingData[gun_index]->Type = 9;
  900. //充電電壓電流
  901. _chargingData[gun_index]->EvBatterySoc = 50;
  902. _chargingData[gun_index]->EvBatterytargetVoltage = 500;
  903. _chargingData[gun_index]->EvBatterytargetCurrent = 2;
  904. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  905. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  906. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  907. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  908. //確定模組己升壓完成
  909. if(_chargingData[gun_index]->GroundFaultStatus == 0x01 ||
  910. _chargingData[gun_index]->GroundFaultStatus == 0x03)
  911. {
  912. printf ("First Ground Fault State (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  913. printf ("Wait K1K2 = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
  914. sleep(5);
  915. //EV done
  916. _chargingData[gun_index]->SystemStatus = SYS_MODE_CHARGING;
  917. }
  918. else if (_chargingData[gun_index]->GroundFaultStatus > 0x02)
  919. {
  920. printf ("First Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  921. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  922. }
  923. }
  924. break;
  925. case SYS_MODE_CHARGING:
  926. {
  927. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  928. {
  929. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  930. //充電電壓電流
  931. _chargingData[gun_index]->EvBatterytargetVoltage = _Voltage[gun_index];
  932. _chargingData[gun_index]->EvBatterytargetCurrent = _Current[gun_index];
  933. _chargingData[gun_index]->EvBatterySoc = 50;
  934. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  935. printf ("[AverageCharging (%d) - S_CHARGING]\n", gun_index);
  936. }
  937. //ev task do this
  938. _chargingData[gun_index]->PresentChargingPower =
  939. ((float)((_chargingData[gun_index]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  940. if (_chargingData[gun_index]->GroundFaultStatus == 0x02)
  941. {
  942. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  943. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  944. }
  945. }
  946. break;
  947. case SYS_MODE_TERMINATING:
  948. {
  949. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  950. {
  951. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  952. printf ("[AverageCharging (%d) - S_TERMINATING] \n", gun_index);
  953. //無阻塞偵測 keybaord 結束
  954. system(STTY_DEF TTY_PATH);
  955. }
  956. sleep(3);
  957. _chargingData[gun_index]->SystemStatus = SYS_MODE_COMPLETE;
  958. }
  959. break;
  960. case SYS_MODE_COMPLETE:
  961. {
  962. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  963. {
  964. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  965. printf ("[AverageCharging (%d) - S_COMPLETE] \n", gun_index);
  966. }
  967. _chargingData[gun_index]->PresentChargingPower = 0;
  968. isComplete[gun_index] = true;
  969. sleep(3);
  970. }
  971. break;
  972. }
  973. }
  974. if (isComplete[0] == true && isComplete[1] == true)
  975. return;
  976. char word[128];
  977. char newString[7][10];
  978. int i,j,ctr;
  979. memset(word, 0x00, sizeof(word));
  980. get_char(word);
  981. if (strlen(word) == 0)
  982. continue;
  983. j=0; ctr=0;
  984. strcpy(newString[1], "-1");
  985. strcpy(newString[2], "-1");
  986. for (i = 0; i <= (strlen(word)); i++)
  987. {
  988. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  989. {
  990. newString[ctr][j] = '\0';
  991. ctr++;
  992. j = 0;
  993. }
  994. else
  995. {
  996. newString[ctr][j] = word[i];
  997. j++;
  998. }
  999. }
  1000. if (strcmp(newString[0], "c") == 0)
  1001. {
  1002. for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
  1003. {
  1004. ShmDcCommonData->StartToChargingFlag[gun_index] = 0x00;
  1005. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  1006. }
  1007. printf("stop \n\r");
  1008. }
  1009. usleep(100000);
  1010. }
  1011. }
  1012. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  1013. {
  1014. int _GunIndex;
  1015. float _Voltage;
  1016. float _Current;
  1017. if (strcmp(v1, "auto") == EQUAL)
  1018. {
  1019. _usingAutoRun = 0x01;
  1020. _GunIndex = atoi(v2);
  1021. _Voltage = 500;
  1022. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  1023. }
  1024. else
  1025. {
  1026. _usingAutoRun = 0x00;
  1027. _GunIndex = atoi(v1);
  1028. _Voltage = atof(v2);
  1029. _Current = atof(v3);
  1030. }
  1031. unsigned char PreviousSystemStatus = 0xff;
  1032. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1033. {
  1034. printf ("FindChargingInfoData error\n");
  1035. return;
  1036. }
  1037. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  1038. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  1039. if(_Voltage > 1000 || _Voltage < 50)
  1040. {
  1041. printf ("Input Voltage over range\n");
  1042. return;
  1043. }
  1044. // if(_Current > 100 || _Current < 2){
  1045. //
  1046. // printf ("Input Current over range\n");
  1047. // return;
  1048. // }
  1049. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1050. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1051. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1052. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1053. sleep(1);
  1054. //kill ev task
  1055. system("killall Module_EvComm");
  1056. //_Voltage = (_Voltage * 10);
  1057. //_Current = (_Current * 10);
  1058. //system(STTY_US TTY_PATH);
  1059. while(true)
  1060. {
  1061. //fix gun 1
  1062. switch(_chargingData[_GunIndex]->SystemStatus)
  1063. {
  1064. case SYS_MODE_IDLE:
  1065. {
  1066. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1067. {
  1068. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1069. printf ("[UnconditionalCharge - S_IDLE]\n");
  1070. }
  1071. ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x01;
  1072. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARING;
  1073. }
  1074. break;
  1075. case SYS_MODE_PREPARING:
  1076. {
  1077. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1078. {
  1079. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1080. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1081. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1082. printf ("wait find module\n");
  1083. }
  1084. //main 會在此階段判斷以下資料跳到下一個 state
  1085. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1086. //ShmPsuData->SystemPresentPsuQuantity;
  1087. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1088. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1089. //_chargingData[gun_index]->AvailableChargingPower;
  1090. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1091. //sleep(10);
  1092. //清除 main timeout 機制
  1093. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1094. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1095. _chargingData[_GunIndex]->Type = 9;
  1096. }
  1097. break;
  1098. case SYS_MODE_PREPARE_FOR_EV:
  1099. {
  1100. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1101. {
  1102. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1103. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  1104. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1105. }
  1106. //清除 main timeout 機制
  1107. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1108. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1109. _chargingData[_GunIndex]->Type = 9;
  1110. //充電電壓電流
  1111. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1112. _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
  1113. _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
  1114. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1115. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1116. //確定模組己升壓完成
  1117. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1118. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1119. {
  1120. printf ("Precharge Done = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
  1121. //EV done
  1122. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
  1123. }
  1124. }
  1125. break;
  1126. case SYS_MODE_PREPARE_FOR_EVSE:
  1127. {
  1128. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1129. {
  1130. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1131. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  1132. }
  1133. //printf ("tar vol = %d \n", _Voltage);
  1134. //printf ("tar cur = %d \n", _Current);
  1135. //清除 main timeout 機制
  1136. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1137. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1138. _chargingData[_GunIndex]->Type = 9;
  1139. //充電電壓電流
  1140. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1141. _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
  1142. _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
  1143. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1144. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1145. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1146. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1147. //確定模組己升壓完成
  1148. if(_chargingData[_GunIndex]->GroundFaultStatus == 0x01 ||
  1149. _chargingData[_GunIndex]->GroundFaultStatus == 0x03)
  1150. {
  1151. printf ("First Ground Fault State (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1152. printf ("Wait K1K2 = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
  1153. sleep(5);
  1154. //EV done
  1155. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_CHARGING;
  1156. }
  1157. else if (_chargingData[_GunIndex]->GroundFaultStatus > 0x02)
  1158. {
  1159. printf ("First Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1160. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1161. }
  1162. }
  1163. break;
  1164. case SYS_MODE_CHARGING:
  1165. {
  1166. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1167. {
  1168. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1169. if (_usingAutoRun == 0x00)
  1170. {
  1171. //充電電壓電流
  1172. _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
  1173. _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
  1174. }
  1175. else
  1176. {
  1177. _curAutoRunCount = 0;
  1178. gettimeofday(&_autoTime, NULL);
  1179. }
  1180. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1181. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1182. printf ("[UnconditionalCharge - S_CHARGING]\n");
  1183. }
  1184. if (_usingAutoRun == 0x01)
  1185. {
  1186. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  1187. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  1188. {
  1189. _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
  1190. _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
  1191. }
  1192. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  1193. {
  1194. _curAutoRunCount++;
  1195. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  1196. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = SYS_MODE_TERMINATING;
  1197. else
  1198. gettimeofday(&_autoTime, NULL);
  1199. }
  1200. else
  1201. {
  1202. _chargingData[_GunIndex]->EvBatterytargetVoltage = 0;
  1203. _chargingData[_GunIndex]->EvBatterytargetCurrent = 0;
  1204. }
  1205. }
  1206. // printf("out : vol = %f, cur = %f \n",
  1207. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  1208. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1209. //ev task do this
  1210. _chargingData[_GunIndex]->PresentChargingPower =
  1211. ((float)((_chargingData[_GunIndex]->PresentChargingVoltage) * (_chargingData[_GunIndex]->PresentChargingCurrent)) / 1000);
  1212. if (_chargingData[_GunIndex]->GroundFaultStatus == 0x02){
  1213. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1214. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = SYS_MODE_TERMINATING;
  1215. }
  1216. }
  1217. break;
  1218. case SYS_MODE_TERMINATING:
  1219. {
  1220. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1221. {
  1222. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1223. system("/root/Module_EvComm &");
  1224. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  1225. //無阻塞偵測 keybaord 結束
  1226. system(STTY_DEF TTY_PATH);
  1227. }
  1228. sleep(3);
  1229. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_COMPLETE;
  1230. return;
  1231. }
  1232. break;
  1233. case SYS_MODE_COMPLETE:
  1234. {
  1235. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1236. {
  1237. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1238. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  1239. }
  1240. _chargingData[_GunIndex]->PresentChargingPower = 0;
  1241. sleep(3);
  1242. return;
  1243. }
  1244. break;
  1245. }
  1246. char word[128];
  1247. char newString[7][10];
  1248. int i,j,ctr;
  1249. memset(word, 0x00, sizeof(word));
  1250. get_char(word);
  1251. if (strlen(word) == 0)
  1252. continue;
  1253. j=0; ctr=0;
  1254. strcpy(newString[1], "-1");
  1255. strcpy(newString[2], "-1");
  1256. for (i = 0; i <= (strlen(word)); i++)
  1257. {
  1258. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1259. {
  1260. newString[ctr][j] = '\0';
  1261. ctr++;
  1262. j = 0;
  1263. }
  1264. else
  1265. {
  1266. newString[ctr][j] = word[i];
  1267. j++;
  1268. }
  1269. }
  1270. if(strcmp(newString[0], "chg") == 0)
  1271. {
  1272. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1273. continue;
  1274. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1275. continue;
  1276. float _vol = atof(newString[1]);
  1277. float _cur = atof(newString[2]);
  1278. if (_cur <= 0 || _cur <= 0)
  1279. continue;
  1280. printf("vol = %f, cur = %f \n", _vol, _cur);
  1281. _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
  1282. _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
  1283. }
  1284. else if (strcmp(newString[0], "c") == 0)
  1285. {
  1286. printf("stop \n\r");
  1287. ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x00;
  1288. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1289. }
  1290. usleep(100000);
  1291. }
  1292. }
  1293. //LWN_Debug
  1294. #ifdef LW_DEBUG_INFO
  1295. void PrintDebugInfo(char *v1)
  1296. {
  1297. int Index = 0;
  1298. bool PrintAll = false;
  1299. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  1300. {
  1301. PrintAll = true;
  1302. Index = 8;
  1303. }
  1304. else
  1305. Index = atoi(v1);
  1306. for (int i = 0; i < Index + 1; i++)
  1307. {
  1308. //command後面有帶value, print該state的info; 未帶值, print all of info.
  1309. if (PrintAll == false)
  1310. if (i != Index)
  1311. continue;
  1312. switch (i)
  1313. {
  1314. case 0:
  1315. {
  1316. if (ShmDcCommonData->DbgInfo.Msg.Index_0 == TRUE)
  1317. printf("[LWTEST]test debyg info print - 0\n");
  1318. }
  1319. break;
  1320. case 1:
  1321. {
  1322. if (ShmDcCommonData->DbgInfo.Msg.Index_1 == TRUE)
  1323. printf("[LWTEST]test debyg info print - 1\n");
  1324. }
  1325. break;
  1326. case 2:
  1327. {
  1328. if (ShmDcCommonData->DbgInfo.Msg.Index_2 == TRUE)
  1329. printf("[LWTEST]test debyg info print - 2\n");
  1330. }
  1331. break;
  1332. case 3:
  1333. {
  1334. if (ShmDcCommonData->DbgInfo.Msg.Index_3 == TRUE)
  1335. printf("[LWTEST]test debyg info print - 3\n");
  1336. }
  1337. break;
  1338. case 4:
  1339. {
  1340. if (ShmDcCommonData->DbgInfo.Msg.Index_4 == TRUE)
  1341. printf("[LWTEST]test debyg info print - 4\n");
  1342. }
  1343. break;
  1344. case 5:
  1345. {
  1346. if (ShmDcCommonData->DbgInfo.Msg.Index_5 == TRUE)
  1347. printf("[LWTEST]test debyg info print - 5\n");
  1348. }
  1349. break;
  1350. case 6:
  1351. {
  1352. if (ShmDcCommonData->DbgInfo.Msg.Index_6 == TRUE)
  1353. printf("[LWTEST]test debyg info print - 6\n");
  1354. }
  1355. break;
  1356. case 7:
  1357. {
  1358. if (ShmDcCommonData->DbgInfo.Msg.Index_7 == TRUE)
  1359. printf("[LWTEST]test debyg info print - 7\n");
  1360. }
  1361. break;
  1362. default:
  1363. break;
  1364. }
  1365. }
  1366. }
  1367. #endif
  1368. int main(void)
  1369. {
  1370. if(InitShareMemory() == FAIL)
  1371. {
  1372. printf ("InitShareMemory = FAIL \n");
  1373. if(ShmStatusCodeData != NULL)
  1374. {
  1375. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1376. }
  1377. sleep(5);
  1378. return 0;
  1379. }
  1380. for(;;)
  1381. {
  1382. char word[128];
  1383. char newString[7][10];
  1384. int i,j,ctr;
  1385. fgets(word, sizeof(word), stdin);
  1386. j=0; ctr=0;
  1387. strcpy(newString[1], "-1");
  1388. strcpy(newString[2], "-1");
  1389. for (i = 0; i <= (strlen(word)); i++)
  1390. {
  1391. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1392. {
  1393. newString[ctr][j] = '\0';
  1394. ctr++;
  1395. j = 0;
  1396. }
  1397. else
  1398. {
  1399. newString[ctr][j] = word[i];
  1400. j++;
  1401. }
  1402. }
  1403. if(strcmp(newString[0], "state") == 0 || strcmp(newString[0], "st") == 0)
  1404. {
  1405. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1406. continue;
  1407. // 槍狀態
  1408. printf("=========================== \n");
  1409. RunStatusProc(newString[1], newString[2]);
  1410. printf("=========================== \n");
  1411. }
  1412. else if(strcmp(newString[0], "card") == 0)
  1413. {
  1414. // 刷卡狀態
  1415. RunCardProc(newString[1], newString[2]);
  1416. }
  1417. else if(strcmp(newString[0], "gun") == 0)
  1418. {
  1419. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1420. continue;
  1421. // 插槍狀態
  1422. RunGunPlugitProc(newString[1], newString[2]);
  1423. }
  1424. else if(strcmp(newString[0], "lock") == 0)
  1425. {
  1426. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1427. continue;
  1428. // 插槍狀態
  1429. GetGunLockStatusProc(newString[1], newString[2]);
  1430. }
  1431. else if(strcmp(newString[0], "sysid") == 0)
  1432. {
  1433. // 測試 sys id
  1434. SetSystemIDProc();
  1435. }
  1436. else if(strcmp(newString[0], "self") == 0)
  1437. {
  1438. // CSU 自我檢測狀態
  1439. RunSelfProc(newString[1]);
  1440. }
  1441. else if(strcmp(newString[0], "ver") == 0)
  1442. {
  1443. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1444. continue;
  1445. // 取 FW 版號
  1446. GetFwVerProc(newString[1]);
  1447. }
  1448. else if (strcmp(newString[0], "update") == 0)
  1449. {
  1450. // 更新
  1451. FwUpdateFlagProc(newString[1]);
  1452. }
  1453. else if (strcmp(newString[0], "ac") == 0)
  1454. {
  1455. // AC contactor 狀態
  1456. CheckAcStatus(newString[1]);
  1457. }
  1458. else if (strcmp(newString[0], "cable") == 0)
  1459. {
  1460. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1461. continue;
  1462. // cable check pass
  1463. SetCableChkStatus(newString[1], newString[2]);
  1464. }
  1465. else if (strcmp(newString[0], "pow") == 0)
  1466. {
  1467. // get output power
  1468. GetPowerValue();
  1469. }
  1470. else if (strcmp(newString[0], "model") == 0)
  1471. {
  1472. GetSystemInfo();
  1473. }
  1474. else if(strcmp(newString[0], "select") == 0)
  1475. {
  1476. // 取得 / 設定 當前選的槍號
  1477. GetGunSelectedNum(newString[1]);
  1478. }
  1479. else if(strcmp(newString[0], "change") == 0)
  1480. {
  1481. // 模擬按鈕改變選槍
  1482. ChangeGunNum();
  1483. }
  1484. else if(strcmp(newString[0], "fan") == 0)
  1485. {
  1486. // 設定風扇速度
  1487. SetFanSpeed(newString[1]);
  1488. }
  1489. else if(strcmp(newString[0], "show") == 0)
  1490. {
  1491. ShowSysInformation();
  1492. }
  1493. else if(strcmp(newString[0], "speed") == 0)
  1494. {
  1495. // 取得風扇速度
  1496. GetFanSpeed();
  1497. }
  1498. else if(strcmp(newString[0], "debug") == 0)
  1499. {
  1500. // 設定 debug mode
  1501. SetDebugMode(newString[1]);
  1502. }
  1503. else if (strcmp(newString[0], "gfd") == 0)
  1504. {
  1505. // 設定盲沖使用 GFD 功能
  1506. SetGFDMode(newString[1]);
  1507. }
  1508. else if(strcmp(newString[0], "temp") == 0)
  1509. {
  1510. // 取得 PSU 溫度
  1511. GetPsuTemp();
  1512. }
  1513. else if(strcmp(newString[0], "acin") == 0)
  1514. {
  1515. // 取得三向輸入電壓
  1516. GetAcInputVol();
  1517. }
  1518. else if(strcmp(newString[0], "psu") == 0)
  1519. {
  1520. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1521. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1522. {
  1523. printf ("PSU : Param fail..Please retry again......\n");
  1524. continue;
  1525. }
  1526. // 取得 PSU 資訊
  1527. GetPsuInformation(newString[1], newString[2], newString[3]);
  1528. }
  1529. else if (strcmp(newString[0], "cap") == 0)
  1530. {
  1531. GetConnectorCapInfo(newString[1]);
  1532. }
  1533. else if(strcmp(newString[0], "error") == 0)
  1534. {
  1535. CreateOneError();
  1536. }
  1537. else if (strcmp(newString[0], "auth") == 0)
  1538. {
  1539. GetAuthorizeFlag(newString[1]);
  1540. }
  1541. else if (strcmp(newString[0], "relay") == 0)
  1542. {
  1543. GetRelayStatus(newString[1]);
  1544. }
  1545. else if (strcmp(newString[0], "ccid") == 0)
  1546. {
  1547. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1548. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1549. {
  1550. printf ("Input ccid fail.\n");
  1551. continue;
  1552. }
  1553. SetChargingInfoCCID(newString[1], newString[2]);
  1554. }
  1555. else if (strcmp(newString[0], "guntemp") == 0)
  1556. {
  1557. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1558. {
  1559. printf ("Input guntemp fail.\n");
  1560. continue;
  1561. }
  1562. GetGunTemp(newString[1]);
  1563. }
  1564. else if (strcmp(newString[0], "offer") == 0)
  1565. {
  1566. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1567. {
  1568. printf ("offer fail.\n");
  1569. continue;
  1570. }
  1571. GetOffered(newString[1]);
  1572. }
  1573. else if (strcmp(newString[0], "evstate") == 0)
  1574. {
  1575. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1576. {
  1577. printf ("evstate fail.\n");
  1578. continue;
  1579. }
  1580. GetEvStatus(newString[1]);
  1581. }
  1582. else if (strcmp(newString[0], "meter") == 0)
  1583. {
  1584. // DC meter infor
  1585. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1586. {
  1587. printf ("meter cmd fail.\n");
  1588. continue;
  1589. }
  1590. GetDcMeterInfor(newString[1]);
  1591. }
  1592. else if (strcmp(newString[0], "soc") == 0)
  1593. {
  1594. GetSOC(newString[1]);
  1595. }
  1596. else if (strcmp(newString[0], "run") == 0)
  1597. {
  1598. if (ShmDcCommonData->_isAutoRunTest == YES)
  1599. ShmDcCommonData->_isAutoRunTest = NO;
  1600. else
  1601. ShmDcCommonData->_isAutoRunTest = YES;
  1602. printf ("_isAutoRunTest = %d \n", ShmDcCommonData->_isAutoRunTest);
  1603. }
  1604. else if (strcmp(newString[0], "test") == 0)
  1605. {
  1606. }
  1607. else if(strcmp(newString[0], "strchg") == 0)
  1608. {
  1609. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1610. if (strcmp(newString[1], "auto") == 0)
  1611. {
  1612. newString[3][0] = 0;
  1613. }
  1614. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1615. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1616. {
  1617. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1618. continue;
  1619. }
  1620. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1621. }
  1622. else if(strcmp(newString[0], "avechg") == 0)
  1623. {
  1624. // 雙槍同時忙充輸出
  1625. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1626. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  1627. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  1628. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  1629. {
  1630. printf ("Input cmd fail ------ avechg\n");
  1631. continue;
  1632. }
  1633. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount < 2 ||
  1634. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == 1)
  1635. {
  1636. printf ("Sorry, This is single gun system. \n");
  1637. continue;
  1638. }
  1639. AverageCharging(newString[1], newString[2], newString[3], newString[4]);
  1640. }
  1641. #ifdef LW_DEBUG_INFO
  1642. else if (strcmp(newString[0], "lwdebug") == 0)
  1643. {
  1644. PrintDebugInfo(newString[1]);
  1645. }
  1646. #endif
  1647. else
  1648. printf ("%s\n", msg);
  1649. usleep(100000);
  1650. }
  1651. return 0;
  1652. }