ReadCmdline.c 38 KB

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