Module_LcmControl.c 41 KB

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