ReadCmdline.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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. {
  836. continue;
  837. }
  838. j=0; ctr=0;
  839. strcpy(newString[1], "-1");
  840. strcpy(newString[2], "-1");
  841. for (i = 0; i <= (strlen(word)); i++)
  842. {
  843. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  844. {
  845. newString[ctr][j] = '\0';
  846. ctr++;
  847. j = 0;
  848. }
  849. else
  850. {
  851. newString[ctr][j] = word[i];
  852. j++;
  853. }
  854. }
  855. if(strcmp(newString[0], "chg") == 0)
  856. {
  857. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  858. continue;
  859. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  860. continue;
  861. float _vol = atof(newString[1]);
  862. float _cur = atof(newString[2]);
  863. if (_cur <= 0 || _cur <= 0)
  864. continue;
  865. printf("vol = %f, cur = %f \n", _vol, _cur);
  866. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  867. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  868. }
  869. else if (strcmp(newString[0], "c") == 0)
  870. {
  871. printf("stop \n\r");
  872. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  873. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  874. }
  875. usleep(100000);
  876. }
  877. }
  878. int main(void)
  879. {
  880. if(InitShareMemory() == FAIL)
  881. {
  882. printf ("InitShareMemory = FAIL \n");
  883. if(ShmStatusCodeData != NULL)
  884. {
  885. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  886. }
  887. sleep(5);
  888. return 0;
  889. }
  890. for(;;)
  891. {
  892. char word[128];
  893. char newString[7][10];
  894. int i,j,ctr;
  895. fgets(word, sizeof(word), stdin);
  896. j=0; ctr=0;
  897. strcpy(newString[1], "-1");
  898. strcpy(newString[2], "-1");
  899. for (i = 0; i <= (strlen(word)); i++)
  900. {
  901. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  902. {
  903. newString[ctr][j] = '\0';
  904. ctr++;
  905. j = 0;
  906. }
  907. else
  908. {
  909. newString[ctr][j] = word[i];
  910. j++;
  911. }
  912. }
  913. if(strcmp(newString[0], "state") == 0)
  914. {
  915. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  916. continue;
  917. // 槍狀態
  918. RunStatusProc(newString[1], newString[2]);
  919. }
  920. else if(strcmp(newString[0], "card") == 0)
  921. {
  922. // 刷卡狀態
  923. RunCardProc(newString[1], newString[2]);
  924. }
  925. else if(strcmp(newString[0], "gun") == 0)
  926. {
  927. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  928. continue;
  929. // 插槍狀態
  930. RunGunPlugitProc(newString[1], newString[2]);
  931. }
  932. else if(strcmp(newString[0], "lock") == 0)
  933. {
  934. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  935. continue;
  936. // 插槍狀態
  937. GetGunLockStatusProc(newString[1], newString[2]);
  938. }
  939. else if(strcmp(newString[0], "sysid") == 0)
  940. {
  941. // 測試 sys id
  942. SetSystemIDProc();
  943. }
  944. else if(strcmp(newString[0], "self") == 0)
  945. {
  946. // CSU 自我檢測狀態
  947. RunSelfProc(newString[1]);
  948. }
  949. else if(strcmp(newString[0], "ver") == 0)
  950. {
  951. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  952. continue;
  953. // 取 FW 版號
  954. GetFwVerProc(newString[1]);
  955. }
  956. else if (strcmp(newString[0], "update") == 0)
  957. {
  958. // 更新
  959. FwUpdateFlagProc(newString[1]);
  960. }
  961. else if (strcmp(newString[0], "ac") == 0)
  962. {
  963. // AC contactor 狀態
  964. CheckAcStatus(newString[1]);
  965. }
  966. else if (strcmp(newString[0], "cable") == 0)
  967. {
  968. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  969. continue;
  970. // cable check pass
  971. SetCableChkStatus(newString[1], newString[2]);
  972. }
  973. else if (strcmp(newString[0], "pow") == 0)
  974. {
  975. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  976. continue;
  977. // cable check pass
  978. SetPowerValue(newString[1], newString[2]);
  979. }
  980. else if (strcmp(newString[0], "model") == 0)
  981. {
  982. GetSystemInfo();
  983. }
  984. else if(strcmp(newString[0], "select") == 0)
  985. {
  986. // 取得 / 設定 當前選的槍號
  987. GetGunSelectedNum(newString[1]);
  988. }
  989. else if(strcmp(newString[0], "change") == 0)
  990. {
  991. // 模擬按鈕改變選槍
  992. ChangeGunNum();
  993. }
  994. else if(strcmp(newString[0], "fan") == 0)
  995. {
  996. // 設定風扇速度
  997. SetFanSpeed(newString[1]);
  998. }
  999. else if(strcmp(newString[0], "speed") == 0)
  1000. {
  1001. // 取得風扇速度
  1002. GetFanSpeed();
  1003. }
  1004. else if(strcmp(newString[0], "debug") == 0)
  1005. {
  1006. // 設定 debug mode
  1007. SetDebugMode(newString[1]);
  1008. }
  1009. else if (strcmp(newString[0], "gfd") == 0)
  1010. {
  1011. // 設定盲沖使用 GFD 功能
  1012. SetGFDMode(newString[1]);
  1013. }
  1014. else if(strcmp(newString[0], "temp") == 0)
  1015. {
  1016. // 取得 PSU 溫度
  1017. GetPsuTemp();
  1018. }
  1019. else if(strcmp(newString[0], "acin") == 0)
  1020. {
  1021. // 取得三向輸入電壓
  1022. GetAcInputVol();
  1023. }
  1024. else if(strcmp(newString[0], "psu") == 0)
  1025. {
  1026. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1027. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1028. {
  1029. printf ("PSU : Param fail..Please retry again......\n");
  1030. continue;
  1031. }
  1032. // 取得 PSU 資訊
  1033. GetPsuInformation(newString[1], newString[2], newString[3]);
  1034. }
  1035. else if (strcmp(newString[0], "cap") == 0)
  1036. {
  1037. GetConnectorCapInfo(newString[1]);
  1038. }
  1039. else if(strcmp(newString[0], "error") == 0)
  1040. {
  1041. CreateOneError(newString[1]);
  1042. }
  1043. else if (strcmp(newString[0], "auth") == 0)
  1044. {
  1045. GetAuthorizeFlag(newString[1]);
  1046. }
  1047. else if (strcmp(newString[0], "id") == 0)
  1048. {
  1049. GetOrClearId(newString[1]);
  1050. }
  1051. else if(strcmp(newString[0], "strchg") == 0)
  1052. {
  1053. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1054. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1055. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1056. {
  1057. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1058. continue;
  1059. }
  1060. // 槍狀態
  1061. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1062. }
  1063. else
  1064. printf ("%s\n", msg);
  1065. usleep(100000);
  1066. }
  1067. return 0;
  1068. }