ReadCmdline.c 40 KB

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