Module_LcmControl.c 38 KB

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