ReadCmdline.c 40 KB

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