ReadCmdline.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  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. ShmPrimaryMcuData->InputDet.bits.EmergencyButton = value;
  392. //ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = value;
  393. //ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  394. }
  395. void GetAuthorizeFlag(char *v1)
  396. {
  397. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  398. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  399. else
  400. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  401. }
  402. void GetRelayStatus(char *v1)
  403. {
  404. int _index = atoi(v1);
  405. if (!FindChargingInfoData(_index, &_chargingData[0]))
  406. {
  407. printf("FindChargingInfoData error\n");
  408. return;
  409. }
  410. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  411. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  412. }
  413. void GetSOC(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("Soc = %d \n", _chargingData[_index]->EvBatterySoc);
  422. }
  423. void FwUpdateFlagProc()
  424. {
  425. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  426. }
  427. void CheckAcStatus(char *v1)
  428. {
  429. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  430. {
  431. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  432. }
  433. }
  434. void SetCableChkStatus(char *v1, char *v2)
  435. {
  436. int _index = atoi(v1);
  437. if (!FindChargingInfoData(_index, &_chargingData[0]))
  438. {
  439. printf ("FindChargingInfoData error\n");
  440. return;
  441. }
  442. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  443. }
  444. void SetChargingInfoCCID(char *v1, char* v2)
  445. {
  446. int _index = atoi(v1);
  447. if (!FindChargingInfoData(_index, &_chargingData[0]))
  448. {
  449. printf ("FindChargingInfoData error\n");
  450. return;
  451. }
  452. memcpy(_chargingData[_index]->EVCCID, v2, 8);
  453. _chargingData[_index]->EVCCID[8] = '\0';
  454. }
  455. void GetPowerValue()
  456. {
  457. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
  458. {
  459. if (!FindChargingInfoData(index, &_chargingData[0]))
  460. {
  461. printf ("FindChargingInfoData error\n");
  462. return;
  463. }
  464. printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
  465. }
  466. }
  467. void GetSystemInfo()
  468. {
  469. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  470. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  471. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  472. printf ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  473. ShmPsuData->SystemAvailablePower / 10,
  474. ShmPsuData->SystemAvailableCurrent / 10
  475. );
  476. printf ("Config : ChargingPower = %d, ChargingCurrent = %d \n",
  477. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  478. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  479. }
  480. void ChangeGunNum()
  481. {
  482. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  483. {
  484. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  485. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  486. }
  487. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  488. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  489. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  490. else
  491. {
  492. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  493. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  494. }
  495. }
  496. void GetGunSelectedNum(char *v1)
  497. {
  498. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  499. {
  500. if (AC_QUANTITY > 0 &&
  501. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  502. {
  503. printf("connector select changed = AC \n");
  504. }
  505. else
  506. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  507. }
  508. else
  509. {
  510. int _index = atoi(v1);
  511. if (_index <= 1)
  512. {
  513. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  514. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  515. printf("connector select changed = %d \n", _index);
  516. }
  517. else if (AC_QUANTITY > 0)
  518. {
  519. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  520. printf("connector select changed = AC \n");
  521. }
  522. }
  523. }
  524. void SetFanSpeed(char *v1)
  525. {
  526. int speed = atoi(v1);
  527. ShmFanModuleData->TestFanSpeed = speed;
  528. }
  529. void GetFanSpeed()
  530. {
  531. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  532. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  533. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  534. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  535. }
  536. void SetDebugMode(char *v1)
  537. {
  538. int mode = atoi(v1);
  539. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  540. }
  541. void SetGFDMode(char *v1)
  542. {
  543. int mode = atoi(v1);
  544. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  545. }
  546. void GetPsuTemp()
  547. {
  548. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  549. {
  550. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  551. {
  552. printf("D.D. Temp = %d ------ Env Temp = %d \n",
  553. ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp,
  554. ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1);
  555. }
  556. }
  557. }
  558. void GetAcInputVol()
  559. {
  560. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  561. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  562. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  563. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  564. }
  565. void GetPsuInformation(char *v1, char *v2, char *v3)
  566. {
  567. printf("**********************AC Contact needed*************************\n");
  568. if(strcmp(v1, "count") == 0)
  569. {
  570. for (int i = 0; i < 4; i++)
  571. {
  572. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  573. }
  574. }
  575. else if(strcmp(v1, "ver") == 0)
  576. {
  577. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  578. {
  579. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  580. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  581. }
  582. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  583. {
  584. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  585. {
  586. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  587. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  588. }
  589. }
  590. }
  591. else if(strcmp(v1, "cap") == 0)
  592. {
  593. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  594. {
  595. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  596. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  597. }
  598. }
  599. else if(strcmp(v1, "input") == 0)
  600. {
  601. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  602. {
  603. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  604. {
  605. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  606. i, count,
  607. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  608. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  609. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  610. }
  611. }
  612. }
  613. else if (strcmp(v1, "output") == 0)
  614. {
  615. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  616. {
  617. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  618. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  619. }
  620. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  621. {
  622. if (!FindChargingInfoData(i, &_chargingData[0]))
  623. {
  624. printf ("FindChargingInfoData error\n");
  625. continue;
  626. }
  627. printf("From RB : Group Index = %d, OutputV = %f \n",
  628. i, _chargingData[i]->FireChargingVoltage);
  629. }
  630. }
  631. else if (strcmp(v1, "test") == 0)
  632. {
  633. int mode = atoi(v2);
  634. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  635. {
  636. ShmPsuData->Work_Step = mode;
  637. }
  638. }
  639. else if (strcmp(v1, "out") == 0)
  640. {
  641. float vol = atof(v2);
  642. float cur = atof(v3);
  643. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  644. {
  645. if (!FindChargingInfoData(0, &_chargingData[0]))
  646. {
  647. printf ("FindChargingInfoData error\n");
  648. return;
  649. }
  650. _chargingData[0]->EvBatterytargetVoltage = vol;
  651. _chargingData[0]->EvBatterytargetCurrent = cur;
  652. }
  653. }
  654. printf("*************************************************\n");
  655. }
  656. void GetConnectorCapInfo(char *v1)
  657. {
  658. int _GunIndex = atoi(v1);
  659. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  660. {
  661. printf ("FindChargingInfoData error\n");
  662. return;
  663. }
  664. printf ("Charger Max Current = %d, Max Power = %d \n",
  665. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  666. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  667. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  668. _GunIndex,
  669. _chargingData[_GunIndex]->RealMaxPower,
  670. _chargingData[_GunIndex]->RealMaxVoltage,
  671. _chargingData[_GunIndex]->RealMaxCurrent);
  672. }
  673. static void get_char(char *word)
  674. {
  675. fd_set rfds;
  676. struct timeval tv;
  677. FD_ZERO(&rfds);
  678. FD_SET(0, &rfds);
  679. tv.tv_sec = 0;
  680. tv.tv_usec = 10; //wait input timout time
  681. //if input
  682. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  683. {
  684. fgets(word, 128, stdin);
  685. }
  686. }
  687. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  688. {
  689. int _GunIndex;
  690. float _Voltage;
  691. float _Current;
  692. if (strcmp(v1, "auto") == EQUAL)
  693. {
  694. _usingAutoRun = 0x01;
  695. _GunIndex = atoi(v2);
  696. _Voltage = 500;
  697. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  698. }
  699. else
  700. {
  701. _usingAutoRun = 0x00;
  702. _GunIndex = atoi(v1);
  703. _Voltage = atof(v2);
  704. _Current = atof(v3);
  705. }
  706. unsigned char PreviousSystemStatus = 0xff;
  707. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  708. {
  709. printf ("FindChargingInfoData error\n");
  710. return;
  711. }
  712. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  713. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  714. if(_Voltage > 1000 || _Voltage < 50)
  715. {
  716. printf ("Input Voltage over range\n");
  717. return;
  718. }
  719. // if(_Current > 100 || _Current < 2){
  720. //
  721. // printf ("Input Current over range\n");
  722. // return;
  723. // }
  724. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  725. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  726. //kill ev task
  727. system("killall Module_EvComm");
  728. //_Voltage = (_Voltage * 10);
  729. //_Current = (_Current * 10);
  730. //system(STTY_US TTY_PATH);
  731. while(true)
  732. {
  733. //fix gun 1
  734. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  735. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  736. {
  737. case S_IDLE:
  738. {
  739. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  740. {
  741. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  742. printf ("[UnconditionalCharge - S_IDLE]\n");
  743. }
  744. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  745. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  746. }
  747. break;
  748. case S_PREPARNING:
  749. {
  750. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  751. {
  752. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  753. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  754. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  755. printf ("wait find module\n");
  756. }
  757. //main 會在此階段判斷以下資料跳到下一個 state
  758. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  759. //ShmPsuData->SystemPresentPsuQuantity;
  760. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  761. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  762. //_chargingData[gun_index]->AvailableChargingPower;
  763. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  764. //sleep(10);
  765. //清除 main timeout 機制
  766. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  767. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  768. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  769. }
  770. break;
  771. case S_PREPARING_FOR_EV:
  772. {
  773. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  774. {
  775. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  776. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  777. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  778. }
  779. //清除 main timeout 機制
  780. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  781. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  782. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  783. //充電電壓電流
  784. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  785. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  786. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  787. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  788. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  789. //確定模組己升壓完成
  790. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  791. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  792. {
  793. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  794. //EV done
  795. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  796. }
  797. }
  798. break;
  799. case S_PREPARING_FOR_EVSE:
  800. {
  801. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  802. {
  803. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  804. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  805. }
  806. //printf ("tar vol = %d \n", _Voltage);
  807. //printf ("tar cur = %d \n", _Current);
  808. //清除 main timeout 機制
  809. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  810. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  811. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  812. //充電電壓電流
  813. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  814. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  815. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  816. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  817. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  818. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  819. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  820. //確定模組己升壓完成
  821. if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  822. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  823. {
  824. printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  825. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  826. sleep(5);
  827. //EV done
  828. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  829. }
  830. else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  831. {
  832. printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  833. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  834. }
  835. }
  836. break;
  837. case S_CHARGING:
  838. {
  839. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  840. {
  841. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  842. if (_usingAutoRun == 0x00)
  843. {
  844. //充電電壓電流
  845. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  846. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  847. }
  848. else
  849. {
  850. _curAutoRunCount = 0;
  851. gettimeofday(&_autoTime, NULL);
  852. }
  853. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  854. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  855. printf ("[UnconditionalCharge - S_CHARGING]\n");
  856. }
  857. if (_usingAutoRun == 0x01)
  858. {
  859. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  860. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  861. {
  862. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  863. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  864. }
  865. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  866. {
  867. _curAutoRunCount++;
  868. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  869. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  870. else
  871. gettimeofday(&_autoTime, NULL);
  872. }
  873. else
  874. {
  875. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
  876. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
  877. }
  878. }
  879. // printf("out : vol = %f, cur = %f \n",
  880. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  881. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  882. //ev task do this
  883. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  884. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  885. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  886. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  887. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  888. }
  889. }
  890. break;
  891. case S_TERMINATING:
  892. {
  893. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  894. {
  895. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  896. system("/root/Module_EvComm &");
  897. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  898. //無阻塞偵測 keybaord 結束
  899. system(STTY_DEF TTY_PATH);
  900. }
  901. sleep(3);
  902. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  903. return;
  904. }
  905. break;
  906. case S_COMPLETE:
  907. {
  908. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  909. {
  910. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  911. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  912. }
  913. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
  914. sleep(3);
  915. return;
  916. }
  917. break;
  918. }
  919. char word[128];
  920. char newString[7][10];
  921. int i,j,ctr;
  922. memset(word, 0x00, sizeof(word));
  923. get_char(word);
  924. if (strlen(word) == 0)
  925. continue;
  926. j=0; ctr=0;
  927. strcpy(newString[1], "-1");
  928. strcpy(newString[2], "-1");
  929. for (i = 0; i <= (strlen(word)); i++)
  930. {
  931. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  932. {
  933. newString[ctr][j] = '\0';
  934. ctr++;
  935. j = 0;
  936. }
  937. else
  938. {
  939. newString[ctr][j] = word[i];
  940. j++;
  941. }
  942. }
  943. if(strcmp(newString[0], "chg") == 0)
  944. {
  945. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  946. continue;
  947. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  948. continue;
  949. float _vol = atof(newString[1]);
  950. float _cur = atof(newString[2]);
  951. if (_cur <= 0 || _cur <= 0)
  952. continue;
  953. printf("vol = %f, cur = %f \n", _vol, _cur);
  954. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  955. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  956. }
  957. else if (strcmp(newString[0], "c") == 0)
  958. {
  959. printf("stop \n\r");
  960. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  961. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  962. }
  963. usleep(100000);
  964. }
  965. }
  966. int main(void)
  967. {
  968. if(InitShareMemory() == FAIL)
  969. {
  970. printf ("InitShareMemory = FAIL \n");
  971. if(ShmStatusCodeData != NULL)
  972. {
  973. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  974. }
  975. sleep(5);
  976. return 0;
  977. }
  978. for(;;)
  979. {
  980. char word[128];
  981. char newString[7][10];
  982. int i,j,ctr;
  983. fgets(word, sizeof(word), stdin);
  984. j=0; ctr=0;
  985. strcpy(newString[1], "-1");
  986. strcpy(newString[2], "-1");
  987. for (i = 0; i <= (strlen(word)); i++)
  988. {
  989. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  990. {
  991. newString[ctr][j] = '\0';
  992. ctr++;
  993. j = 0;
  994. }
  995. else
  996. {
  997. newString[ctr][j] = word[i];
  998. j++;
  999. }
  1000. }
  1001. if(strcmp(newString[0], "state") == 0)
  1002. {
  1003. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1004. continue;
  1005. // 槍狀態
  1006. RunStatusProc(newString[1], newString[2]);
  1007. }
  1008. else if(strcmp(newString[0], "card") == 0)
  1009. {
  1010. // 刷卡狀態
  1011. RunCardProc(newString[1], newString[2]);
  1012. }
  1013. else if(strcmp(newString[0], "gun") == 0)
  1014. {
  1015. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1016. continue;
  1017. // 插槍狀態
  1018. RunGunPlugitProc(newString[1], newString[2]);
  1019. }
  1020. else if(strcmp(newString[0], "lock") == 0)
  1021. {
  1022. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1023. continue;
  1024. // 插槍狀態
  1025. GetGunLockStatusProc(newString[1], newString[2]);
  1026. }
  1027. else if(strcmp(newString[0], "sysid") == 0)
  1028. {
  1029. // 測試 sys id
  1030. SetSystemIDProc();
  1031. }
  1032. else if(strcmp(newString[0], "self") == 0)
  1033. {
  1034. // CSU 自我檢測狀態
  1035. RunSelfProc(newString[1]);
  1036. }
  1037. else if(strcmp(newString[0], "ver") == 0)
  1038. {
  1039. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1040. continue;
  1041. // 取 FW 版號
  1042. GetFwVerProc(newString[1]);
  1043. }
  1044. else if (strcmp(newString[0], "update") == 0)
  1045. {
  1046. // 更新
  1047. FwUpdateFlagProc(newString[1]);
  1048. }
  1049. else if (strcmp(newString[0], "ac") == 0)
  1050. {
  1051. // AC contactor 狀態
  1052. CheckAcStatus(newString[1]);
  1053. }
  1054. else if (strcmp(newString[0], "cable") == 0)
  1055. {
  1056. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1057. continue;
  1058. // cable check pass
  1059. SetCableChkStatus(newString[1], newString[2]);
  1060. }
  1061. else if (strcmp(newString[0], "pow") == 0)
  1062. {
  1063. // get output power
  1064. GetPowerValue();
  1065. }
  1066. else if (strcmp(newString[0], "model") == 0)
  1067. {
  1068. GetSystemInfo();
  1069. }
  1070. else if(strcmp(newString[0], "select") == 0)
  1071. {
  1072. // 取得 / 設定 當前選的槍號
  1073. GetGunSelectedNum(newString[1]);
  1074. }
  1075. else if(strcmp(newString[0], "change") == 0)
  1076. {
  1077. // 模擬按鈕改變選槍
  1078. ChangeGunNum();
  1079. }
  1080. else if(strcmp(newString[0], "fan") == 0)
  1081. {
  1082. // 設定風扇速度
  1083. SetFanSpeed(newString[1]);
  1084. }
  1085. else if(strcmp(newString[0], "speed") == 0)
  1086. {
  1087. // 取得風扇速度
  1088. GetFanSpeed();
  1089. }
  1090. else if(strcmp(newString[0], "debug") == 0)
  1091. {
  1092. // 設定 debug mode
  1093. SetDebugMode(newString[1]);
  1094. }
  1095. else if (strcmp(newString[0], "gfd") == 0)
  1096. {
  1097. // 設定盲沖使用 GFD 功能
  1098. SetGFDMode(newString[1]);
  1099. }
  1100. else if(strcmp(newString[0], "temp") == 0)
  1101. {
  1102. // 取得 PSU 溫度
  1103. GetPsuTemp();
  1104. }
  1105. else if(strcmp(newString[0], "acin") == 0)
  1106. {
  1107. // 取得三向輸入電壓
  1108. GetAcInputVol();
  1109. }
  1110. else if(strcmp(newString[0], "psu") == 0)
  1111. {
  1112. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1113. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1114. {
  1115. printf ("PSU : Param fail..Please retry again......\n");
  1116. continue;
  1117. }
  1118. // 取得 PSU 資訊
  1119. GetPsuInformation(newString[1], newString[2], newString[3]);
  1120. }
  1121. else if (strcmp(newString[0], "cap") == 0)
  1122. {
  1123. GetConnectorCapInfo(newString[1]);
  1124. }
  1125. else if(strcmp(newString[0], "error") == 0)
  1126. {
  1127. CreateOneError(newString[1]);
  1128. }
  1129. else if (strcmp(newString[0], "auth") == 0)
  1130. {
  1131. GetAuthorizeFlag(newString[1]);
  1132. }
  1133. else if (strcmp(newString[0], "relay") == 0)
  1134. {
  1135. GetRelayStatus(newString[1]);
  1136. }
  1137. else if (strcmp(newString[0], "ccid") == 0)
  1138. {
  1139. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1140. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1141. {
  1142. printf ("Input ccid fail.\n");
  1143. continue;
  1144. }
  1145. SetChargingInfoCCID(newString[1], newString[2]);
  1146. }
  1147. else if (strcmp(newString[0], "soc") == 0)
  1148. {
  1149. GetSOC(newString[1]);
  1150. }
  1151. else if (strcmp(newString[0], "test") == 0)
  1152. {
  1153. if (!FindChargingInfoData(1, &_chargingData[0]))
  1154. {
  1155. printf ("FindChargingInfoData error\n");
  1156. continue;
  1157. }
  1158. }
  1159. else if(strcmp(newString[0], "strchg") == 0)
  1160. {
  1161. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1162. if (strcmp(newString[1], "auto") == 0)
  1163. {
  1164. newString[3][0] = 0;
  1165. }
  1166. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1167. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1168. {
  1169. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1170. continue;
  1171. }
  1172. // 槍狀態
  1173. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1174. }
  1175. else
  1176. printf ("%s\n", msg);
  1177. usleep(100000);
  1178. }
  1179. return 0;
  1180. }