Module_LcmControl.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 = 86;
  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. break;
  212. case _PAGE_CHARGING:
  213. pDcChargingInfo->PresentChargingPower = i;
  214. pDcChargingInfo->PresentChargedEnergy = i/6;
  215. pDcChargingInfo->RemainChargingDuration = i;
  216. pDcChargingInfo->EvBatterySoc = i/6;
  217. break;
  218. case _PAGE_COMPLETE:
  219. pDcChargingInfo->PresentChargedEnergy = i;
  220. pDcChargingInfo->ChargingFee = i;
  221. pDcChargingInfo->EvBatterySoc = i/6;
  222. pSysConfig->BillingData.isBilling = TRUE;
  223. ChangeCarBonValue(i);
  224. pSysConfig->isQRCode = 1;
  225. break;
  226. case _PAGE_PLUGOUT:
  227. pSysConfig->isQRCode = 1;
  228. CheckTouchPress(_Touch_Return);
  229. break;
  230. // ************************************************ */
  231. } // switch
  232. usleep(5000);
  233. ///*
  234. i++;
  235. if (i == 600 ) {
  236. index >= 8 ? index = 1 : index++;
  237. pSysInfo->SystemPage = index;
  238. i = 0;
  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()
  443. {
  444. _everyPageRollChange >= 10 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  445. }
  446. //================================================
  447. // Change current page
  448. //================================================
  449. void ChangeCurPage()
  450. {
  451. //log_info("cur = %d ,system = %d, lcm = %d ",_currentPage, pSysInfo->SystemPage, pSysInfo->PageIndex);
  452. struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  453. struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  454. pSysInfo->PageIndex = pSysInfo->SystemPage;
  455. if (_currentPage != pSysInfo->PageIndex) {
  456. switch (pSysInfo->SystemPage) {
  457. case _PAGE_AUTHORIZE:
  458. gettimeofday(&returnIdleTimer, NULL);
  459. break;
  460. case _PAGE_PLUGIN:
  461. break;
  462. case _PAGE_PRECHARGE:
  463. break;
  464. case _PAGE_CHARGING:
  465. break;
  466. case _PAGE_COMPLETE:
  467. break;
  468. }
  469. _currentPage = pSysInfo->PageIndex;
  470. log_info("Page:%d",pSysInfo->PageIndex);
  471. ChangeToOtherPage(pSysInfo->PageIndex);
  472. }
  473. }
  474. /*
  475. * View Page
  476. *
  477. */
  478. unsigned long GetTimeoutValue(struct timeval _sour_time)
  479. {
  480. struct timeval _end_time;
  481. gettimeofday(&_end_time, NULL);
  482. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  483. }
  484. void showGunWorkingType()
  485. {
  486. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
  487. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  488. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  489. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  490. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS1_ON);
  491. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  492. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  493. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS2_ON);
  494. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  495. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CHAdeMO_ON);
  496. }
  497. // Set Right Gun
  498. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  499. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  500. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  501. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS1_Off);
  502. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  503. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  504. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS2_Off);
  505. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  506. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMo_Off);
  507. }
  508. } else {
  509. // Left Gun
  510. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  511. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  512. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  513. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS1_Off);
  514. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  515. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  516. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CCS2_Off);
  517. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  518. ChangeDisplay2Value(_LeftGun_status,_ICON_Left_CHAdeMO_Off);
  519. }
  520. // Right Gun
  521. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  522. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  523. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  524. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS1_ON);
  525. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  526. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  527. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CCS2_ON);
  528. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  529. ChangeDisplay2Value(_RightGun_status,_ICON_Right_CHAdeMO_ON);
  530. }
  531. }
  532. }
  533. void ChangeQrCode_Idle(char *input)
  534. {
  535. int len = strlen(input);
  536. uint8_t cmd[len];
  537. int loop = 0;
  538. int i = 0;
  539. while (input[loop] != '\0') {
  540. cmd[i++] = input[loop++];
  541. }
  542. DisplayValueToLcm(_QRCode_Authorize, cmd, len + 1);
  543. }
  544. void ShowHomePage()
  545. {
  546. // Show QR Code
  547. if (pSysConfig->isQRCode) {
  548. if (pSysConfig->QRCodeMadeMode == NO) {
  549. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  550. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  551. } else {
  552. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  553. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  554. }
  555. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  556. }
  557. }
  558. /*
  559. void ChangeRemainTime(int sec)
  560. {
  561. int h, m, s;
  562. uint8_t cmd[10];
  563. uint8_t value[10];
  564. memset(cmd, 0x00, sizeof(cmd));
  565. // srand(time(NULL));
  566. // int min = 0;
  567. // int max = 65536;
  568. // sec = rand() % (max - min + 1) + min;
  569. h = (sec / 3600);
  570. m = (sec - (3600 * h)) / 60;
  571. s = (sec - (3600 * h) - (m * 60));
  572. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  573. string2ByteArray(value, cmd);
  574. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  575. }
  576. */
  577. void ChangeChargingPowerValue(float pow)
  578. {
  579. uint8_t cmd[10];
  580. uint8_t value[10];
  581. memset(cmd, 0x00, sizeof(cmd));
  582. sprintf((char *) value, "%.1fkW",pow);
  583. string2ByteArray(value, cmd);
  584. DisplayValueToLcm(_Text_Power, cmd, sizeof(cmd));
  585. }
  586. void ChangeChargingFeeValue(float fee)
  587. {
  588. uint8_t cmd[10];
  589. uint8_t value[10];
  590. memset(cmd, 0x00, sizeof(cmd));
  591. sprintf((char *) value, "%d", (int)fee);
  592. string2ByteArray(value, cmd);
  593. DisplayValueToLcm(_Text_Money, cmd, sizeof(cmd));
  594. }
  595. void ChangeCarBonValue(int data)
  596. {
  597. uint8_t cmd[10];
  598. uint8_t value[10];
  599. memset(cmd, 0x00, sizeof(cmd));
  600. sprintf((char *) value, "-%d", data);
  601. string2ByteArray(value, cmd);
  602. DisplayValueToLcm(_Text_Carbon, cmd, sizeof(cmd));
  603. }
  604. void ChangeChargingEnergyValue(float energy)
  605. {
  606. uint8_t cmd[10];
  607. uint8_t value[10];
  608. memset(cmd, 0x00, sizeof(cmd));
  609. if (energy >= 0.05) {
  610. energy -= 0.05;
  611. }
  612. if (energy < 0 )
  613. ChangeDisplay2Value(_EnergyBar,_ICON_Empty);
  614. else if (energy > 100)
  615. ChangeDisplay2Value(_EnergyBar,_ICON_Bar_10);
  616. else
  617. ChangeDisplay2Value(_EnergyBar,((int)energy/10)+_ICON_Bar_1);
  618. sprintf((char *) value, "%d", (int)energy);
  619. string2ByteArray(value, cmd);
  620. DisplayValueToLcm(_Text_Energy, cmd, sizeof(cmd));
  621. }
  622. uint8_t _battery_display_count = 0;
  623. void ChangeBattMapAndValue(int soc)
  624. {
  625. int i = (soc*36)/100;
  626. uint8_t cmd[5];
  627. uint8_t value[5];
  628. _battery_display_count++;
  629. if (_battery_display_count == 3 ) {
  630. if (_battery_display_ani == 0)
  631. _battery_display_ani= TRUE;
  632. else
  633. _battery_display_ani= FALSE ;
  634. _battery_display_count = 0;
  635. }
  636. if (i==36)
  637. ChangeDisplay2Value(_Battery_Circle,_ICON_Battery_35);
  638. else {
  639. if (_battery_display_ani) {
  640. ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+(int)i);
  641. } else {
  642. ChangeDisplay2Value(_Battery_Circle, _ICON_Battery_0+(int)i+1);
  643. }
  644. }
  645. memset(cmd, 0x00, sizeof(cmd));
  646. memset(value, 0x00, sizeof(value));
  647. sprintf((char *)value, "%d%%", soc);
  648. string2ByteArray(value, cmd);
  649. DisplayValueToLcm(_Text_BatterySoc, cmd, sizeof(cmd));
  650. }
  651. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  652. {
  653. struct timeval _end_time;
  654. gettimeofday(&_end_time, NULL);
  655. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  656. }
  657. void ChangeTimeValue(uint8_t time)
  658. {
  659. uint8_t cmd[2];
  660. uint8_t value[2];
  661. memset(cmd, 0x00, sizeof(cmd));
  662. sprintf((char *) value, "%d", time);
  663. string2ByteArray(value, cmd);
  664. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  665. }
  666. void CabinetChangeLCMProcess()
  667. {
  668. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  669. if ( (pDcChargingInfo->ChangeLcmPage == _CHANGE_REFUNDAMOUNT ||
  670. pDcChargingInfo->ChangeLcmPage == _CHANGE_PREPAYMENTINFO ||
  671. pDcChargingInfo->ChangeLcmPage == _CHANGE_PAYMENT_FAIL) &&
  672. ShmDcCommonData->_ChangeLCMRequest != TRUE) {
  673. return;
  674. }
  675. switch(pDcChargingInfo->ChangeLcmPage) {
  676. case _CHANGE_REMOTESTART:
  677. break;
  678. case _CHANGE_REFUNDING:
  679. pSysInfo->SystemPage = _PAGE_REFUNDING;
  680. break;
  681. case _CHANGE_REFUNDAMOUNT:
  682. pSysInfo->SystemPage = _PAGE_REFUND_COMPLETE;
  683. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  684. break;
  685. case _CHANGE_NOREFUND:
  686. pSysInfo->SystemPage = _PAGE_REFUND_NONE;
  687. break;
  688. case _CHANGE_PREPAYMENTINFO:
  689. pSysInfo->SystemPage = _PAGE_PAY_ETICKET_SUCCESS;
  690. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  691. break;
  692. case _CHANGE_PAYMENT_OK:
  693. pSysInfo->SystemPage = _PAGE_PAY_MPAY_SUCCESS;
  694. break;
  695. case _CHANGE_PAYMENT_FAIL:
  696. pSysInfo->SystemPage = _PAGE_PAY_FAIL;
  697. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  698. break;
  699. }
  700. }
  701. void ProcessPageInfo()
  702. {
  703. // Show Gun Working and Type
  704. float _current;
  705. uint8_t precharg_time;
  706. showGunWorkingType();
  707. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  708. if (pSysInfo->CurGunSelected == i) {
  709. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  710. CabinetChangeLCMProcess();
  711. switch (pSysInfo->SystemPage) {
  712. case _PAGE_AUTHORIZE:
  713. ShowHomePage();
  714. if (GetTimeoutValue(returnIdleTimer) /uSEC_VAL >= RETURNIDLE_Timeout ) {
  715. pSysInfo->SystemPage = _PAGE_IDLE;
  716. gettimeofday(&returnIdleTimer, NULL);
  717. }
  718. break;
  719. case _PAGE_PLUGIN:
  720. _Text_Running_Count = 86;
  721. _everyPageRollChange = 0;
  722. break;
  723. case _PAGE_PRECHARGE:
  724. RefreshProgressAnimation();
  725. if (_everyPageRollChange == 0) {
  726. ChangeDisplay2Value(_PrepareBar,_Text_Running_Count);
  727. _Text_Running_Count >= 99 ? _Text_Running_Count = 86 : _Text_Running_Count++;
  728. }
  729. break;
  730. case _PAGE_CHARGING:
  731. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  732. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  733. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  734. } else {
  735. ChangeChargingPowerValue(0);
  736. }
  737. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  738. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  739. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  740. } else {
  741. ChangeChargingEnergyValue(0);
  742. }
  743. if (pSysConfig->BillingData.isBilling &&
  744. pDcChargingInfo->ChargingFee >= 0) {
  745. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  746. }
  747. if (pDcChargingInfo->RemainChargingDuration >= 0 &&
  748. pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
  749. ChangeTimeValue(pDcChargingInfo->RemainChargingDuration);
  750. } else {
  751. ChangeTimeValue(0);
  752. }
  753. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  754. break;
  755. case _PAGE_COMPLETE:
  756. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  757. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  758. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  759. } else {
  760. ChangeChargingEnergyValue(0);
  761. }
  762. if (pSysConfig->BillingData.isBilling &&
  763. pDcChargingInfo->ChargingFee >= 0) {
  764. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  765. }
  766. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  767. if (pSysConfig->isQRCode) {
  768. if (pSysConfig->QRCodeMadeMode == NO) {
  769. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  770. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  771. } else {
  772. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  773. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  774. }
  775. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  776. }
  777. break;
  778. case _PAGE_REFUND_SENSEING:
  779. break;
  780. case _PAGE_PLUGOUT:
  781. if (pSysConfig->isQRCode) {
  782. if (pSysConfig->QRCodeMadeMode == NO) {
  783. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  784. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  785. } else {
  786. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  787. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  788. }
  789. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  790. }
  791. break;
  792. }
  793. }
  794. }
  795. }
  796. void ChangeWarningFunc()
  797. {
  798. uint8_t cmd[7] = {0};
  799. uint8_t i = 0;
  800. //uint8_t j = 0;
  801. //log_info("ChangeWarningFunc ");
  802. // 最多一次五筆
  803. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  804. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  805. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  806. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  807. //log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  808. memset(cmd, 0x00, sizeof(cmd));
  809. if ((i) >= 5) {
  810. break;
  811. }
  812. //error code
  813. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  814. DisplayValueToLcm(0x3020 + ((i) * 6), cmd, sizeof(cmd));
  815. //警告標示
  816. memset(cmd, 0x00, sizeof(cmd));
  817. cmd[0] = 0x00;
  818. cmd[1] = 85;
  819. DisplayValueToLcm(0x1090 + ((i) * 2), cmd, 2);
  820. }
  821. memset(cmd, 0x00, sizeof(cmd));
  822. for (; i < 5; i++) {
  823. DisplayValueToLcm(0x3020 + ((i) * 6), cmd, sizeof(cmd));
  824. DisplayValueToLcm(0x1090 + ((i) * 2), cmd, 2);
  825. }
  826. }
  827. void ShowCabientVersionDefaultText()
  828. {
  829. char value[16];
  830. memset(value, 0x00, sizeof(value));
  831. sprintf((char *)value,"%s","Cabient:");
  832. DisplayValueToLcm(_Version_Cabient_Name_Text, (uint8_t *)value, sizeof(value));
  833. sprintf((char *)value,"%s","BootLoader:");
  834. DisplayValueToLcm(_Version_Cabient_BootLoader_Text, (uint8_t *)value, sizeof(value));
  835. sprintf((char *)value,"%s","Kernel Fw:");
  836. DisplayValueToLcm(_Version_Cabient_Kernel_Text, (uint8_t *)value, sizeof(value));
  837. sprintf((char *)value,"%s","CSU Fw:");
  838. DisplayValueToLcm(_Version_Cabient_CSU_Text, (uint8_t *)value, sizeof(value));
  839. sprintf((char *)value,"%s","Priamry Fw:");
  840. DisplayValueToLcm(_Version_Cabient_Priamry_Text, (uint8_t *)value, sizeof(value));
  841. sprintf((char *)value,"%s","Relay(0) Fw:");
  842. DisplayValueToLcm(_Version_Cabient_Relay0_Text, (uint8_t *)value, sizeof(value));
  843. sprintf((char *)value,"%s","Relay(1) Fw:");
  844. DisplayValueToLcm(_Version_Cabient_Relay1_Text, (uint8_t *)value, sizeof(value));
  845. sprintf((char *)value,"%s","Fan Fw:");
  846. DisplayValueToLcm(_Version_Cabient_Fan_Text, (uint8_t *)value, sizeof(value));
  847. sprintf((char *)value,"%s","IP Addr:");
  848. DisplayValueToLcm(_Version_Cabient_IPAddr_Text, (uint8_t *)value, sizeof(value));
  849. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number <= 12) {
  850. sprintf((char *)value,"%s","Primary");
  851. DisplayValueToLcm(_Version_Cabient_Primary_Text, (uint8_t *)value, sizeof(value));
  852. sprintf((char *)value,"%s","Secondary");
  853. DisplayValueToLcm(_Version_Cabient_Secondary_Text, (uint8_t *)value, sizeof(value));
  854. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  855. sprintf((char *)value,"PSU(%d):",i+1);
  856. DisplayValueToLcm(_Version_Cabient_PSU1_Text+i*0x10, (uint8_t *)value, sizeof(value));
  857. }
  858. }
  859. }
  860. void ShowDispenserVersionDefautlText()
  861. {
  862. char value[16];
  863. memset(value, 0x00, sizeof(value));
  864. sprintf((char *)value,"%s","Dispenser:");
  865. DisplayValueToLcm(_Version_Dispenser_Name_Text, (uint8_t *)value, sizeof(value));
  866. sprintf((char *)value,"%s","BootLoader:");
  867. DisplayValueToLcm(_Version_Dispenser_BootLoader_Text, (uint8_t *)value, sizeof(value));
  868. sprintf((char *)value,"%s","Kernel Fw:");
  869. DisplayValueToLcm(_Version_Dispenser_Kernel_Text, (uint8_t *)value, sizeof(value));
  870. sprintf((char *)value,"%s","CSU Fw:");
  871. DisplayValueToLcm(_Version_Dispenser_CSU_Text, (uint8_t *)value, sizeof(value));
  872. sprintf((char *)value,"%s","Relay Fw:");
  873. DisplayValueToLcm(_Version_Dispenser_Relay_Text, (uint8_t *)value, sizeof(value));
  874. sprintf((char *)value,"%s","Fan Fw:");
  875. DisplayValueToLcm(_Version_Dispenser_Fan_Text, (uint8_t *)value, sizeof(value));
  876. sprintf((char *)value,"%s","Prim Fw:");
  877. DisplayValueToLcm(_Version_Dispenser_Priamry_Text, (uint8_t *)value, sizeof(value));
  878. sprintf((char *)value,"%s","LCM Hw:");
  879. DisplayValueToLcm(_Version_Dispenser_LCM_Text, (uint8_t *)value, sizeof(value));
  880. sprintf((char *)value,"%s","LED Fw:");
  881. DisplayValueToLcm(_Version_Dispenser_LED_Text, (uint8_t *)value, sizeof(value));
  882. sprintf((char *)value,"%s","Connector(0):");
  883. DisplayValueToLcm(_Version_Dispenser_Connector0_Text, (uint8_t *)value, sizeof(value));
  884. sprintf((char *)value,"%s","Connector(1):");
  885. DisplayValueToLcm(_Version_Dispenser_Connector1_Text, (uint8_t *)value, sizeof(value));
  886. sprintf((char *)value,"%s","IP Addr:");
  887. DisplayValueToLcm(_Version_Dispenser_IPAddr_Text, (uint8_t *)value, sizeof(value));
  888. }
  889. void ShowCabientVersion()
  890. {
  891. char value[16];
  892. memset(value, 0x00, sizeof(value));
  893. sprintf((char *)value,"%s",ShmDcCommonData->CabinetModelName);
  894. DisplayValueToLcm(_Version_Cabient_Model_value, (uint8_t *)value, sizeof(value));
  895. sprintf((char *)value,"%s",ShmDcCommonData->CabinetBoolLoaderVersion);
  896. DisplayValueToLcm(_Version_Cabient_BootLoader_value, (uint8_t *)value, sizeof(value));
  897. sprintf((char *)value,"%s",ShmDcCommonData->CabinetKernelVersion);
  898. DisplayValueToLcm(_Version_Cabient_Kernel_value, (uint8_t *)value, sizeof(value));
  899. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRFSystemVersion);
  900. DisplayValueToLcm(_Version_Cabient_CSU_value, (uint8_t *)value, sizeof(value));
  901. sprintf((char *)value,"%s",ShmDcCommonData->CabinetPrimaryVersion);
  902. DisplayValueToLcm(_Version_Cabient_Priamry_value, (uint8_t *)value, sizeof(value));
  903. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay0Version);
  904. DisplayValueToLcm(_Version_Cabient_Relay0_value, (uint8_t *)value, sizeof(value));
  905. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay1Version);
  906. DisplayValueToLcm(_Version_Cabient_Relay1_value, (uint8_t *)value, sizeof(value));
  907. sprintf((char *)value,"%s",ShmDcCommonData->CabinetFanVersion);
  908. DisplayValueToLcm(_Version_Cabient_Fan_value, (uint8_t *)value, sizeof(value));
  909. sprintf((char *)value,"%s",ShmDcCommonData->CabinetIPAddr);
  910. DisplayValueToLcm(_Version_Cabient_IPAddr_value, (uint8_t *)value, sizeof(value));
  911. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number < 12) {
  912. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  913. if (i>=6) {
  914. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].DCVersion);
  915. DisplayValueToLcm(_Version_Cabient_PSU_Prim7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  916. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].FPCVersion);
  917. DisplayValueToLcm(_Version_Cabient_PSU_Sec7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  918. continue;
  919. }
  920. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].DCVersion);
  921. DisplayValueToLcm(_Version_Cabient_PSU_Prim1_value+i*0x10, (uint8_t *)value, sizeof(value));
  922. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].FPCVersion);
  923. DisplayValueToLcm(_Version_Cabient_PSU_Sec1_value+i*0x10, (uint8_t *)value, sizeof(value));
  924. }
  925. }
  926. }
  927. void ShowDispenserVersion()
  928. {
  929. char value[32];
  930. memset(value, 0x00, sizeof(value));
  931. sprintf((char *)value,"%s",pSysConfig->ModelName);
  932. DisplayValueToLcm(_Version_Dispenser_Model_value, (uint8_t *)value, sizeof(value));
  933. sprintf((char *)value,"%s",pSysInfo->CsuBootLoadFwRev);
  934. DisplayValueToLcm(_Version_Dispenser_BootLoader_value, (uint8_t *)value, sizeof(value));
  935. sprintf((char *)value,"%s",pSysInfo->CsuKernelFwRev);
  936. DisplayValueToLcm(_Version_Dispenser_Kernel_value, (uint8_t *)value, sizeof(value));
  937. sprintf((char *)value,"%s",pSysInfo->CsuRootFsFwRev);
  938. DisplayValueToLcm(_Version_Dispenser_CSU_value, (uint8_t *)value, sizeof(value));
  939. sprintf((char *)value,"%s",pSysInfo->RelayModuleFwRev);
  940. DisplayValueToLcm(_Version_Dispenser_Relay_value, (uint8_t *)value, sizeof(value));
  941. sprintf((char *)value,"%s",pSysInfo->FanModuleFwRev);
  942. DisplayValueToLcm(_Version_Dispenser_Fan_value, (uint8_t *)value, sizeof(value));
  943. sprintf((char *)value,"%s",pSysInfo->CsuPrimFwRev);
  944. DisplayValueToLcm(_Version_Dispenser_Priamry_value, (uint8_t *)value, sizeof(value));
  945. sprintf((char *)value,"%s",pSysInfo->LcmHwRev);
  946. DisplayValueToLcm(_Version_Dispenser_LCM_value, (uint8_t *)value, sizeof(value));
  947. sprintf((char *)value,"%s",pSysInfo->LedModuleFwRev);
  948. DisplayValueToLcm(_Version_Dispenser_LED_value, (uint8_t *)value, sizeof(value));
  949. sprintf((char *)value,"%s",pSysInfo->Connector1FwRev);
  950. DisplayValueToLcm(_Version_Dispenser_Connector0_value, (uint8_t *)value, sizeof(value));
  951. sprintf((char *)value,"%s",pSysInfo->Connector2FwRev);
  952. DisplayValueToLcm(_Version_Dispenser_Connector1_value, (uint8_t *)value, sizeof(value));
  953. sprintf((char *)value,"%s",pSysConfig->Eth0Interface.EthIpAddress);
  954. DisplayValueToLcm(_Version_Dispenser_IPAddr_value, (uint8_t *)value, sizeof(value));
  955. }
  956. void InformationShow()
  957. {
  958. is_show = true;
  959. if (_showInformIndex == 0 ) {
  960. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  961. } else {
  962. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  963. ShowDispenserVersion();
  964. }
  965. }
  966. void DefautLayOut()
  967. {
  968. for (int i = 0 ; i <= 0x72 ; i+=2 ) {
  969. ChangeDisplay2Value(0x1000+i,1);
  970. if (i == 0x38)
  971. ChangeDisplay2Value(0x1000+i,85);
  972. else if (i == 0x36)
  973. ChangeDisplay2Value(0x1000+i,75);
  974. else if (i == 0x3A)
  975. ChangeDisplay2Value(0x1000+i,99);
  976. }
  977. ChangeDisplay2Value(0x5000,1);
  978. }
  979. int main(void)
  980. {
  981. bool defaulttext = false;
  982. if (CreateAllCsuShareMemory() == FAIL) {
  983. log_error("create share memory error");
  984. return FAIL;
  985. }
  986. MappingGunChargingInfo("LCM Control Task");
  987. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  988. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  989. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  990. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  991. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  992. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  993. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  994. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  995. struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  996. struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  997. _port = CreateCommunicationLcmPort();
  998. uint8_t changeWarningPriority = 0;
  999. uint8_t curWarningCount = 255;
  1000. ChangeBackLight(true);
  1001. _totalCount = pSysConfig->TotalConnectorCount;
  1002. _everyPageRollChange = 0;
  1003. //Initialization();
  1004. //printf("_LCM_COMPLETE ");
  1005. //ChangeToOtherPage(_LCM_COMPLETE);
  1006. DefautLayOut();
  1007. //return 0;
  1008. //uint8_t index = 1;
  1009. ShmDcCommonData->PSU_Number = 12;
  1010. CheckLCMPressed();
  1011. while (_port != -1) {
  1012. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  1013. GetCurrentPage();
  1014. sleep(1);
  1015. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1016. } else {
  1017. UpdateLcmFunction(ShmDcCommonData,_port);
  1018. ///*
  1019. // Warning 處理
  1020. if (curWarningCount != pSysWarning->WarningCount) {
  1021. changeWarningPriority = 0;
  1022. pSysWarning->PageIndex = 0;
  1023. curWarningCount = pSysWarning->WarningCount;
  1024. ChangeWarningFunc();
  1025. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  1026. // 當有兩頁 Warning 則每隔三秒改變一次
  1027. if (pSysWarning->PageIndex == 0) {
  1028. pSysWarning->PageIndex = 1;
  1029. } else {
  1030. pSysWarning->PageIndex = 0;
  1031. }
  1032. ChangeWarningFunc();
  1033. }
  1034. /*
  1035. // Show Default Text
  1036. if (!defaulttext) {
  1037. ShowCabientVersionDefaultText();
  1038. ShowDispenserVersionDefautlText();
  1039. defaulttext = true;
  1040. }
  1041. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1042. // 頁面資訊處理
  1043. ProcessPageInfo();
  1044. // 換頁處理
  1045. //GetCurrentPage(); //DS60-120 add
  1046. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1047. InformationShow();
  1048. ChangeToOtherPage(pSysInfo->PageIndex);
  1049. usleep(100000);
  1050. continue;
  1051. } else {
  1052. if (is_show)
  1053. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1054. is_show = false;
  1055. }
  1056. GetCurrentPage(); //DS60-120 add
  1057. ChangeCurPage();
  1058. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1059. usleep(10000); //*/
  1060. ///*
  1061. ProcessPageInfo();
  1062. GetCurrentPage();
  1063. ChangeCurPage();
  1064. usleep(10000);
  1065. //*/
  1066. }
  1067. } //while
  1068. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1069. log_info("Close LCM Uart Port");
  1070. CloseCommunicationLcmPort();
  1071. return FAIL;
  1072. }