ReadCmdline.c 35 KB

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