Module_LcmControl.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <termios.h>
  7. #include <fcntl.h>
  8. #include <time.h>
  9. #include <sys/ioctl.h>
  10. #include <sys/timeb.h>
  11. #include "Module_LcmControl.h"
  12. #include "../Log/log.h"
  13. #include "../ShareMemory/shmMem.h"
  14. #include "../Define/define.h"
  15. #include "../Config.h"
  16. #include "../SelectGun/SelectGun.h"
  17. #include "../CSU/main.h"
  18. #define uSEC_VAL (1000000)
  19. //------------------------------------------------------------------------------
  20. //struct SysConfigAndInfo *ShmSysConfigAndInfo;
  21. //struct StatusCodeData *ShmStatusCodeData;
  22. static struct SysConfigData *pSysConfig = NULL;
  23. static struct SysInfoData *pSysInfo = NULL;
  24. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  25. static struct FanModuleData *ShmFanModuleData;
  26. static struct PrimaryMcuData *ShmPrimaryMcuData;
  27. static SelectGunInfo *ShmSelectGunInfo = NULL;
  28. static struct ChargingInfoData *pDcChargingInfo = NULL;
  29. static DcCommonInfo *ShmDcCommonData = NULL;
  30. short _currentPage = _PAGE_NONE;
  31. uint8_t _totalCount;
  32. uint8_t _showInformIndex = 0;
  33. float ChargeMaxPower_0 = 0;
  34. float ChargeMaxPower_1 = 0;
  35. bool _battery_display_ani = false;
  36. int _port;
  37. //char* pPortName = "/dev/ttyO2";
  38. char *pPortName = "/dev/ttyS3";
  39. char *moduleName = "DMT80480T070_09WT";
  40. bool is_show = false;
  41. uint8_t _everyPageRollChange;
  42. uint8_t _btn_press = 0;
  43. short _btn_press_id = 0;
  44. struct timeval returnIdleTimer;
  45. int _Text_Running_Count = 0;
  46. int Battery_Test = 0;
  47. extern void UpdateLcmFunction(DcCommonInfo *ShmDcCommonData,int _lcmport);
  48. //==========================================
  49. // Open and Close RS232 and R/W
  50. //==========================================
  51. unsigned long GetClockTimeoutValue(struct timespec _start_time)
  52. {
  53. struct timespec ts_end;
  54. unsigned long ret = 0;
  55. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  56. ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
  57. return ret;
  58. }
  59. int CreateCommunicationLcmPort()
  60. {
  61. int fd;
  62. struct termios tios;
  63. fd = open(pPortName, O_RDWR);
  64. if (fd <= 0) {
  65. log_error("open /dev/ttyS3 NG ");
  66. return -1;
  67. }
  68. ioctl(fd, TCGETS, &tios);
  69. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  70. tios.c_lflag = 0;
  71. tios.c_iflag = 0;
  72. tios.c_oflag = 0;
  73. tios.c_cc[VMIN] = 0;
  74. tios.c_cc[VTIME] = (uint8_t) 5;
  75. tios.c_lflag = 0;
  76. tcflush(fd, TCIFLUSH);
  77. ioctl(fd, TCSETS, &tios);
  78. return fd;
  79. }
  80. void CloseCommunicationLcmPort()
  81. {
  82. close(_port);
  83. }
  84. void GetDeviceInfoStatus(short address, uint8_t len)
  85. {
  86. uint8_t cmd[8];
  87. memset(cmd, 0x00, sizeof(cmd));
  88. uint8_t msg[11];
  89. memset(msg, 0x00, sizeof(msg));
  90. cmd[0] = CMD_TITLE_1;
  91. cmd[1] = CMD_TITLE_2;
  92. cmd[2] = 0x04;
  93. cmd[3] = CMD_MULTI_READ;
  94. cmd[4] = (address >> 8) & 0xff;
  95. cmd[5] = (address >> 0) & 0xff;
  96. cmd[6] = len;
  97. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  98. usleep(1000);
  99. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  100. }
  101. void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
  102. {
  103. int len = write(_port, cmd, cmdLen);
  104. if (len < sizeof(cmd)) {
  105. log_error("Write cmd to LCM Failure. ");
  106. }
  107. }
  108. void CheckScreenModePress()
  109. {
  110. }
  111. void CheckMemberSelectPress()
  112. {
  113. }
  114. void CheckDonatePress()
  115. {
  116. }
  117. void CheckDonateSelectPress()
  118. {
  119. }
  120. void CheckIdlePress()
  121. {
  122. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  123. log_info("LCM Enter Authorize Page");
  124. }
  125. void CheckTouchPress(short id)
  126. {
  127. GetDeviceInfoStatus(id,1);
  128. if (_btn_press >= 1 && _btn_press_id == id) {
  129. ChangeDisplay2Value(id, 0);
  130. switch (id) {
  131. case _Touch_LeftGun:
  132. if(pSysInfo->CurGunSelected != LEFT_GUN_NUM) {
  133. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  134. log_info("LCM left Gun down...............................%x %x %x",
  135. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  136. if (pDcChargingInfo->SystemStatus == S_IDLE &&
  137. (pSysInfo->SystemPage <_PAGE_REFUND_SENSEING ||
  138. pSysInfo->SystemPage > _PAGE_REFUND_NONE ||
  139. pSysInfo->SystemPage != _PAGE_PAY_ETICKET_SUCCESS ||
  140. pSysInfo->SystemPage != _PAGE_PAY_MPAY_SUCCESS) ) {
  141. log_info("Reset LCM to IDLE");
  142. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  143. gettimeofday(&returnIdleTimer, NULL);
  144. }
  145. }
  146. pSysInfo->CurGunSelected = LEFT_GUN_NUM;
  147. break;
  148. case _Touch_RightGun:
  149. if (pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
  150. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  151. log_info("LCM right Gun down...............................%x %x %x",
  152. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  153. if (pDcChargingInfo->SystemStatus == S_IDLE &&
  154. (pSysInfo->SystemPage <_PAGE_REFUND_SENSEING ||
  155. pSysInfo->SystemPage > _PAGE_REFUND_NONE ||
  156. pSysInfo->SystemPage != _PAGE_PAY_ETICKET_SUCCESS ||
  157. pSysInfo->SystemPage != _PAGE_PAY_MPAY_SUCCESS) ) {
  158. log_info("Reset LCM to IDLE");
  159. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  160. gettimeofday(&returnIdleTimer, NULL);
  161. }
  162. }
  163. pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
  164. break;
  165. case _Touch_Return:
  166. CheckIdlePress();
  167. break;
  168. case _Touch_IDLE:
  169. CheckIdlePress();
  170. break;
  171. } // switch
  172. } //if (_btn_press >= 3)
  173. }
  174. void CheckLCMPressed()
  175. {
  176. pid_t Pid = fork();
  177. int i = 0;
  178. int index = 0;
  179. if ( Pid == 0 ) {
  180. while (1) {
  181. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  182. CheckTouchPress(_Touch_LeftGun);
  183. CheckTouchPress(_Touch_RightGun);
  184. switch (pSysInfo->SystemPage) {
  185. case _PAGE_IDLE:
  186. CheckTouchPress(_Touch_IDLE);
  187. break;
  188. case _PAGE_AUTHORIZE:
  189. CheckScreenModePress();
  190. break;
  191. case _PAGE_FUNCTION_SELECT:
  192. break;
  193. case _PAGE_MEMBER_SELECT:
  194. CheckMemberSelectPress();
  195. break;
  196. case _PAGE_DONATE:
  197. CheckDonatePress();
  198. break;
  199. case _PAGE_DONATE_SELECT:
  200. CheckDonateSelectPress();
  201. break;
  202. // ********************** Test *******************
  203. ///*
  204. case _PAGE_PRECHARGE:
  205. /*
  206. if ((i/100) %2 == 0)
  207. ChangeDisplay2Value(0x109A,i%100);
  208. else
  209. ChangeDisplay2Value(0x109A,100-(i%100));
  210. */
  211. ChangeDisplay2Value(0x103A,99);
  212. break;
  213. case _PAGE_CHARGING:
  214. pDcChargingInfo->PresentChargingPower = i;
  215. pDcChargingInfo->PresentChargedEnergy = i;
  216. pDcChargingInfo->RemainChargingDuration = i;
  217. pDcChargingInfo->EvBatterySoc = i/6;
  218. break;
  219. case _PAGE_COMPLETE:
  220. pDcChargingInfo->PresentChargedEnergy = i;
  221. pDcChargingInfo->ChargingFee = i;
  222. pDcChargingInfo->EvBatterySoc = i/6;
  223. pSysConfig->BillingData.isBilling = TRUE;
  224. ChangeCarBonValue(i/6);
  225. break;
  226. // ************************************************ */
  227. } // switch
  228. usleep(5000);
  229. ///*
  230. i++;
  231. if (i == 600 ) {
  232. index >= 8 ? index = 1 : index++;
  233. pSysInfo->SystemPage = index;
  234. i = 0;
  235. /*
  236. if (pSysInfo->SystemPage == _PAGE_PRECHARGE)
  237. gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
  238. */
  239. }//*/
  240. } //while
  241. } // if pid
  242. log_info("Create LCM fork:%d",Pid);
  243. }
  244. void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
  245. {
  246. read(_port, msg, readLen);
  247. // 5a : CMD_TITLE_1
  248. // a5 : CMD_TITLE_2
  249. // 5
  250. // 81 : CMD_WRITE
  251. // 3 : CMD_REGISTER
  252. // 2 : Data length
  253. // 0 : High byte
  254. // 1 : Low byte
  255. // printf("-------------------------------------------- \n");
  256. // printf("msg = %x \n", *msg); // A5
  257. // printf("msg = %x \n", *(msg + 1)); // 5A
  258. // printf("msg = %x \n", *(msg + 2)); // Len : [3] ~ [6] + Data Len
  259. // printf("msg = %x \n", *(msg + 3)); // cmd : 0x83
  260. // printf("msg = %x \n", *(msg + 4)); // addr : H
  261. // printf("msg = %x \n", *(msg + 5)); // addr : L
  262. // printf("msg = %x \n", *(msg + 6)); // Data Len
  263. //
  264. // printf("msg = %x \n", *(msg + 7));
  265. // printf("msg = %x \n", *(msg + 8));
  266. // printf("msg = %x \n", *(msg + 9));
  267. // printf("msg = %x \n", *(msg + 10));
  268. // printf("msg = %x \n", *(msg + 11));
  269. // printf("msg = %x \n", *(msg + 12));
  270. // printf("msg = %x \n", *(msg + 13));
  271. // printf("msg = %x \n", *(msg + 14));
  272. /*
  273. for(uint8_t i = 0 ; i<readLen+3; i++) {
  274. log_info("Read data[%d]:0x%x",i,msg[i]);
  275. }*/
  276. if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
  277. {
  278. if(*(msg + 3) == CMD_WRITE)
  279. {
  280. switch (*(msg + 4))
  281. {
  282. case CMD_REGISTER:
  283. {
  284. // 頁面
  285. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  286. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  287. _currentPage = *(msg + 7);
  288. log_info("Current Page:%d",_currentPage);
  289. // if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
  290. // printf("_currentPage = %d \n", _currentPage);
  291. }
  292. break;
  293. }
  294. }
  295. else if (*(msg + 3) == CMD_MULTI_READ)
  296. {
  297. short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
  298. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  299. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  300. if (key == 0x0014)
  301. _currentPage = *(msg + 8);
  302. if ( key >= _Touch_LeftGun && key <=_Touch_IDLE ) {
  303. _btn_press_id = key;
  304. _btn_press = *(msg + 8);
  305. }
  306. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  307. // {
  308. // case BUTTON_GUN_INDEX:
  309. // {
  310. // // 當前選的槍號
  311. // _curGunIndex = (*(msg + 8));
  312. // }
  313. // break;
  314. // }
  315. }
  316. }
  317. }
  318. void GetHrFormTimeString(char* time,char* hr)
  319. {
  320. //char tm[] = "2021-12-06 17:29:08:084";
  321. for(int i = 0 ; i < 2 ; i++) {
  322. hr[i] = time[i+11];
  323. }
  324. if( atoi(hr) == NULL ) {
  325. strcmp(hr,"");
  326. }
  327. }
  328. void GetMinFormTimeString(char* time,char* min)
  329. {
  330. //char tm[] = "2021-12-06 17:29:08:084";
  331. for(int i = 0 ; i < 2 ; i++) {
  332. min[i] = time[i+14];
  333. }
  334. if( atoi(min) == NULL || atoi(min) > 60) {
  335. strcmp(min,"");
  336. }
  337. }
  338. //================================================
  339. // Function
  340. //================================================
  341. void ChangeToOtherPage(short newPage)
  342. {
  343. uint8_t cmd[10];
  344. memset(cmd, 0x00, sizeof(cmd));
  345. uint8_t msg[9];
  346. memset(msg, 0x00, sizeof(msg));
  347. cmd[0] = CMD_TITLE_1;
  348. cmd[1] = CMD_TITLE_2;
  349. cmd[2] = 0x07;
  350. cmd[3] = 0x82;
  351. cmd[4] = 0x00;
  352. cmd[5] = 0x84;
  353. cmd[6] = 0x5A;
  354. cmd[7] = 0x01;
  355. cmd[8] = newPage >> 8;
  356. cmd[9] = newPage & 0x00FF;
  357. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  358. usleep(5000);
  359. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  360. }
  361. void ChangeBackLight(bool islight)
  362. {
  363. uint8_t value = 0x01;
  364. uint8_t msg[9];
  365. memset(msg, 0x00, sizeof(msg));
  366. // 0x00 ~ 0x40
  367. if (islight)
  368. {
  369. value = 0x20;
  370. }
  371. uint8_t cmd[7];
  372. memset(cmd, 0x00, sizeof(cmd));
  373. cmd[0] = CMD_TITLE_1;
  374. cmd[1] = CMD_TITLE_2;
  375. cmd[2] = 0x03;
  376. cmd[3] = CMD_READ;
  377. cmd[4] = CMD_BACKLIGHT;
  378. cmd[5] = value;
  379. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  380. usleep(10000);
  381. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  382. }
  383. void GetCurrentPage()
  384. {
  385. uint8_t cmd[7];
  386. memset(cmd, 0x00, sizeof(cmd));
  387. uint8_t msg[9];
  388. memset(msg, 0x00, sizeof(msg));
  389. cmd[0] = CMD_TITLE_1;
  390. cmd[1] = CMD_TITLE_2;
  391. cmd[2] = 0x04; // 底下總長度
  392. cmd[3] = 0x83;
  393. cmd[4] = 0x00;
  394. cmd[5] = 0x14;
  395. cmd[6] = 0x01;
  396. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  397. usleep(5000);
  398. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  399. }
  400. void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
  401. {
  402. uint8_t cmd[256];
  403. memset(cmd, 0x00, sizeof(cmd));
  404. uint8_t msg[9];
  405. memset(msg, 0x00, sizeof(msg));
  406. cmd[0] = CMD_TITLE_1;
  407. cmd[1] = CMD_TITLE_2;
  408. cmd[2] = 0x03 + len;
  409. cmd[3] = CMD_MULTI_WRITE;
  410. cmd[4] = address >> 8;
  411. cmd[5] = address & 0x00FF;
  412. for(uint8_t count = 0; count < len; count++)
  413. {
  414. cmd[6 + count] = *(data + count);
  415. }
  416. WriteCmdToLcm(cmd, cmd[2] + 3);
  417. usleep(10000);
  418. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  419. }
  420. void ChangeDisplay2Value(short address, short value)
  421. {
  422. uint8_t data[2];
  423. data[0] = value >> 8;
  424. data[1] = value & 0x00FF;
  425. //log_info("Addr:0x%x, value:%d",address,value);
  426. DisplayValueToLcm(address, data, sizeof(data));
  427. }
  428. //================================================
  429. // Warning process
  430. //================================================
  431. void string2ByteArray(uint8_t *input, uint8_t *output)
  432. {
  433. int loop;
  434. int i;
  435. loop = 0;
  436. i = 0;
  437. while (input[loop] != '\0') {
  438. output[i++] = input[loop++];
  439. }
  440. output[loop] = '\0';
  441. }
  442. void RefreshProgressAnimation(uint8_t progress_index)
  443. {
  444. if(_everyPageRollChange % 2) {
  445. progress_index+=1;
  446. }
  447. _everyPageRollChange++;
  448. }
  449. //================================================
  450. // Change current page
  451. //================================================
  452. void ChangeCurPage()
  453. {
  454. //log_info("cur = %d ,system = %d, lcm = %d ",_currentPage, pSysInfo->SystemPage, pSysInfo->PageIndex);
  455. struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  456. struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  457. pSysInfo->PageIndex = pSysInfo->SystemPage;
  458. if (_currentPage != pSysInfo->PageIndex) {
  459. switch (pSysInfo->SystemPage) {
  460. case _PAGE_AUTHORIZE:
  461. gettimeofday(&returnIdleTimer, NULL);
  462. break;
  463. case _PAGE_PLUGIN:
  464. break;
  465. case _PAGE_PRECHARGE:
  466. break;
  467. case _PAGE_CHARGING:
  468. break;
  469. case _PAGE_COMPLETE:
  470. break;
  471. }
  472. _currentPage = pSysInfo->PageIndex;
  473. log_info("Page:%d",pSysInfo->PageIndex);
  474. ChangeToOtherPage(pSysInfo->PageIndex);
  475. }
  476. }
  477. /*
  478. * View Page
  479. *
  480. */
  481. unsigned long GetTimeoutValue(struct timeval _sour_time)
  482. {
  483. struct timeval _end_time;
  484. gettimeofday(&_end_time, NULL);
  485. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  486. }
  487. void showGunWorkingType()
  488. {
  489. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
  490. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  491. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  492. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  493. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS1_ON);
  494. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  495. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  496. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS2_ON);
  497. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  498. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CHAdeMO_ON);
  499. }
  500. // Set Right Gun
  501. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  502. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  503. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  504. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS1_Off);
  505. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  506. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  507. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS2_Off);
  508. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  509. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMo_Off);
  510. }
  511. } else {
  512. // Left Gun
  513. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  514. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  515. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  516. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS1_Off);
  517. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  518. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  519. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS2_Off);
  520. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  521. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CHAdeMO_Off);
  522. }
  523. // Right Gun
  524. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  525. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  526. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  527. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS1_ON);
  528. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  529. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  530. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS2_ON);
  531. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  532. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMO_ON);
  533. }
  534. }
  535. }
  536. void ChangeQrCode_Idle(char *input)
  537. {
  538. int len = strlen(input);
  539. uint8_t cmd[len];
  540. int loop = 0;
  541. int i = 0;
  542. while (input[loop] != '\0') {
  543. cmd[i++] = input[loop++];
  544. }
  545. DisplayValueToLcm(_QRCode_Authorize, cmd, len + 1);
  546. }
  547. void ShowHomePage()
  548. {
  549. // Show QR Code
  550. if (pSysConfig->isQRCode) {
  551. if (pSysConfig->QRCodeMadeMode == NO) {
  552. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  553. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  554. } else {
  555. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  556. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  557. }
  558. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  559. }
  560. }
  561. /*
  562. void ChangeRemainTime(int sec)
  563. {
  564. int h, m, s;
  565. uint8_t cmd[10];
  566. uint8_t value[10];
  567. memset(cmd, 0x00, sizeof(cmd));
  568. // srand(time(NULL));
  569. // int min = 0;
  570. // int max = 65536;
  571. // sec = rand() % (max - min + 1) + min;
  572. h = (sec / 3600);
  573. m = (sec - (3600 * h)) / 60;
  574. s = (sec - (3600 * h) - (m * 60));
  575. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  576. string2ByteArray(value, cmd);
  577. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  578. }
  579. */
  580. void ChangeChargingPowerValue(float pow)
  581. {
  582. uint8_t cmd[10];
  583. uint8_t value[10];
  584. memset(cmd, 0x00, sizeof(cmd));
  585. sprintf((char *) value, "%.1f",pow);
  586. string2ByteArray(value, cmd);
  587. DisplayValueToLcm(_Text_Power, cmd, sizeof(cmd));
  588. }
  589. void ChangeChargingFeeValue(float fee)
  590. {
  591. uint8_t cmd[10];
  592. uint8_t value[10];
  593. memset(cmd, 0x00, sizeof(cmd));
  594. sprintf((char *) value, "%d", (int)fee);
  595. string2ByteArray(value, cmd);
  596. DisplayValueToLcm(_Text_Money, cmd, sizeof(cmd));
  597. }
  598. void ChangeCarBonValue(float fee)
  599. {
  600. uint8_t cmd[10];
  601. uint8_t value[10];
  602. memset(cmd, 0x00, sizeof(cmd));
  603. sprintf((char *) value, "%d", (int)fee);
  604. string2ByteArray(value, cmd);
  605. DisplayValueToLcm(_Text_Carbon, cmd, sizeof(cmd));
  606. }
  607. void ChangeChargingEnergyValue(float energy)
  608. {
  609. uint8_t cmd[10];
  610. uint8_t value[10];
  611. memset(cmd, 0x00, sizeof(cmd));
  612. if (energy >= 0.05) {
  613. energy -= 0.05;
  614. }
  615. sprintf((char *) value, "%d", (int)energy);
  616. string2ByteArray(value, cmd);
  617. DisplayValueToLcm(_Text_Energy, cmd, sizeof(cmd));
  618. }
  619. uint8_t _battery_display_count = 0;
  620. void ChangeBattMapAndValue(int soc)
  621. {
  622. int i = soc*(36/100);
  623. uint8_t cmd[5];
  624. uint8_t value[5];
  625. _battery_display_count++;
  626. if (_battery_display_count == 3 ) {
  627. if (_battery_display_ani == 0)
  628. _battery_display_ani= TRUE;
  629. else
  630. _battery_display_ani= FALSE ;
  631. _battery_display_count = 0;
  632. }
  633. if (i==36)
  634. ChangeDisplay2Value(_Battery_Circle,_ICON_Battery_35);
  635. else {
  636. if (_battery_display_ani) {
  637. ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+i);
  638. } else {
  639. ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+i+1);
  640. }
  641. }
  642. memset(cmd, 0x00, sizeof(cmd));
  643. memset(value, 0x00, sizeof(value));
  644. sprintf((char *)value, "%d", soc);
  645. string2ByteArray(value, cmd);
  646. DisplayValueToLcm(_Text_BatterySoc, cmd, sizeof(cmd));
  647. }
  648. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  649. {
  650. struct timeval _end_time;
  651. gettimeofday(&_end_time, NULL);
  652. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  653. }
  654. void ChangeTimeValue(uint8_t time)
  655. {
  656. uint8_t cmd[2];
  657. uint8_t value[2];
  658. memset(cmd, 0x00, sizeof(cmd));
  659. sprintf((char *) value, "%d", time);
  660. string2ByteArray(value, cmd);
  661. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  662. }
  663. void CabinetChangeLCMProcess()
  664. {
  665. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  666. if ( (pDcChargingInfo->ChangeLcmPage == _CHANGE_REFUNDAMOUNT ||
  667. pDcChargingInfo->ChangeLcmPage == _CHANGE_PREPAYMENTINFO ||
  668. pDcChargingInfo->ChangeLcmPage == _CHANGE_PAYMENT_FAIL) &&
  669. ShmDcCommonData->_ChangeLCMRequest != TRUE) {
  670. return;
  671. }
  672. switch(pDcChargingInfo->ChangeLcmPage) {
  673. case _CHANGE_REMOTESTART:
  674. break;
  675. case _CHANGE_REFUNDING:
  676. pSysInfo->SystemPage = _PAGE_REFUNDING;
  677. break;
  678. case _CHANGE_REFUNDAMOUNT:
  679. pSysInfo->SystemPage = _PAGE_REFUND_COMPLETE;
  680. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  681. break;
  682. case _CHANGE_NOREFUND:
  683. pSysInfo->SystemPage = _PAGE_REFUND_NONE;
  684. break;
  685. case _CHANGE_PREPAYMENTINFO:
  686. pSysInfo->SystemPage = _PAGE_PAY_ETICKET_SUCCESS;
  687. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  688. break;
  689. case _CHANGE_PAYMENT_OK:
  690. pSysInfo->SystemPage = _PAGE_PAY_MPAY_SUCCESS;
  691. break;
  692. case _CHANGE_PAYMENT_FAIL:
  693. pSysInfo->SystemPage = _PAGE_PAY_FAIL;
  694. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  695. break;
  696. }
  697. }
  698. void ProcessPageInfo()
  699. {
  700. // Show Gun Working and Type
  701. float _current;
  702. uint8_t precharg_time;
  703. showGunWorkingType();
  704. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  705. if (pSysInfo->CurGunSelected == i) {
  706. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  707. CabinetChangeLCMProcess();
  708. switch (pSysInfo->SystemPage) {
  709. case _PAGE_AUTHORIZE:
  710. ShowHomePage();
  711. if (GetTimeoutValue(returnIdleTimer) /uSEC_VAL >= RETURNIDLE_Timeout ) {
  712. pSysInfo->SystemPage = _PAGE_IDLE;
  713. gettimeofday(&returnIdleTimer, NULL);
  714. }
  715. break;
  716. case _PAGE_PLUGIN:
  717. _Text_Running_Count = 0;
  718. break;
  719. case _PAGE_PRECHARGE:
  720. ChangeDisplay2Value(_PrepareBar,_Text_Running_Count);
  721. _Text_Running_Count >= 99 ? _Text_Running_Count = 86 : _Text_Running_Count++;
  722. break;
  723. case _PAGE_CHARGING:
  724. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  725. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  726. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  727. } else {
  728. ChangeChargingPowerValue(0);
  729. }
  730. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  731. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  732. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  733. } else {
  734. ChangeChargingEnergyValue(0);
  735. }
  736. if (pSysConfig->BillingData.isBilling &&
  737. pDcChargingInfo->ChargingFee >= 0) {
  738. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  739. }
  740. if (pDcChargingInfo->RemainChargingDuration >= 0 &&
  741. pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
  742. ChangeTimeValue(pDcChargingInfo->RemainChargingDuration);
  743. } else {
  744. ChangeTimeValue(0);
  745. }
  746. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  747. break;
  748. case _PAGE_COMPLETE:
  749. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  750. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  751. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  752. } else {
  753. ChangeChargingEnergyValue(0);
  754. }
  755. if (pSysConfig->BillingData.isBilling &&
  756. pDcChargingInfo->ChargingFee >= 0) {
  757. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  758. }
  759. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  760. break;
  761. case _PAGE_REFUND_SENSEING:
  762. break;
  763. case _PAGE_PLUGOUT:
  764. break;
  765. }
  766. }
  767. }
  768. }
  769. void ChangeWarningFunc()
  770. {
  771. uint8_t cmd[7] = {0};
  772. uint8_t i = 0;
  773. //uint8_t j = 0;
  774. //log_info("ChangeWarningFunc ");
  775. // 最多一次五筆
  776. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  777. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  778. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  779. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  780. //log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  781. memset(cmd, 0x00, sizeof(cmd));
  782. if ((i) >= 5) {
  783. break;
  784. }
  785. //error code
  786. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  787. DisplayValueToLcm(0x3020 + ((i) * 6), cmd, sizeof(cmd));
  788. //警告標示
  789. memset(cmd, 0x00, sizeof(cmd));
  790. cmd[0] = 0x00;
  791. cmd[1] = 85;
  792. DisplayValueToLcm(0x1090 + ((i) * 2), cmd, 2);
  793. }
  794. memset(cmd, 0x00, sizeof(cmd));
  795. for (; i < 5; i++) {
  796. DisplayValueToLcm(0x3020 + ((i) * 6), cmd, sizeof(cmd));
  797. DisplayValueToLcm(0x1090 + ((i) * 2), cmd, 2);
  798. }
  799. }
  800. void ShowCabientVersionDefaultText()
  801. {
  802. char value[16];
  803. memset(value, 0x00, sizeof(value));
  804. sprintf((char *)value,"%s","Cabient:");
  805. DisplayValueToLcm(_Version_Cabient_Name_Text, (uint8_t *)value, sizeof(value));
  806. sprintf((char *)value,"%s","BootLoader:");
  807. DisplayValueToLcm(_Version_Cabient_BootLoader_Text, (uint8_t *)value, sizeof(value));
  808. sprintf((char *)value,"%s","Kernel Fw:");
  809. DisplayValueToLcm(_Version_Cabient_Kernel_Text, (uint8_t *)value, sizeof(value));
  810. sprintf((char *)value,"%s","CSU Fw:");
  811. DisplayValueToLcm(_Version_Cabient_CSU_Text, (uint8_t *)value, sizeof(value));
  812. sprintf((char *)value,"%s","Priamry Fw:");
  813. DisplayValueToLcm(_Version_Cabient_Priamry_Text, (uint8_t *)value, sizeof(value));
  814. sprintf((char *)value,"%s","Relay(0) Fw:");
  815. DisplayValueToLcm(_Version_Cabient_Relay0_Text, (uint8_t *)value, sizeof(value));
  816. sprintf((char *)value,"%s","Relay(1) Fw:");
  817. DisplayValueToLcm(_Version_Cabient_Relay1_Text, (uint8_t *)value, sizeof(value));
  818. sprintf((char *)value,"%s","Fan Fw:");
  819. DisplayValueToLcm(_Version_Cabient_Fan_Text, (uint8_t *)value, sizeof(value));
  820. sprintf((char *)value,"%s","IP Addr:");
  821. DisplayValueToLcm(_Version_Cabient_IPAddr_Text, (uint8_t *)value, sizeof(value));
  822. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number <= 12) {
  823. sprintf((char *)value,"%s","Primary");
  824. DisplayValueToLcm(_Version_Cabient_Primary_Text, (uint8_t *)value, sizeof(value));
  825. sprintf((char *)value,"%s","Secondary");
  826. DisplayValueToLcm(_Version_Cabient_Secondary_Text, (uint8_t *)value, sizeof(value));
  827. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  828. sprintf((char *)value,"PSU(%d):",i+1);
  829. DisplayValueToLcm(_Version_Cabient_PSU1_Text+i*0x10, (uint8_t *)value, sizeof(value));
  830. }
  831. }
  832. }
  833. void ShowDispenserVersionDefautlText()
  834. {
  835. char value[16];
  836. memset(value, 0x00, sizeof(value));
  837. sprintf((char *)value,"%s","Dispenser:");
  838. DisplayValueToLcm(_Version_Dispenser_Name_Text, (uint8_t *)value, sizeof(value));
  839. sprintf((char *)value,"%s","BootLoader:");
  840. DisplayValueToLcm(_Version_Dispenser_BootLoader_Text, (uint8_t *)value, sizeof(value));
  841. sprintf((char *)value,"%s","Kernel Fw:");
  842. DisplayValueToLcm(_Version_Dispenser_Kernel_Text, (uint8_t *)value, sizeof(value));
  843. sprintf((char *)value,"%s","CSU Fw:");
  844. DisplayValueToLcm(_Version_Dispenser_CSU_Text, (uint8_t *)value, sizeof(value));
  845. sprintf((char *)value,"%s","Relay Fw:");
  846. DisplayValueToLcm(_Version_Dispenser_Relay_Text, (uint8_t *)value, sizeof(value));
  847. sprintf((char *)value,"%s","Fan Fw:");
  848. DisplayValueToLcm(_Version_Dispenser_Fan_Text, (uint8_t *)value, sizeof(value));
  849. sprintf((char *)value,"%s","Prim Fw:");
  850. DisplayValueToLcm(_Version_Dispenser_Priamry_Text, (uint8_t *)value, sizeof(value));
  851. sprintf((char *)value,"%s","LCM Hw:");
  852. DisplayValueToLcm(_Version_Dispenser_LCM_Text, (uint8_t *)value, sizeof(value));
  853. sprintf((char *)value,"%s","LED Fw:");
  854. DisplayValueToLcm(_Version_Dispenser_LED_Text, (uint8_t *)value, sizeof(value));
  855. sprintf((char *)value,"%s","Connector(0):");
  856. DisplayValueToLcm(_Version_Dispenser_Connector0_Text, (uint8_t *)value, sizeof(value));
  857. sprintf((char *)value,"%s","Connector(1):");
  858. DisplayValueToLcm(_Version_Dispenser_Connector1_Text, (uint8_t *)value, sizeof(value));
  859. sprintf((char *)value,"%s","IP Addr:");
  860. DisplayValueToLcm(_Version_Dispenser_IPAddr_Text, (uint8_t *)value, sizeof(value));
  861. }
  862. void ShowCabientVersion()
  863. {
  864. char value[16];
  865. memset(value, 0x00, sizeof(value));
  866. sprintf((char *)value,"%s",ShmDcCommonData->CabinetModelName);
  867. DisplayValueToLcm(_Version_Cabient_Model_value, (uint8_t *)value, sizeof(value));
  868. sprintf((char *)value,"%s",ShmDcCommonData->CabinetBoolLoaderVersion);
  869. DisplayValueToLcm(_Version_Cabient_BootLoader_value, (uint8_t *)value, sizeof(value));
  870. sprintf((char *)value,"%s",ShmDcCommonData->CabinetKernelVersion);
  871. DisplayValueToLcm(_Version_Cabient_Kernel_value, (uint8_t *)value, sizeof(value));
  872. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRFSystemVersion);
  873. DisplayValueToLcm(_Version_Cabient_CSU_value, (uint8_t *)value, sizeof(value));
  874. sprintf((char *)value,"%s",ShmDcCommonData->CabinetPrimaryVersion);
  875. DisplayValueToLcm(_Version_Cabient_Priamry_value, (uint8_t *)value, sizeof(value));
  876. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay0Version);
  877. DisplayValueToLcm(_Version_Cabient_Relay0_value, (uint8_t *)value, sizeof(value));
  878. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay1Version);
  879. DisplayValueToLcm(_Version_Cabient_Relay1_value, (uint8_t *)value, sizeof(value));
  880. sprintf((char *)value,"%s",ShmDcCommonData->CabinetFanVersion);
  881. DisplayValueToLcm(_Version_Cabient_Fan_value, (uint8_t *)value, sizeof(value));
  882. sprintf((char *)value,"%s",ShmDcCommonData->CabinetIPAddr);
  883. DisplayValueToLcm(_Version_Cabient_IPAddr_value, (uint8_t *)value, sizeof(value));
  884. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number < 12) {
  885. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  886. if (i>=6) {
  887. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].DCVersion);
  888. DisplayValueToLcm(_Version_Cabient_PSU_Prim7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  889. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].FPCVersion);
  890. DisplayValueToLcm(_Version_Cabient_PSU_Sec7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  891. continue;
  892. }
  893. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].DCVersion);
  894. DisplayValueToLcm(_Version_Cabient_PSU_Prim1_value+i*0x10, (uint8_t *)value, sizeof(value));
  895. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].FPCVersion);
  896. DisplayValueToLcm(_Version_Cabient_PSU_Sec1_value+i*0x10, (uint8_t *)value, sizeof(value));
  897. }
  898. }
  899. }
  900. void ShowDispenserVersion()
  901. {
  902. char value[32];
  903. memset(value, 0x00, sizeof(value));
  904. sprintf((char *)value,"%s",pSysConfig->ModelName);
  905. DisplayValueToLcm(_Version_Dispenser_Model_value, (uint8_t *)value, sizeof(value));
  906. sprintf((char *)value,"%s",pSysInfo->CsuBootLoadFwRev);
  907. DisplayValueToLcm(_Version_Dispenser_BootLoader_value, (uint8_t *)value, sizeof(value));
  908. sprintf((char *)value,"%s",pSysInfo->CsuKernelFwRev);
  909. DisplayValueToLcm(_Version_Dispenser_Kernel_value, (uint8_t *)value, sizeof(value));
  910. sprintf((char *)value,"%s",pSysInfo->CsuRootFsFwRev);
  911. DisplayValueToLcm(_Version_Dispenser_CSU_value, (uint8_t *)value, sizeof(value));
  912. sprintf((char *)value,"%s",pSysInfo->RelayModuleFwRev);
  913. DisplayValueToLcm(_Version_Dispenser_Relay_value, (uint8_t *)value, sizeof(value));
  914. sprintf((char *)value,"%s",pSysInfo->FanModuleFwRev);
  915. DisplayValueToLcm(_Version_Dispenser_Fan_value, (uint8_t *)value, sizeof(value));
  916. sprintf((char *)value,"%s",pSysInfo->CsuPrimFwRev);
  917. DisplayValueToLcm(_Version_Dispenser_Priamry_value, (uint8_t *)value, sizeof(value));
  918. sprintf((char *)value,"%s",pSysInfo->LcmHwRev);
  919. DisplayValueToLcm(_Version_Dispenser_LCM_value, (uint8_t *)value, sizeof(value));
  920. sprintf((char *)value,"%s",pSysInfo->LedModuleFwRev);
  921. DisplayValueToLcm(_Version_Dispenser_LED_value, (uint8_t *)value, sizeof(value));
  922. sprintf((char *)value,"%s",pSysInfo->Connector1FwRev);
  923. DisplayValueToLcm(_Version_Dispenser_Connector0_value, (uint8_t *)value, sizeof(value));
  924. sprintf((char *)value,"%s",pSysInfo->Connector2FwRev);
  925. DisplayValueToLcm(_Version_Dispenser_Connector1_value, (uint8_t *)value, sizeof(value));
  926. sprintf((char *)value,"%s",pSysConfig->Eth0Interface.EthIpAddress);
  927. DisplayValueToLcm(_Version_Dispenser_IPAddr_value, (uint8_t *)value, sizeof(value));
  928. }
  929. void InformationShow()
  930. {
  931. is_show = true;
  932. if (_showInformIndex == 0 ) {
  933. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  934. } else {
  935. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  936. ShowDispenserVersion();
  937. }
  938. }
  939. void DefautLayOut()
  940. {
  941. for (int i = 0 ; i <= 0x72 ; i+=2 ) {
  942. ChangeDisplay2Value(0x1000+i,1);
  943. if (i == 0x38)
  944. ChangeDisplay2Value(0x1000+i,85);
  945. else if (i == 0x36)
  946. ChangeDisplay2Value(0x1000+i,75);
  947. else if (i == 0x3A)
  948. ChangeDisplay2Value(0x1000+i,99);
  949. }
  950. ChangeDisplay2Value(0x5000,1);
  951. }
  952. int main(void)
  953. {
  954. bool defaulttext = false;
  955. if (CreateAllCsuShareMemory() == FAIL) {
  956. log_error("create share memory error");
  957. return FAIL;
  958. }
  959. MappingGunChargingInfo("LCM Control Task");
  960. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  961. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  962. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  963. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  964. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  965. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  966. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  967. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  968. struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  969. struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  970. _port = CreateCommunicationLcmPort();
  971. uint8_t changeWarningPriority = 0;
  972. uint8_t curWarningCount = 255;
  973. ChangeBackLight(true);
  974. _totalCount = pSysConfig->TotalConnectorCount;
  975. _everyPageRollChange = 0;
  976. //Initialization();
  977. //printf("_LCM_COMPLETE ");
  978. //ChangeToOtherPage(_LCM_COMPLETE);
  979. DefautLayOut();
  980. //return 0;
  981. //uint8_t index = 1;
  982. ShmDcCommonData->PSU_Number = 12;
  983. CheckLCMPressed();
  984. while (_port != -1) {
  985. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  986. GetCurrentPage();
  987. sleep(1);
  988. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  989. } else {
  990. UpdateLcmFunction(ShmDcCommonData,_port);
  991. ///*
  992. // Warning 處理
  993. if (curWarningCount != pSysWarning->WarningCount) {
  994. changeWarningPriority = 0;
  995. pSysWarning->PageIndex = 0;
  996. curWarningCount = pSysWarning->WarningCount;
  997. ChangeWarningFunc();
  998. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  999. // 當有兩頁 Warning 則每隔三秒改變一次
  1000. if (pSysWarning->PageIndex == 0) {
  1001. pSysWarning->PageIndex = 1;
  1002. } else {
  1003. pSysWarning->PageIndex = 0;
  1004. }
  1005. ChangeWarningFunc();
  1006. }
  1007. /*
  1008. // Show Default Text
  1009. if (!defaulttext) {
  1010. ShowCabientVersionDefaultText();
  1011. ShowDispenserVersionDefautlText();
  1012. defaulttext = true;
  1013. }
  1014. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1015. // 頁面資訊處理
  1016. ProcessPageInfo();
  1017. // 換頁處理
  1018. //GetCurrentPage(); //DS60-120 add
  1019. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1020. InformationShow();
  1021. ChangeToOtherPage(pSysInfo->PageIndex);
  1022. usleep(100000);
  1023. continue;
  1024. } else {
  1025. if (is_show)
  1026. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1027. is_show = false;
  1028. }
  1029. GetCurrentPage(); //DS60-120 add
  1030. ChangeCurPage();
  1031. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1032. usleep(10000); //*/
  1033. ///*
  1034. ProcessPageInfo();
  1035. GetCurrentPage();
  1036. ChangeCurPage();
  1037. usleep(10000);
  1038. //*/
  1039. }
  1040. } //while
  1041. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1042. log_info("Close LCM Uart Port");
  1043. CloseCommunicationLcmPort();
  1044. return FAIL;
  1045. }