Module_LcmControl.c 40 KB

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