Module_LcmControl.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. #include "Module_LcmControl.h"
  2. bool needReloadQr = true;
  3. void PRINTF_FUNC(char *string, ...);
  4. int StoreLogMsg(const char *fmt, ...);
  5. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  6. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  7. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  8. char* getTimeString(void);
  9. //=================================
  10. // Common routine
  11. //=================================
  12. int StoreLogMsg(const char *fmt, ...)
  13. {
  14. char Buf[4096+256];
  15. char buffer[4096];
  16. time_t CurrentTime;
  17. struct tm *tm;
  18. va_list args;
  19. va_start(args, fmt);
  20. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  21. va_end(args);
  22. memset(Buf,0,sizeof(Buf));
  23. CurrentTime = time(NULL);
  24. tm=localtime(&CurrentTime);
  25. sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  26. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
  27. buffer,
  28. tm->tm_year+1900,tm->tm_mon+1);
  29. system(Buf);
  30. return rc;
  31. }
  32. char* getTimeString(void)
  33. {
  34. char *result=malloc(21);
  35. time_t timep;
  36. struct tm *p;
  37. time(&timep);
  38. p=gmtime(&timep);
  39. sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
  40. return result;
  41. }
  42. void PRINTF_FUNC(char *string, ...)
  43. {
  44. va_list args;
  45. char buffer[4096];
  46. va_start(args, string);
  47. vsnprintf(buffer, sizeof(buffer), string, args);
  48. va_end(args);
  49. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
  50. printf("%s \n", buffer);
  51. else
  52. DEBUG_INFO("%s \n", buffer);
  53. }
  54. //==========================================
  55. // Init all share memory
  56. //==========================================
  57. int InitShareMemory()
  58. {
  59. int result = PASS;
  60. int MeterSMId;
  61. //creat ShmSysConfigAndInfo
  62. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  63. {
  64. #ifdef SystemLogMessage
  65. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  66. #endif
  67. result = FAIL;
  68. }
  69. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  70. {
  71. #ifdef SystemLogMessage
  72. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  73. #endif
  74. result = FAIL;
  75. }
  76. else
  77. {}
  78. //creat ShmStatusCodeData
  79. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  80. {
  81. #ifdef SystemLogMessage
  82. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  83. #endif
  84. result = FAIL;
  85. }
  86. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  87. {
  88. #ifdef SystemLogMessage
  89. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  90. #endif
  91. result = FAIL;
  92. }
  93. else
  94. {}
  95. return result;
  96. }
  97. //==========================================
  98. // Open and Close RS232 and R/W
  99. //==========================================
  100. int CreateCommunicationLcmPort()
  101. {
  102. int fd;
  103. struct termios tios;
  104. fd = open(pPortName, O_RDWR);
  105. if (fd <= 0) {
  106. #ifdef SystemLogMessage
  107. DEBUG_ERROR("open /dev/ttyS3 NG \n");
  108. #endif
  109. return -1;
  110. }
  111. ioctl(fd, TCGETS, &tios);
  112. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  113. tios.c_lflag = 0;
  114. tios.c_iflag = 0;
  115. tios.c_oflag = 0;
  116. tios.c_cc[VMIN] = 0;
  117. tios.c_cc[VTIME] = (unsigned char) 5;
  118. tios.c_lflag = 0;
  119. tcflush(fd, TCIFLUSH);
  120. ioctl(fd, TCSETS, &tios);
  121. return fd;
  122. }
  123. void CloseCommunicationLcmPort()
  124. {
  125. close(_port);
  126. }
  127. void WriteCmdToLcm(byte *cmd, byte cmdLen)
  128. {
  129. int len = write(_port, cmd, cmdLen);
  130. if(len >= sizeof(cmd))
  131. {
  132. //PRINTF_FUNC("Write cmd to LCM successfully. \n");
  133. }
  134. }
  135. void ReadMsgFromLcm(byte *msg, byte readLen)
  136. {
  137. read(_port, msg, readLen);
  138. if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
  139. {
  140. if(*(msg + 3) == CMD_WRITE)
  141. {
  142. switch (*(msg + 4))
  143. {
  144. case CMD_REGISTER:
  145. {
  146. // 頁面
  147. strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
  148. }
  149. break;
  150. }
  151. }
  152. else if (*(msg + 3) == CMD_MULTI_READ)
  153. {
  154. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  155. // {
  156. // case BUTTON_GUN_INDEX:
  157. // {
  158. // // 當前選的槍號
  159. // _curGunIndex = (*(msg + 8));
  160. // }
  161. // break;
  162. // }
  163. }
  164. }
  165. }
  166. //================================================
  167. // Function
  168. //================================================
  169. void ChangeToOtherPage(short newPage)
  170. {
  171. byte cmd[7];
  172. memset(cmd, 0x00, sizeof(cmd));
  173. cmd[0] = CMD_TITLE_1;
  174. cmd[1] = CMD_TITLE_2;
  175. cmd[2] = 0x02 + sizeof(newPage);
  176. cmd[3] = CMD_READ;
  177. cmd[4] = CMD_REGISTER;
  178. cmd[5] = newPage >> 8;
  179. cmd[6] = newPage & 0x00FF;
  180. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  181. usleep(100000);
  182. }
  183. void ChangeBackLight(bool islight)
  184. {
  185. byte value = 0x01;
  186. if (islight)
  187. {
  188. value = 0x20;
  189. }
  190. byte cmd[7];
  191. memset(cmd, 0x00, sizeof(cmd));
  192. cmd[0] = CMD_TITLE_1;
  193. cmd[1] = CMD_TITLE_2;
  194. cmd[2] = 0x03;
  195. cmd[3] = CMD_READ;
  196. cmd[4] = CMD_BACKLIGHT;
  197. cmd[5] = value;
  198. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  199. usleep(100000);
  200. }
  201. void GetCurrentPage()
  202. {
  203. byte cmd[6];
  204. memset(cmd, 0x00, sizeof(cmd));
  205. byte msg[8];
  206. memset(msg, 0x00, sizeof(msg));
  207. cmd[0] = CMD_TITLE_1;
  208. cmd[1] = CMD_TITLE_2;
  209. cmd[2] = 0x03; // 底下總長度
  210. cmd[3] = CMD_WRITE;
  211. cmd[4] = CMD_REGISTER;
  212. cmd[5] = 0x02;
  213. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  214. usleep(100000);
  215. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  216. }
  217. void DisplayValueToLcm(short address, byte *data, byte len)
  218. {
  219. byte cmd[256];
  220. memset(cmd, 0x00, sizeof(cmd));
  221. cmd[0] = CMD_TITLE_1;
  222. cmd[1] = CMD_TITLE_2;
  223. cmd[2] = 0x03 + len;
  224. cmd[3] = CMD_MULTI_WRITE;
  225. cmd[4] = address >> 8;
  226. cmd[5] = address & 0x00FF;
  227. for(byte count = 0; count < len; count++)
  228. {
  229. cmd[6 + count] = *(data + count);
  230. }
  231. WriteCmdToLcm(cmd, cmd[2] + 3);
  232. }
  233. void ChangeDisplay2Value(short address, short value)
  234. {
  235. byte data[2];
  236. data[0] = value >> 8;
  237. data[1] = value & 0x00FF;
  238. DisplayValueToLcm(address, data, sizeof(data));
  239. }
  240. void GetBtnStatus(short address, byte len)
  241. {
  242. byte cmd[8];
  243. memset(cmd, 0x00, sizeof(cmd));
  244. byte msg[8];
  245. memset(msg, 0x00, sizeof(msg));
  246. cmd[0] = CMD_TITLE_1;
  247. cmd[1] = CMD_TITLE_2;
  248. cmd[2] = 0x03 + len;
  249. cmd[3] = CMD_MULTI_READ;
  250. cmd[4] = address >> 8;
  251. cmd[5] = address & 0x00FF;
  252. cmd[6] = 0x00 + len;
  253. WriteCmdToLcm(cmd, cmd[2] + 3);
  254. usleep(100000);
  255. ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
  256. }
  257. //================================================
  258. // Warning process
  259. //================================================
  260. void string2ByteArray(unsigned char *input, byte *output)
  261. {
  262. int loop;
  263. int i;
  264. loop = 0;
  265. i = 0;
  266. while(input[loop] != '\0')
  267. {
  268. output[i++] = input[loop++];
  269. }
  270. output[loop] = '\0';
  271. }
  272. void ChangeWarningFunc()
  273. {
  274. byte cmd[7];
  275. byte i = 0;
  276. //PRINTF_FUNC("ChangeWarningFunc \n");
  277. // 最多一次五筆
  278. //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
  279. //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  280. for(i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  281. {
  282. memset(cmd, 0x00, sizeof(cmd));
  283. if(i >= 5)
  284. {
  285. break;
  286. }
  287. //error code
  288. string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
  289. DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
  290. //警告標示
  291. memset(cmd, 0x00, sizeof(cmd));
  292. cmd[0] = 0x00;
  293. cmd[1] = 0x01;
  294. DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
  295. }
  296. memset(cmd, 0x00, sizeof(cmd));
  297. for(; i < 5; i++)
  298. {
  299. DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
  300. DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
  301. }
  302. }
  303. //================================================
  304. // QR Code process
  305. //================================================
  306. void ChangeQrCode_Idle(char *input)
  307. {
  308. int len = strlen(input);
  309. byte cmd[len];
  310. int loop = 0;
  311. int i = 0;
  312. while(input[loop] != '\0')
  313. {
  314. cmd[i++] = input[loop++];
  315. }
  316. DisplayValueToLcm(__qr_code, cmd, len);
  317. }
  318. void ChangeQrCode_Charge(char *input)
  319. {
  320. int len = strlen(input);
  321. byte cmd[len];
  322. int loop = 0;
  323. int i = 0;
  324. while(input[loop] != '\0')
  325. {
  326. cmd[i++] = input[loop++];
  327. }
  328. DisplayValueToLcm(__qr_code_pre, cmd, len);
  329. }
  330. //================================================
  331. // Change current page
  332. //================================================
  333. void ChangeCurPage()
  334. {
  335. //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
  336. if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex)
  337. {
  338. _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
  339. ChangeToOtherPage(_currentPage);
  340. _everyPageRollChange = 0;
  341. }
  342. }
  343. //================================================
  344. // Main process
  345. //================================================
  346. byte demoCount = 0;
  347. void DemoFunction()
  348. {
  349. if (demoCount == 0)
  350. {
  351. ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
  352. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
  353. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
  354. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
  355. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
  356. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
  357. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
  358. }
  359. else
  360. {
  361. if (demoCount == 20) {
  362. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_IDLE;
  363. } else if (demoCount == 80) {
  364. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
  365. } else if (demoCount == 100) {
  366. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
  367. } else if (demoCount == 120) {
  368. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
  369. } else if (demoCount == 140) {
  370. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
  371. } else if (demoCount == 180) {
  372. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
  373. }
  374. }
  375. if (demoCount < 180)
  376. demoCount++;
  377. }
  378. //================================================
  379. // Main process
  380. //================================================
  381. bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
  382. {
  383. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  384. {
  385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  386. {
  387. _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  388. return true;
  389. }
  390. }
  391. for (byte index = 0; index < CCS_QUANTITY; index++)
  392. {
  393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  394. {
  395. _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  396. return true;
  397. }
  398. }
  399. for (byte index = 0; index < GB_QUANTITY; index++)
  400. {
  401. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  402. {
  403. _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  404. return true;
  405. }
  406. }
  407. return false;
  408. }
  409. void ChangeBattMapAndValue(short page, int soc)
  410. {
  411. // srand(time(NULL));
  412. // int min = 10;
  413. // int max = 90;
  414. // soc = rand() % (max - min + 1) + min;
  415. if (page == _LCM_CHARGING)
  416. {
  417. if (soc < 20)
  418. {
  419. if (_battery_display_ani)
  420. ChangeDisplay2Value(__batt_map, _battery_empty);
  421. else
  422. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  423. }
  424. else if (soc >= 20 && soc < 40)
  425. {
  426. if (_battery_display_ani)
  427. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  428. else
  429. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  430. }
  431. else if (soc >= 40 && soc < 60)
  432. {
  433. if (_battery_display_ani)
  434. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  435. else
  436. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  437. }
  438. else if (soc >= 60 && soc < 80)
  439. {
  440. if (_battery_display_ani)
  441. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  442. else
  443. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  444. }
  445. else if (soc >= 80 && soc <= 100)
  446. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  447. }
  448. else if (page == _LCM_COMPLETE)
  449. {
  450. if (soc < 20)
  451. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  452. else if (soc >= 20 && soc < 40)
  453. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  454. else if (soc >= 40 && soc < 60)
  455. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  456. else if (soc >= 60 && soc < 80)
  457. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  458. else if (soc >= 80 && soc <= 100)
  459. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  460. }
  461. byte cmd[5];
  462. byte value[5];
  463. memset(cmd, 0x00, sizeof(cmd));
  464. memset(value, 0x00, sizeof(value));
  465. sprintf((char *)value, "%d%%", soc);
  466. string2ByteArray(value, cmd);
  467. DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
  468. }
  469. void ChangeRemainTime(int sec)
  470. {
  471. int h, m, s;
  472. byte cmd[10];
  473. byte value[10];
  474. memset(cmd, 0x00, sizeof(cmd));
  475. // srand(time(NULL));
  476. // int min = 0;
  477. // int max = 65536;
  478. // sec = rand() % (max - min + 1) + min;
  479. h = (sec / 3600);
  480. m = (sec - (3600 * h)) / 60;
  481. s = (sec - (3600 * h) - (m * 60));
  482. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  483. string2ByteArray(value, cmd);
  484. DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
  485. }
  486. void ChangeChargingEnergyValue(float energy)
  487. {
  488. byte cmd[10];
  489. byte value[10];
  490. memset(cmd, 0x00, sizeof(cmd));
  491. if(energy > 0.05)
  492. {
  493. energy -= 0.05;
  494. }
  495. sprintf((char *) value, "%.1f kWh", energy);
  496. string2ByteArray(value, cmd);
  497. DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
  498. }
  499. void ChangeChargingPowerValue(float pow)
  500. {
  501. byte cmd[10];
  502. byte value[10];
  503. memset(cmd, 0x00, sizeof(cmd));
  504. // float min = 0.0;
  505. // float max = 50;
  506. // pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
  507. sprintf((char *) value, "%.1f kW", pow);
  508. string2ByteArray(value, cmd);
  509. DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
  510. }
  511. void ChangeChargingFeeValue(float fee)
  512. {
  513. byte cmd[10];
  514. byte value[10];
  515. memset(cmd, 0x00, sizeof(cmd));
  516. sprintf((char *) value, "%.2f", fee);
  517. string2ByteArray(value, cmd);
  518. DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
  519. }
  520. void DisplayMoneyRate(float money)
  521. {
  522. byte cmd[8];
  523. byte value[8];
  524. memset(cmd, 0x00, sizeof(cmd));
  525. sprintf((char *) value, "%.2f", money);
  526. string2ByteArray(value, cmd);
  527. DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
  528. }
  529. void DisplayMoneyCur(byte *cur)
  530. {
  531. byte cmd[5];
  532. byte buf[5];
  533. *(cur + 3) = '\0';
  534. memset(cmd, 0x00, sizeof(cmd));
  535. sprintf((char *) buf, "%s", cur);
  536. string2ByteArray(buf, cmd);
  537. DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
  538. }
  539. void RefreshPageAnimation(byte value)
  540. {
  541. switch(_currentPage)
  542. {
  543. case _LCM_IDLE:
  544. {
  545. }
  546. break;
  547. case _LCM_WAIT_FOR_PLUG:
  548. {
  549. if(_everyPageRollChange == 0)
  550. ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
  551. else if(_everyPageRollChange == 15)
  552. ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
  553. _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  554. }
  555. break;
  556. case _LCM_PRE_CHARGE:
  557. case _LCM_CHARGING:
  558. case _LCM_COMPLETE:
  559. {
  560. if (_currentPage == _LCM_PRE_CHARGE)
  561. {
  562. if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
  563. ChangeDisplay2Value(__conn_line, _conn_map1);
  564. else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
  565. ChangeDisplay2Value(__conn_line, _conn_map2);
  566. }
  567. else if (_currentPage == _LCM_CHARGING)
  568. {
  569. if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
  570. ChangeDisplay2Value(__conn_line_chag, _charging_map1);
  571. else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
  572. ChangeDisplay2Value(__conn_line_chag, _charging_map2);
  573. }
  574. else if (_currentPage == _LCM_COMPLETE)
  575. {
  576. if (_everyPageRollChange == 0)
  577. ChangeDisplay2Value(__conn_line_comp, _complete_map);
  578. }
  579. _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  580. }
  581. break;
  582. }
  583. }
  584. void RefreshConnStatus()
  585. {
  586. // Wifi priority is higher than Ethernet
  587. if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES)
  588. {
  589. _wifi_conn_status = true;
  590. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  591. ChangeDisplay2Value(__ethernet_status, _disappear);
  592. }
  593. else
  594. {
  595. _wifi_conn_status = false;
  596. ChangeDisplay2Value(__wifi_status, _disappear);
  597. }
  598. if (!_wifi_conn_status)
  599. {
  600. if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
  601. {
  602. ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
  603. }
  604. else
  605. {
  606. ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
  607. }
  608. }
  609. // 連線到後台
  610. if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES)
  611. ChangeDisplay2Value(__conn_status, _connect);
  612. else
  613. ChangeDisplay2Value(__conn_status, _disconnect);
  614. }
  615. byte FirstPageChanged()
  616. {
  617. byte result = NO;
  618. if (_currentPage != _oldPage)
  619. {
  620. result = YES;
  621. _oldPage = _currentPage;
  622. }
  623. return result;
  624. }
  625. void ProcessPageInfo()
  626. {
  627. switch(_currentPage)
  628. {
  629. case _LCM_IDLE:
  630. {
  631. if (ShmSysConfigAndInfo->SysConfig.isRFID)
  632. ChangeDisplay2Value(__main_rfid, _main_rfid);
  633. else
  634. ChangeDisplay2Value(__main_rfid, _main_none_rfid);
  635. if (ShmSysConfigAndInfo->SysConfig.isQRCode)
  636. ChangeDisplay2Value(__main_qr, _main_qr);
  637. else
  638. {
  639. ChangeDisplay2Value(__qr_code, _disappear);
  640. ChangeDisplay2Value(__main_qr, _main_none_qr);
  641. needReloadQr = true;
  642. }
  643. if (ShmSysConfigAndInfo->SysConfig.isAPP)
  644. ChangeDisplay2Value(__main_app, _main_app);
  645. else
  646. ChangeDisplay2Value(__main_app, _main_none_app);
  647. if (FirstPageChanged() == YES || needReloadQr)
  648. {
  649. if (ShmSysConfigAndInfo->SysConfig.isQRCode)
  650. {
  651. needReloadQr = false;
  652. ChangeQrCode_Idle("http://google.com.tw");
  653. }
  654. }
  655. }
  656. break;
  657. case _LCM_AUTHORIZING:
  658. case _LCM_AUTHORIZ_COMP:
  659. case _LCM_AUTHORIZ_FAIL:
  660. case _LCM_WAIT_FOR_PLUG:
  661. {
  662. FirstPageChanged();
  663. }
  664. break;
  665. case _LCM_PRE_CHARGE:
  666. case _LCM_CHARGING:
  667. case _LCM_COMPLETE:
  668. {
  669. if (_totalCount == 2)
  670. {
  671. ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
  672. if (ShmSysConfigAndInfo->SysConfig.isRFID)
  673. ChangeDisplay2Value(__side_top, _side_rfid);
  674. else
  675. ChangeDisplay2Value(__side_top, _side_none_rfid);
  676. if (ShmSysConfigAndInfo->SysConfig.isQRCode)
  677. ChangeDisplay2Value(__side_mid, _side_qr);
  678. else
  679. {
  680. ChangeDisplay2Value(__qr_code_pre, _disappear);
  681. ChangeDisplay2Value(__side_mid, _side_none_qr);
  682. needReloadQr = true;
  683. }
  684. if (ShmSysConfigAndInfo->SysConfig.isAPP)
  685. ChangeDisplay2Value(__side_down, _side_app);
  686. else
  687. ChangeDisplay2Value(__side_down, _side_none_app);
  688. }
  689. else
  690. {
  691. ChangeDisplay2Value(__side_top, _disappear);
  692. ChangeDisplay2Value(__side_mid, _disappear);
  693. ChangeDisplay2Value(__side_down, _disappear);
  694. ChangeDisplay2Value(__sel_gun_btn, _disappear);
  695. }
  696. // gun type and charging info
  697. for(byte i = 0; i < _totalCount; i++)
  698. {
  699. switch(_chargingInfoData[i]->Type)
  700. {
  701. case _Type_Chademo:
  702. {
  703. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
  704. {
  705. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
  706. }
  707. else
  708. {
  709. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
  710. }
  711. }
  712. break;
  713. case _Type_GB:
  714. {
  715. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
  716. {
  717. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
  718. }
  719. else
  720. {
  721. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
  722. }
  723. }
  724. break;
  725. case _Type_CCS_2:
  726. {
  727. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
  728. {
  729. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
  730. }
  731. else
  732. {
  733. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
  734. }
  735. }
  736. break;
  737. }
  738. if (_currentPage == _LCM_CHARGING)
  739. {
  740. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
  741. {
  742. ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
  743. if (_chargingInfoData[i]->RemainChargingDuration >= 0)
  744. ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
  745. else
  746. ChangeRemainTime(0);
  747. if (_chargingInfoData[i]->PresentChargingPower >= 0)
  748. ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
  749. else
  750. ChangeChargingPowerValue(0);
  751. if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1)
  752. ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
  753. else
  754. ChangeChargingEnergyValue(0);
  755. if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0)
  756. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  757. else
  758. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  759. }
  760. }
  761. else if (_currentPage == _LCM_COMPLETE)
  762. {
  763. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
  764. {
  765. ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
  766. if (_chargingInfoData[i]->RemainChargingDuration >= 0)
  767. ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
  768. else
  769. ChangeRemainTime(0);
  770. if (_chargingInfoData[i]->PresentChargingPower >= 0)
  771. ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
  772. else
  773. ChangeChargingPowerValue(0);
  774. if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1)
  775. {
  776. ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
  777. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
  778. _chargingInfoData[i]->ChargingFee >= 0)
  779. {
  780. ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
  781. }
  782. }
  783. else
  784. {
  785. ChangeChargingEnergyValue(0);
  786. ChangeChargingFeeValue(0);
  787. }
  788. }
  789. }
  790. }
  791. // gun btn and QR code
  792. if (_totalCount == 2 && _currentPage)
  793. {
  794. byte index = 0;
  795. for(index = 0; index < _totalCount; index++)
  796. {
  797. if(ShmSysConfigAndInfo->SysInfo.CurGunSelected != index)
  798. {
  799. break;
  800. }
  801. }
  802. if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
  803. _chargingInfoData[index]->SystemStatus == S_RESERVATION ||
  804. _chargingInfoData[index]->SystemStatus == S_BOOTING)
  805. {
  806. if (FirstPageChanged() == YES || needReloadQr)
  807. {
  808. if (ShmSysConfigAndInfo->SysConfig.isQRCode)
  809. {
  810. needReloadQr = false;
  811. ChangeQrCode_Charge("http://google.com.tw");
  812. }
  813. }
  814. }
  815. }
  816. }
  817. break;
  818. }
  819. }
  820. void ChangeDisplayMoneyInfo()
  821. {
  822. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
  823. {
  824. struct timeb csuTime;
  825. struct tm *tmCSU;
  826. ftime(&csuTime);
  827. tmCSU = localtime(&csuTime.time);
  828. ChangeDisplay2Value(__money_rate_map, _charging_money);
  829. if (tmCSU->tm_hour <= 23)
  830. {
  831. ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
  832. DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
  833. }
  834. if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
  835. DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
  836. }
  837. else
  838. {
  839. ChangeDisplay2Value(__money_rate_map, _disappear);
  840. ChangeDisplay2Value(__money_by_rate, _disappear);
  841. ChangeDisplay2Value(__money_rate, _disappear);
  842. }
  843. }
  844. void Initialization()
  845. {
  846. bool isPass = false;
  847. byte count = 5;
  848. while(!isPass && count > 0)
  849. {
  850. isPass = true;
  851. for (byte _index = 0; _index < _totalCount; _index++)
  852. {
  853. if (!FindChargingInfoData(_index, &_chargingInfoData[0]))
  854. {
  855. DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
  856. isPass = false;
  857. count--;
  858. break;
  859. }
  860. }
  861. }
  862. if (count == 0)
  863. PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
  864. }
  865. int main(void)
  866. {
  867. if(InitShareMemory() == FAIL)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("InitShareMemory NG\n");
  871. #endif
  872. if (ShmStatusCodeData != NULL)
  873. {
  874. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  875. }
  876. sleep(5);
  877. return 0;
  878. }
  879. _port = CreateCommunicationLcmPort();
  880. byte changeWarningPriority = 0;
  881. byte curWarningCount = 255;
  882. //ChangeBackLight(true);
  883. _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  884. Initialization();
  885. //ChangeToOtherPage(_LCM_INIT);
  886. //return 0;
  887. while(_port != -1)
  888. {
  889. if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName) != 0x00)
  890. {
  891. GetCurrentPage();
  892. sleep(1);
  893. }
  894. else
  895. {
  896. //DemoFunction();
  897. // Warning 處理
  898. if(curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
  899. {
  900. changeWarningPriority = 0;
  901. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  902. curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
  903. ChangeWarningFunc();
  904. }
  905. else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0)
  906. {
  907. // 當有兩頁 Warning 則每隔三秒改變一次
  908. if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
  909. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
  910. else
  911. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  912. ChangeWarningFunc();
  913. }
  914. // 頁面資訊處理
  915. ProcessPageInfo();
  916. // 網路 - wifi - 連線訊號處理
  917. RefreshConnStatus();
  918. // 換頁處理
  919. ChangeCurPage();
  920. RefreshPageAnimation(_everyPageRollChange);
  921. if (changeWarningPriority == 0)
  922. ChangeDisplayMoneyInfo();
  923. changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
  924. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  925. usleep(100000);
  926. }
  927. }
  928. CloseCommunicationLcmPort();
  929. return FAIL;
  930. }