ReadCmdline.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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. typedef unsigned char byte;
  39. #define PASS 1
  40. #define FAIL -1
  41. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  42. #define NO_DEFINE 255
  43. #define DEFAULT_AC_INDEX 2
  44. #define TTY_PATH "/dev/tty"
  45. #define STTY_US "stty raw -echo -F "
  46. #define STTY_DEF "stty -raw echo -F "
  47. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  48. struct StatusCodeData *ShmStatusCodeData;
  49. struct PrimaryMcuData *ShmPrimaryMcuData;
  50. struct CHAdeMOData *ShmCHAdeMOData;
  51. struct CcsData *ShmCcsData;
  52. struct GBTData *ShmGBTData;
  53. struct FanModuleData *ShmFanModuleData;
  54. struct RelayModuleData *ShmRelayModuleData;
  55. struct LedModuleData *ShmLedModuleData;
  56. struct PsuData *ShmPsuData;
  57. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  58. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  59. char *msg = "state : get gun state (index) \n"
  60. "card : scanning card (x) : \n"
  61. "gun : get gun plugit state (index) \n"
  62. "lock : get gun locked state (index) \n"
  63. "self : self test state (x) \n"
  64. "ver : ver of board (407 or index or rb or fan) \n"
  65. "ac : get ac relay state (x) \n";
  66. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  67. {
  68. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  69. {
  70. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  71. {
  72. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  73. return true;
  74. }
  75. }
  76. for (byte index = 0; index < CCS_QUANTITY; index++)
  77. {
  78. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  79. {
  80. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  81. return true;
  82. }
  83. }
  84. for (byte index = 0; index < GB_QUANTITY; index++)
  85. {
  86. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  87. {
  88. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  89. return true;
  90. }
  91. }
  92. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  93. {
  94. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  95. return true;
  96. }
  97. return false;
  98. }
  99. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  100. {
  101. if (target < AC_QUANTITY)
  102. {
  103. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  104. return true;
  105. }
  106. return false;
  107. }
  108. int InitShareMemory()
  109. {
  110. int result = PASS;
  111. int MeterSMId;
  112. //initial ShmSysConfigAndInfo
  113. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  114. {
  115. result = FAIL;
  116. }
  117. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  118. {
  119. result = FAIL;
  120. }
  121. else
  122. {}
  123. //initial ShmStatusCodeData
  124. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  125. {
  126. result = FAIL;
  127. }
  128. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  129. {
  130. result = FAIL;
  131. }
  132. else
  133. {}
  134. if (CHAdeMO_QUANTITY > 0) {
  135. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  136. IPC_CREAT | 0777)) < 0) {
  137. result = FAIL;
  138. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  139. == (void *) -1) {
  140. result = FAIL;
  141. } else {
  142. }
  143. }
  144. if (CCS_QUANTITY > 0) {
  145. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  146. IPC_CREAT | 0777)) < 0) {
  147. result = FAIL;
  148. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  149. result = FAIL;
  150. } else {
  151. }
  152. }
  153. if (GB_QUANTITY > 0) {
  154. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  155. IPC_CREAT | 0777)) < 0) {
  156. return 0;
  157. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  158. return 0;
  159. }
  160. memset(ShmGBTData, 0, sizeof(struct GBTData));
  161. }
  162. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  163. {
  164. result = FAIL;
  165. }
  166. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  167. {
  168. result = FAIL;
  169. }
  170. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  171. {
  172. result = FAIL;
  173. }
  174. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  175. {
  176. result = FAIL;
  177. }
  178. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  179. {
  180. result = FAIL;
  181. }
  182. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  183. {
  184. result = FAIL;
  185. }
  186. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  187. {
  188. result = FAIL;
  189. }
  190. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  191. {
  192. result = FAIL;
  193. }
  194. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  195. {
  196. result = FAIL;
  197. }
  198. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  199. {
  200. result = FAIL;
  201. }
  202. return result;
  203. }
  204. unsigned long GetTimeoutValue(struct timeval _sour_time)
  205. {
  206. struct timeval _end_time;
  207. gettimeofday(&_end_time, NULL);
  208. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  209. }
  210. void RunStatusProc(char *v1, char *v2)
  211. {
  212. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  213. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  214. if (strcmp(v1, "ac") == 0)
  215. {
  216. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  217. {
  218. printf("FindChargingInfoData (AC) false \n");
  219. }
  220. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  221. return;
  222. }
  223. int _index = atoi(v1);
  224. if (_index <= 1)
  225. {
  226. if (!FindChargingInfoData(_index, &_chargingData[0]))
  227. {
  228. printf ("FindChargingInfoData error\n");
  229. return;
  230. }
  231. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  232. {
  233. // get
  234. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  235. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  236. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  237. }
  238. else
  239. {
  240. // set
  241. _chargingData[_index]->SystemStatus = atoi(v2);
  242. }
  243. }
  244. else
  245. {
  246. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  247. {
  248. printf("FindChargingInfoData (AC) false \n");
  249. }
  250. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  251. {
  252. // get
  253. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  254. }
  255. else
  256. {
  257. // set
  258. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  259. }
  260. }
  261. }
  262. void RunCardProc(char *v1, char *v2)
  263. {
  264. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  265. {
  266. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  267. {
  268. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  269. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  270. }
  271. else
  272. {
  273. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  274. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  275. }
  276. }
  277. else
  278. {
  279. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  280. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  281. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  282. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  283. }
  284. }
  285. void RunGunPlugitProc(char *v1, char *v2)
  286. {
  287. if (strcmp(v1, "ac") == 0)
  288. {
  289. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  290. {
  291. printf("FindChargingInfoData (AC) false \n");
  292. }
  293. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  294. {
  295. // get
  296. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  297. }
  298. else
  299. {
  300. // set
  301. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  302. }
  303. return;
  304. }
  305. int _index = atoi(v1);
  306. if (!FindChargingInfoData(_index, &_chargingData[0]))
  307. {
  308. printf("FindChargingInfoData error\n");
  309. return;
  310. }
  311. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  312. {
  313. // get
  314. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  315. }
  316. else
  317. {
  318. // set
  319. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  320. }
  321. }
  322. void GetGunLockStatusProc(char *v1, char *v2)
  323. {
  324. int _index = atoi(v1);
  325. if (!FindChargingInfoData(_index, &_chargingData[0]))
  326. {
  327. printf("FindChargingInfoData error\n");
  328. return;
  329. }
  330. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  331. {
  332. _chargingData[_index]->GunLocked = atoi(v2);
  333. }
  334. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  335. }
  336. void SetSystemIDProc()
  337. {
  338. char *systemId = "Alston_Test";
  339. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  340. }
  341. void RunSelfProc()
  342. {
  343. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  344. }
  345. void GetFwVerProc(char *v1)
  346. {
  347. if (strcmp(v1, "407") == 0)
  348. {
  349. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  350. }
  351. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
  352. {
  353. int _index = atoi(v1);
  354. if (_index == 0)
  355. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  356. else if (_index == 1)
  357. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  358. }
  359. else if (strcmp(v1, "rb") == 0)
  360. {
  361. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  362. }
  363. else if (strcmp(v1, "fan") == 0)
  364. {
  365. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  366. }
  367. else if (strcmp(v1, "dc") == 0)
  368. {
  369. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  370. }
  371. else if (strcmp(v1, "led") == 0)
  372. {
  373. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  374. }
  375. else if (strcmp(v1, "ac") == 0)
  376. {
  377. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  378. {
  379. printf("FindChargingInfoData (AC) false \n");
  380. }
  381. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  382. }
  383. }
  384. void CreateOneError(char *v1)
  385. {
  386. int value = atoi(v1);
  387. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  388. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  389. }
  390. void GetAuthorizeFlag(char *v1)
  391. {
  392. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  393. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  394. else
  395. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  396. }
  397. void GetOrClearId(char *v1)
  398. {
  399. int _index = atoi(v1);
  400. if (!FindChargingInfoData(_index, &_chargingData[0]))
  401. {
  402. printf("FindChargingInfoData error\n");
  403. return;
  404. }
  405. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  406. }
  407. void FwUpdateFlagProc()
  408. {
  409. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  410. }
  411. void CheckAcStatus(char *v1)
  412. {
  413. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  414. {
  415. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  416. }
  417. }
  418. void SetCableChkStatus(char *v1, char *v2)
  419. {
  420. int _index = atoi(v1);
  421. if (!FindChargingInfoData(_index, &_chargingData[0]))
  422. {
  423. printf ("FindChargingInfoData error\n");
  424. return;
  425. }
  426. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  427. }
  428. void SetPowerValue(char *v1, char *v2)
  429. {
  430. int _index = atoi(v1);
  431. float _Current = atof(v2);
  432. // 盲沖的時候才允許使用~
  433. if (_chargingData[_index]->Type != 9)
  434. return;
  435. if (!FindChargingInfoData(_index, &_chargingData[0]))
  436. {
  437. printf ("FindChargingInfoData error\n");
  438. return;
  439. }
  440. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  441. }
  442. void GetSystemInfo()
  443. {
  444. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  445. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  446. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  447. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  448. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  449. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  450. }
  451. void ChangeGunNum()
  452. {
  453. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  454. {
  455. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  456. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  457. }
  458. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  459. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  460. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  461. else
  462. {
  463. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  464. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  465. }
  466. }
  467. void GetGunSelectedNum(char *v1)
  468. {
  469. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  470. {
  471. if (AC_QUANTITY > 0 &&
  472. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  473. {
  474. printf("connector select changed = AC \n");
  475. }
  476. else
  477. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  478. }
  479. else
  480. {
  481. int _index = atoi(v1);
  482. if (_index <= 1)
  483. {
  484. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  485. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  486. printf("connector select changed = %d \n", _index);
  487. }
  488. else if (AC_QUANTITY > 0)
  489. {
  490. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  491. printf("connector select changed = AC \n");
  492. }
  493. }
  494. }
  495. void SetFanSpeed(char *v1)
  496. {
  497. int speed = atoi(v1);
  498. ShmFanModuleData->TestFanSpeed = speed;
  499. }
  500. void GetFanSpeed()
  501. {
  502. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  503. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  504. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  505. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  506. }
  507. void SetDebugMode(char *v1)
  508. {
  509. int mode = atoi(v1);
  510. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  511. }
  512. void SetGFDMode(char *v1)
  513. {
  514. int mode = atoi(v1);
  515. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  516. }
  517. void GetPsuTemp()
  518. {
  519. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  520. {
  521. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  522. {
  523. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  524. }
  525. }
  526. }
  527. void GetAcInputVol()
  528. {
  529. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  530. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  531. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  532. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  533. }
  534. void GetPsuInformation(char *v1, char *v2, char *v3)
  535. {
  536. printf("**********************AC Contact needed*************************\n");
  537. if(strcmp(v1, "count") == 0)
  538. {
  539. for (int i = 0; i < 4; i++)
  540. {
  541. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  542. }
  543. }
  544. else if(strcmp(v1, "ver") == 0)
  545. {
  546. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  547. {
  548. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  549. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  550. }
  551. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  552. {
  553. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  554. {
  555. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  556. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  557. }
  558. }
  559. }
  560. else if(strcmp(v1, "cap") == 0)
  561. {
  562. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  563. {
  564. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  565. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  566. }
  567. }
  568. else if(strcmp(v1, "input") == 0)
  569. {
  570. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  571. {
  572. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  573. {
  574. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  575. i, count,
  576. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  577. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  578. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  579. }
  580. }
  581. }
  582. else if (strcmp(v1, "output") == 0)
  583. {
  584. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  585. {
  586. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  587. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  588. }
  589. }
  590. else if (strcmp(v1, "test") == 0)
  591. {
  592. int mode = atoi(v2);
  593. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  594. {
  595. ShmPsuData->Work_Step = mode;
  596. }
  597. }
  598. else if (strcmp(v1, "out") == 0)
  599. {
  600. float vol = atof(v2);
  601. float cur = atof(v3);
  602. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  603. {
  604. if (!FindChargingInfoData(0, &_chargingData[0]))
  605. {
  606. printf ("FindChargingInfoData error\n");
  607. return;
  608. }
  609. _chargingData[0]->EvBatterytargetVoltage = vol;
  610. _chargingData[0]->EvBatterytargetCurrent = cur;
  611. }
  612. }
  613. printf("*************************************************\n");
  614. }
  615. void GetConnectorCapInfo(char *v1)
  616. {
  617. int _GunIndex = atoi(v1);
  618. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  619. {
  620. printf ("FindChargingInfoData error\n");
  621. return;
  622. }
  623. printf ("Charger Max Current = %d, Max Power = %d \n",
  624. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  625. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  626. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  627. _GunIndex,
  628. _chargingData[_GunIndex]->RealMaxPower,
  629. _chargingData[_GunIndex]->RealMaxVoltage,
  630. _chargingData[_GunIndex]->RealMaxCurrent);
  631. }
  632. static void get_char(char *word)
  633. {
  634. fd_set rfds;
  635. struct timeval tv;
  636. FD_ZERO(&rfds);
  637. FD_SET(0, &rfds);
  638. tv.tv_sec = 0;
  639. tv.tv_usec = 10; //wait input timout time
  640. //if input
  641. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  642. {
  643. fgets(word, 128, stdin);
  644. }
  645. }
  646. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  647. {
  648. int _GunIndex = atoi(v1);
  649. float _Voltage = atof(v2);
  650. float _Current = atof(v3);
  651. unsigned char PreviousSystemStatus = 0xff;
  652. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  653. {
  654. printf ("FindChargingInfoData error\n");
  655. return;
  656. }
  657. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  658. if(_Voltage > 1000 || _Voltage < 50)
  659. {
  660. printf ("Input Voltage over range\n");
  661. return;
  662. }
  663. // if(_Current > 100 || _Current < 2){
  664. //
  665. // printf ("Input Current over range\n");
  666. // return;
  667. // }
  668. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  669. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  670. //kill ev task
  671. system("killall Module_EvComm");
  672. //_Voltage = (_Voltage * 10);
  673. //_Current = (_Current * 10);
  674. //system(STTY_US TTY_PATH);
  675. while(true)
  676. {
  677. //fix gun 1
  678. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  679. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  680. {
  681. case S_IDLE:
  682. {
  683. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  684. {
  685. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  686. printf ("[UnconditionalCharge - S_IDLE]\n");
  687. }
  688. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  689. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  690. }
  691. break;
  692. case S_PREPARNING:
  693. {
  694. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  695. {
  696. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  697. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  698. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  699. printf ("wait find module\n");
  700. }
  701. //main 會在此階段判斷以下資料跳到下一個 state
  702. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  703. //ShmPsuData->SystemPresentPsuQuantity;
  704. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  705. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  706. //_chargingData[gun_index]->AvailableChargingPower;
  707. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  708. //sleep(10);
  709. //清除 main timeout 機制
  710. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  711. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  712. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  713. }
  714. break;
  715. case S_PREPARING_FOR_EV:
  716. {
  717. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  718. {
  719. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  720. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  721. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  722. }
  723. //清除 main timeout 機制
  724. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  725. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  726. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  727. //充電電壓電流
  728. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  729. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  730. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  731. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  732. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  733. //確定模組己升壓完成
  734. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  735. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  736. {
  737. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  738. //EV done
  739. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  740. }
  741. }
  742. break;
  743. case S_PREPARING_FOR_EVSE:
  744. {
  745. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  746. {
  747. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  748. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  749. }
  750. //printf ("tar vol = %d \n", _Voltage);
  751. //printf ("tar cur = %d \n", _Current);
  752. //清除 main timeout 機制
  753. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  754. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  755. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  756. //充電電壓電流
  757. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  758. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  759. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  760. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  761. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  762. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  763. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  764. //確定模組己升壓完成
  765. if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  766. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  767. {
  768. printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  769. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  770. sleep(5);
  771. //EV done
  772. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  773. }
  774. else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  775. {
  776. printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  777. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  778. }
  779. }
  780. break;
  781. case S_CHARGING:
  782. {
  783. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  784. {
  785. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  786. //充電電壓電流
  787. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  788. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  789. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  790. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  791. printf ("[UnconditionalCharge - S_CHARGING]\n");
  792. }
  793. //ev task do this
  794. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  795. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  796. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  797. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  798. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  799. }
  800. }
  801. break;
  802. case S_TERMINATING:
  803. {
  804. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  805. {
  806. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  807. system("/root/Module_EvComm &");
  808. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  809. //無阻塞偵測 keybaord 結束
  810. system(STTY_DEF TTY_PATH);
  811. }
  812. sleep(3);
  813. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  814. return;
  815. }
  816. break;
  817. case S_COMPLETE:
  818. {
  819. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  820. {
  821. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  822. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  823. }
  824. sleep(3);
  825. return;
  826. }
  827. break;
  828. }
  829. char word[128];
  830. char newString[7][10];
  831. int i,j,ctr;
  832. memset(word, 0x00, sizeof(word));
  833. get_char(word);
  834. if (strlen(word) == 0)
  835. continue;
  836. j=0; ctr=0;
  837. strcpy(newString[1], "-1");
  838. strcpy(newString[2], "-1");
  839. for (i = 0; i <= (strlen(word)); i++)
  840. {
  841. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  842. {
  843. newString[ctr][j] = '\0';
  844. ctr++;
  845. j = 0;
  846. }
  847. else
  848. {
  849. newString[ctr][j] = word[i];
  850. j++;
  851. }
  852. }
  853. if(strcmp(newString[0], "chg") == 0)
  854. {
  855. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  856. continue;
  857. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  858. continue;
  859. float _vol = atof(newString[1]);
  860. float _cur = atof(newString[2]);
  861. if (_cur <= 0 || _cur <= 0)
  862. continue;
  863. printf("vol = %f, cur = %f \n", _vol, _cur);
  864. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  865. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  866. }
  867. else if (strcmp(newString[0], "c") == 0)
  868. {
  869. printf("stop \n\r");
  870. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  871. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  872. }
  873. usleep(100000);
  874. }
  875. }
  876. int main(void)
  877. {
  878. if(InitShareMemory() == FAIL)
  879. {
  880. printf ("InitShareMemory = FAIL \n");
  881. if(ShmStatusCodeData != NULL)
  882. {
  883. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  884. }
  885. sleep(5);
  886. return 0;
  887. }
  888. for(;;)
  889. {
  890. char word[128];
  891. char newString[7][10];
  892. int i,j,ctr;
  893. fgets(word, sizeof(word), stdin);
  894. j=0; ctr=0;
  895. strcpy(newString[1], "-1");
  896. strcpy(newString[2], "-1");
  897. for (i = 0; i <= (strlen(word)); i++)
  898. {
  899. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  900. {
  901. newString[ctr][j] = '\0';
  902. ctr++;
  903. j = 0;
  904. }
  905. else
  906. {
  907. newString[ctr][j] = word[i];
  908. j++;
  909. }
  910. }
  911. if(strcmp(newString[0], "state") == 0)
  912. {
  913. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  914. continue;
  915. // 槍狀態
  916. RunStatusProc(newString[1], newString[2]);
  917. }
  918. else if(strcmp(newString[0], "card") == 0)
  919. {
  920. // 刷卡狀態
  921. RunCardProc(newString[1], newString[2]);
  922. }
  923. else if(strcmp(newString[0], "gun") == 0)
  924. {
  925. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  926. continue;
  927. // 插槍狀態
  928. RunGunPlugitProc(newString[1], newString[2]);
  929. }
  930. else if(strcmp(newString[0], "lock") == 0)
  931. {
  932. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  933. continue;
  934. // 插槍狀態
  935. GetGunLockStatusProc(newString[1], newString[2]);
  936. }
  937. else if(strcmp(newString[0], "sysid") == 0)
  938. {
  939. // 測試 sys id
  940. SetSystemIDProc();
  941. }
  942. else if(strcmp(newString[0], "self") == 0)
  943. {
  944. // CSU 自我檢測狀態
  945. RunSelfProc(newString[1]);
  946. }
  947. else if(strcmp(newString[0], "ver") == 0)
  948. {
  949. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  950. continue;
  951. // 取 FW 版號
  952. GetFwVerProc(newString[1]);
  953. }
  954. else if (strcmp(newString[0], "update") == 0)
  955. {
  956. // 更新
  957. FwUpdateFlagProc(newString[1]);
  958. }
  959. else if (strcmp(newString[0], "ac") == 0)
  960. {
  961. // AC contactor 狀態
  962. CheckAcStatus(newString[1]);
  963. }
  964. else if (strcmp(newString[0], "cable") == 0)
  965. {
  966. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  967. continue;
  968. // cable check pass
  969. SetCableChkStatus(newString[1], newString[2]);
  970. }
  971. else if (strcmp(newString[0], "pow") == 0)
  972. {
  973. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  974. continue;
  975. // cable check pass
  976. SetPowerValue(newString[1], newString[2]);
  977. }
  978. else if (strcmp(newString[0], "model") == 0)
  979. {
  980. GetSystemInfo();
  981. }
  982. else if(strcmp(newString[0], "select") == 0)
  983. {
  984. // 取得 / 設定 當前選的槍號
  985. GetGunSelectedNum(newString[1]);
  986. }
  987. else if(strcmp(newString[0], "change") == 0)
  988. {
  989. // 模擬按鈕改變選槍
  990. ChangeGunNum();
  991. }
  992. else if(strcmp(newString[0], "fan") == 0)
  993. {
  994. // 設定風扇速度
  995. SetFanSpeed(newString[1]);
  996. }
  997. else if(strcmp(newString[0], "speed") == 0)
  998. {
  999. // 取得風扇速度
  1000. GetFanSpeed();
  1001. }
  1002. else if(strcmp(newString[0], "debug") == 0)
  1003. {
  1004. // 設定 debug mode
  1005. SetDebugMode(newString[1]);
  1006. }
  1007. else if (strcmp(newString[0], "gfd") == 0)
  1008. {
  1009. // 設定盲沖使用 GFD 功能
  1010. SetGFDMode(newString[1]);
  1011. }
  1012. else if(strcmp(newString[0], "temp") == 0)
  1013. {
  1014. // 取得 PSU 溫度
  1015. GetPsuTemp();
  1016. }
  1017. else if(strcmp(newString[0], "acin") == 0)
  1018. {
  1019. // 取得三向輸入電壓
  1020. GetAcInputVol();
  1021. }
  1022. else if(strcmp(newString[0], "psu") == 0)
  1023. {
  1024. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1025. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1026. {
  1027. printf ("PSU : Param fail..Please retry again......\n");
  1028. continue;
  1029. }
  1030. // 取得 PSU 資訊
  1031. GetPsuInformation(newString[1], newString[2], newString[3]);
  1032. }
  1033. else if (strcmp(newString[0], "cap") == 0)
  1034. {
  1035. GetConnectorCapInfo(newString[1]);
  1036. }
  1037. else if(strcmp(newString[0], "error") == 0)
  1038. {
  1039. CreateOneError(newString[1]);
  1040. }
  1041. else if (strcmp(newString[0], "auth") == 0)
  1042. {
  1043. GetAuthorizeFlag(newString[1]);
  1044. }
  1045. else if (strcmp(newString[0], "id") == 0)
  1046. {
  1047. GetOrClearId(newString[1]);
  1048. }
  1049. else if(strcmp(newString[0], "strchg") == 0)
  1050. {
  1051. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1052. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1053. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1054. {
  1055. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1056. continue;
  1057. }
  1058. // 槍狀態
  1059. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1060. }
  1061. else
  1062. printf ("%s\n", msg);
  1063. usleep(100000);
  1064. }
  1065. return 0;
  1066. }