Module_LcmControl.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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 _Button_LeftGun_Select:
  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 _Button_RightGun_Select:
  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 _Button_Screen_Mode:
  166. break;
  167. case _Button_Charge:
  168. break;
  169. case _Button_Refund:
  170. ShmDcCommonData->_RefundRequest = true;
  171. break;
  172. case _Button_Return:
  173. ShmDcCommonData->_RefundCancel = true;
  174. break;
  175. case _Button_Member:
  176. break;
  177. case _Button_Member_None:
  178. break;
  179. case _Button_Return_Home:
  180. break;
  181. case _Button_Donate:
  182. ShmDcCommonData->_InvoiceRequest = true;
  183. break;
  184. case _Button_Donate_Select0:
  185. break;
  186. case _Button_Donate_Select1:
  187. break;
  188. case _Button_Donate_Select2:
  189. break;
  190. case _Button_Donate_Select3:
  191. break;
  192. case _Button_Donate_Confirm:
  193. break;
  194. case _Button_Authorize:
  195. CheckIdlePress();
  196. break;
  197. } // switch
  198. } //if (_btn_press >= 3)
  199. }
  200. void CheckLCMPressed()
  201. {
  202. pid_t Pid = fork();
  203. int i = 0;
  204. int index = 0;
  205. if ( Pid == 0 ) {
  206. while (1) {
  207. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  208. CheckTouchPress(_Button_LeftGun_Select);
  209. CheckTouchPress(_Button_RightGun_Select);
  210. switch (pSysInfo->SystemPage) {
  211. case _PAGE_IDLE:
  212. CheckTouchPress(_Button_Authorize);
  213. break;
  214. case _PAGE_AUTHORIZE:
  215. CheckScreenModePress();
  216. break;
  217. case _PAGE_FUNCTION_SELECT:
  218. CheckTouchPress(_Button_Charge);
  219. CheckTouchPress(_Button_Return);
  220. break;
  221. case _PAGE_MEMBER_SELECT:
  222. CheckMemberSelectPress();
  223. break;
  224. case _PAGE_DONATE:
  225. CheckDonatePress();
  226. break;
  227. case _PAGE_DONATE_SELECT:
  228. CheckDonateSelectPress();
  229. break;
  230. // ********************** Test *******************
  231. ///*
  232. case _PAGE_PRECHARGE:
  233. /*
  234. if ((i/100) %2 == 0)
  235. ChangeDisplay2Value(0x109A,i%100);
  236. else
  237. ChangeDisplay2Value(0x109A,100-(i%100));
  238. */
  239. break;
  240. case _PAGE_CHARGING:
  241. pDcChargingInfo->PresentChargingVoltage = i;
  242. pDcChargingInfo->PresentChargingPower = i;
  243. pDcChargingInfo->PresentChargedEnergy = i;
  244. pDcChargingInfo->PresentChargingCurrent =i;
  245. pDcChargingInfo->PresentChargedDuration = i;
  246. pDcChargingInfo->EvBatterySoc = i/6;
  247. break;
  248. case _PAGE_COMPLETE:
  249. pDcChargingInfo->PresentChargedEnergy = i;
  250. pDcChargingInfo->ChargingFee = i;
  251. pDcChargingInfo->EvBatterySoc = i/6;
  252. pSysConfig->BillingData.isBilling = TRUE;
  253. break;
  254. // ************************************************ */
  255. } // switch
  256. usleep(5000);
  257. ///*
  258. i++;
  259. if (i == 600 ) {
  260. index >= 22 ? index = 1 : index++;
  261. pSysInfo->SystemPage = 22;
  262. i = 0;
  263. /*
  264. if (pSysInfo->SystemPage == _PAGE_PRECHARGE)
  265. gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
  266. */
  267. }//*/
  268. } //while
  269. } // if pid
  270. log_info("Create LCM fork:%d",Pid);
  271. }
  272. void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
  273. {
  274. read(_port, msg, readLen);
  275. // 5a : CMD_TITLE_1
  276. // a5 : CMD_TITLE_2
  277. // 5
  278. // 81 : CMD_WRITE
  279. // 3 : CMD_REGISTER
  280. // 2 : Data length
  281. // 0 : High byte
  282. // 1 : Low byte
  283. // printf("-------------------------------------------- \n");
  284. // printf("msg = %x \n", *msg); // A5
  285. // printf("msg = %x \n", *(msg + 1)); // 5A
  286. // printf("msg = %x \n", *(msg + 2)); // Len : [3] ~ [6] + Data Len
  287. // printf("msg = %x \n", *(msg + 3)); // cmd : 0x83
  288. // printf("msg = %x \n", *(msg + 4)); // addr : H
  289. // printf("msg = %x \n", *(msg + 5)); // addr : L
  290. // printf("msg = %x \n", *(msg + 6)); // Data Len
  291. //
  292. // printf("msg = %x \n", *(msg + 7));
  293. // printf("msg = %x \n", *(msg + 8));
  294. // printf("msg = %x \n", *(msg + 9));
  295. // printf("msg = %x \n", *(msg + 10));
  296. // printf("msg = %x \n", *(msg + 11));
  297. // printf("msg = %x \n", *(msg + 12));
  298. // printf("msg = %x \n", *(msg + 13));
  299. // printf("msg = %x \n", *(msg + 14));
  300. /*
  301. for(uint8_t i = 0 ; i<readLen+3; i++) {
  302. log_info("Read data[%d]:0x%x",i,msg[i]);
  303. }*/
  304. if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
  305. {
  306. if(*(msg + 3) == CMD_WRITE)
  307. {
  308. switch (*(msg + 4))
  309. {
  310. case CMD_REGISTER:
  311. {
  312. // 頁面
  313. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  314. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  315. _currentPage = *(msg + 7);
  316. log_info("Current Page:%d",_currentPage);
  317. // if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
  318. // printf("_currentPage = %d \n", _currentPage);
  319. }
  320. break;
  321. }
  322. }
  323. else if (*(msg + 3) == CMD_MULTI_READ)
  324. {
  325. short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
  326. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  327. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  328. if (key == 0x0014)
  329. _currentPage = *(msg + 8);
  330. if ( key >= _Button_LeftGun_Select && key <=_Button_Authorize ) {
  331. _btn_press_id = key;
  332. _btn_press = *(msg + 8);
  333. }
  334. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  335. // {
  336. // case BUTTON_GUN_INDEX:
  337. // {
  338. // // 當前選的槍號
  339. // _curGunIndex = (*(msg + 8));
  340. // }
  341. // break;
  342. // }
  343. }
  344. }
  345. }
  346. void GetHrFormTimeString(char* time,char* hr)
  347. {
  348. //char tm[] = "2021-12-06 17:29:08:084";
  349. for(int i = 0 ; i < 2 ; i++) {
  350. hr[i] = time[i+11];
  351. }
  352. if( atoi(hr) == NULL ) {
  353. strcmp(hr,"");
  354. }
  355. }
  356. void GetMinFormTimeString(char* time,char* min)
  357. {
  358. //char tm[] = "2021-12-06 17:29:08:084";
  359. for(int i = 0 ; i < 2 ; i++) {
  360. min[i] = time[i+14];
  361. }
  362. if( atoi(min) == NULL || atoi(min) > 60) {
  363. strcmp(min,"");
  364. }
  365. }
  366. //================================================
  367. // Function
  368. //================================================
  369. void ChangeToOtherPage(short newPage)
  370. {
  371. uint8_t cmd[10];
  372. memset(cmd, 0x00, sizeof(cmd));
  373. uint8_t msg[9];
  374. memset(msg, 0x00, sizeof(msg));
  375. cmd[0] = CMD_TITLE_1;
  376. cmd[1] = CMD_TITLE_2;
  377. cmd[2] = 0x07;
  378. cmd[3] = 0x82;
  379. cmd[4] = 0x00;
  380. cmd[5] = 0x84;
  381. cmd[6] = 0x5A;
  382. cmd[7] = 0x01;
  383. cmd[8] = newPage >> 8;
  384. cmd[9] = newPage & 0x00FF;
  385. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  386. usleep(5000);
  387. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  388. }
  389. void ChangeBackLight(bool islight)
  390. {
  391. uint8_t value = 0x01;
  392. uint8_t msg[9];
  393. memset(msg, 0x00, sizeof(msg));
  394. // 0x00 ~ 0x40
  395. if (islight)
  396. {
  397. value = 0x20;
  398. }
  399. uint8_t cmd[7];
  400. memset(cmd, 0x00, sizeof(cmd));
  401. cmd[0] = CMD_TITLE_1;
  402. cmd[1] = CMD_TITLE_2;
  403. cmd[2] = 0x03;
  404. cmd[3] = CMD_READ;
  405. cmd[4] = CMD_BACKLIGHT;
  406. cmd[5] = value;
  407. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  408. usleep(10000);
  409. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  410. }
  411. void GetCurrentPage()
  412. {
  413. uint8_t cmd[7];
  414. memset(cmd, 0x00, sizeof(cmd));
  415. uint8_t msg[9];
  416. memset(msg, 0x00, sizeof(msg));
  417. cmd[0] = CMD_TITLE_1;
  418. cmd[1] = CMD_TITLE_2;
  419. cmd[2] = 0x04; // 底下總長度
  420. cmd[3] = 0x83;
  421. cmd[4] = 0x00;
  422. cmd[5] = 0x14;
  423. cmd[6] = 0x01;
  424. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  425. usleep(5000);
  426. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  427. }
  428. void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
  429. {
  430. uint8_t cmd[256];
  431. memset(cmd, 0x00, sizeof(cmd));
  432. uint8_t msg[9];
  433. memset(msg, 0x00, sizeof(msg));
  434. cmd[0] = CMD_TITLE_1;
  435. cmd[1] = CMD_TITLE_2;
  436. cmd[2] = 0x03 + len;
  437. cmd[3] = CMD_MULTI_WRITE;
  438. cmd[4] = address >> 8;
  439. cmd[5] = address & 0x00FF;
  440. for(uint8_t count = 0; count < len; count++)
  441. {
  442. cmd[6 + count] = *(data + count);
  443. }
  444. WriteCmdToLcm(cmd, cmd[2] + 3);
  445. usleep(10000);
  446. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  447. }
  448. void ChangeDisplay2Value(short address, short value)
  449. {
  450. uint8_t data[2];
  451. data[0] = value >> 8;
  452. data[1] = value & 0x00FF;
  453. //log_info("Addr:0x%x, value:%d",address,value);
  454. DisplayValueToLcm(address, data, sizeof(data));
  455. }
  456. //================================================
  457. // Warning process
  458. //================================================
  459. void string2ByteArray(uint8_t *input, uint8_t *output)
  460. {
  461. int loop;
  462. int i;
  463. loop = 0;
  464. i = 0;
  465. while (input[loop] != '\0') {
  466. output[i++] = input[loop++];
  467. }
  468. output[loop] = '\0';
  469. }
  470. void RefreshProgressAnimation(uint8_t progress_index)
  471. {
  472. if(_everyPageRollChange % 2) {
  473. progress_index+=1;
  474. }
  475. _everyPageRollChange++;
  476. }
  477. //================================================
  478. // Change current page
  479. //================================================
  480. void ChangeCurPage()
  481. {
  482. //log_info("cur = %d ,system = %d, lcm = %d ",_currentPage, pSysInfo->SystemPage, pSysInfo->PageIndex);
  483. struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  484. struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  485. pSysInfo->PageIndex = pSysInfo->SystemPage;
  486. if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM &&
  487. pSysInfo->SystemPage != _PAGE_IDLE &&
  488. pSysInfo->SystemPage != _PAGE_MAINTAIN &&
  489. pSysInfo->SystemPage != _PAGE_ERROR ) {
  490. pSysInfo->PageIndex = pSysInfo->SystemPage + 30;
  491. }
  492. if (_currentPage != pSysInfo->PageIndex) {
  493. switch (pSysInfo->SystemPage) {
  494. case _PAGE_AUTHORIZE:
  495. gettimeofday(&returnIdleTimer, NULL);
  496. break;
  497. case _PAGE_PLUGIN:
  498. break;
  499. case _PAGE_PRECHARGE:
  500. break;
  501. case _PAGE_CHARGING:
  502. break;
  503. case _PAGE_COMPLETE:
  504. break;
  505. }
  506. _currentPage = pSysInfo->PageIndex;
  507. ChangeToOtherPage(pSysInfo->PageIndex);
  508. }
  509. }
  510. /*
  511. * View Page
  512. *
  513. */
  514. unsigned long GetTimeoutValue(struct timeval _sour_time)
  515. {
  516. struct timeval _end_time;
  517. gettimeofday(&_end_time, NULL);
  518. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  519. }
  520. void showGunWorkingType()
  521. {
  522. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
  523. ChangeDisplay2Value(_LeftGun_Title,_ICON_LeftGunShow);
  524. // Set Left Gun
  525. ChangeDisplay2Value(_LeftGun_Status,_ICON_LeftGun_on);
  526. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  527. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  528. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  529. ChangeDisplay2Value(_LeftGun_Type,_ICON_LeftGun_on_CCCS1);
  530. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  531. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  532. ChangeDisplay2Value(_LeftGun_Type,_ICON_LeftGun_on_CCS2);
  533. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  534. ChangeDisplay2Value(_LeftGun_Type,_ICON_LeftGun_on_CHAdeMo);
  535. }
  536. // Set Right Gun
  537. ChangeDisplay2Value(_RightGun_Status,_ICON_RightGun_off);
  538. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  539. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  540. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  541. ChangeDisplay2Value(_RightGun_Type,_ICON_RightGun_off_CCS1);
  542. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  543. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  544. ChangeDisplay2Value(_RightGun_Type,_ICON_RightGun_off_CCS2);
  545. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  546. ChangeDisplay2Value(_RightGun_Type,_ICON_RightGun_off_CHAdeMo);
  547. }
  548. } else {
  549. // Left Gun
  550. ChangeDisplay2Value(_RightGun_Title,_ICON_RightGunShow);
  551. ChangeDisplay2Value(_LeftGun_Status,_ICON_LeftGun_off);
  552. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  553. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  554. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  555. ChangeDisplay2Value(_LeftGun_Type,_ICON_LeftGun_off_CCS1);
  556. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  557. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  558. ChangeDisplay2Value(_LeftGun_Type,_ICON_LeftGun_off_CCS2);
  559. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  560. ChangeDisplay2Value(_LeftGun_Type,_ICON_LeftGun_off_CHAdeMo);
  561. }
  562. // Right Gun
  563. ChangeDisplay2Value(_RightGun_Status,_ICON_RightGun_on);
  564. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  565. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  566. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  567. ChangeDisplay2Value(_RightGun_Type,_ICON_RightGun_on_CCS1);
  568. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  569. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  570. ChangeDisplay2Value(_RightGun_Type,_ICON_RightGun_on_CCS2);
  571. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  572. ChangeDisplay2Value(_RightGun_Type,_ICON_RightGun_on_CHAdeMo);
  573. }
  574. }
  575. }
  576. void ChangeQrCode_Idle(char *input)
  577. {
  578. int len = strlen(input);
  579. uint8_t cmd[len];
  580. int loop = 0;
  581. int i = 0;
  582. while (input[loop] != '\0') {
  583. cmd[i++] = input[loop++];
  584. }
  585. DisplayValueToLcm(_QR_CODE_, cmd, len + 1);
  586. }
  587. void ShowHomePage()
  588. {
  589. // Show QR Code
  590. if (pSysConfig->isQRCode) {
  591. if (pSysConfig->QRCodeMadeMode == NO) {
  592. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  593. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  594. } else {
  595. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  596. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  597. }
  598. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  599. }
  600. }
  601. void ChangeRemainTime(int sec)
  602. {
  603. int h, m, s;
  604. uint8_t cmd[10];
  605. uint8_t value[10];
  606. memset(cmd, 0x00, sizeof(cmd));
  607. // srand(time(NULL));
  608. // int min = 0;
  609. // int max = 65536;
  610. // sec = rand() % (max - min + 1) + min;
  611. h = (sec / 3600);
  612. m = (sec - (3600 * h)) / 60;
  613. s = (sec - (3600 * h) - (m * 60));
  614. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  615. string2ByteArray(value, cmd);
  616. DisplayValueToLcm(_String_ChargeTime_, cmd, sizeof(cmd));
  617. }
  618. void ChangeChargingPowerValue(float pow)
  619. {
  620. uint8_t cmd[10];
  621. uint8_t value[10];
  622. memset(cmd, 0x00, sizeof(cmd));
  623. sprintf((char *) value, "%.1f",pow);
  624. string2ByteArray(value, cmd);
  625. DisplayValueToLcm(_String_Power_, cmd, sizeof(cmd));
  626. }
  627. void ChangeChargingVoltageValue(float vol)
  628. {
  629. uint8_t cmd[10];
  630. uint8_t value[10];
  631. memset(cmd, 0x00, sizeof(cmd));
  632. sprintf((char *) value, "%d", (int)vol);
  633. string2ByteArray(value, cmd);
  634. DisplayValueToLcm(_String_Voltage_, cmd, sizeof(cmd));
  635. }
  636. void ChangeChargingCurrenteValue(float vol)
  637. {
  638. uint8_t cmd[10];
  639. uint8_t value[10];
  640. memset(cmd, 0x00, sizeof(cmd));
  641. sprintf((char *) value, "%d", (int)vol);
  642. string2ByteArray(value, cmd);
  643. DisplayValueToLcm(_String_Current_, cmd, sizeof(cmd));
  644. }
  645. void ChangeChargingFeeValue(float fee)
  646. {
  647. uint8_t cmd[10];
  648. uint8_t value[10];
  649. memset(cmd, 0x00, sizeof(cmd));
  650. sprintf((char *) value, "%d", (int)fee);
  651. string2ByteArray(value, cmd);
  652. DisplayValueToLcm(_String_Cost_, cmd, sizeof(cmd));
  653. }
  654. void ChangeChargingEnergyValue(float energy)
  655. {
  656. uint8_t cmd[10];
  657. uint8_t value[10];
  658. memset(cmd, 0x00, sizeof(cmd));
  659. if (energy >= 0.05) {
  660. energy -= 0.05;
  661. }
  662. sprintf((char *) value, "%d", (int)energy);
  663. string2ByteArray(value, cmd);
  664. DisplayValueToLcm(_String_Rate_, cmd, sizeof(cmd));
  665. }
  666. uint8_t _battery_display_count = 0;
  667. void ChangeBattMapAndValue(short page, int soc)
  668. {
  669. if (page == _PAGE_CHARGING) {
  670. _battery_display_count++;
  671. if (_battery_display_count == 3 ) {
  672. if (_battery_display_ani == 0)
  673. _battery_display_ani= TRUE;
  674. else
  675. _battery_display_ani= FALSE ;
  676. _battery_display_count = 0;
  677. }
  678. if (soc < 25) {
  679. if (_battery_display_ani) {
  680. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_0);
  681. } else {
  682. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_1);
  683. }
  684. } else if (soc >= 25 && soc < 50) {
  685. if (_battery_display_ani) {
  686. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_1);
  687. } else {
  688. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_2);
  689. }
  690. } else if (soc >= 50 && soc < 75) {
  691. if (_battery_display_ani) {
  692. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_2);
  693. } else {
  694. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_3);
  695. }
  696. } else if (soc >= 75 && soc < 100) {
  697. if (_battery_display_ani) {
  698. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_3);
  699. } else {
  700. ChangeDisplay2Value(_Battery_Progress_0, _ICON_battery_4);
  701. }
  702. }
  703. } else if (page == _PAGE_COMPLETE) {
  704. if (soc < 20) {
  705. ChangeDisplay2Value(_Battery_Progress_1, _ICON_text_battery_0);
  706. } else if (soc >= 20 && soc < 40) {
  707. ChangeDisplay2Value(_Battery_Progress_1, _ICON_text_battery_1);
  708. } else if (soc >= 40 && soc < 60) {
  709. ChangeDisplay2Value(_Battery_Progress_1, _ICON_text_battery_2);
  710. } else if (soc >= 60 && soc < 80) {
  711. ChangeDisplay2Value(_Battery_Progress_1, _ICON_text_battery_3);
  712. } else if (soc >= 80 && soc <= 100) {
  713. ChangeDisplay2Value(_Battery_Progress_1, _ICON_text_battery_4);
  714. }
  715. }
  716. uint8_t cmd[5];
  717. uint8_t value[5];
  718. memset(cmd, 0x00, sizeof(cmd));
  719. memset(value, 0x00, sizeof(value));
  720. sprintf((char *)value, "%d", soc);
  721. string2ByteArray(value, cmd);
  722. DisplayValueToLcm(_String_BatterySoc_, cmd, sizeof(cmd));
  723. }
  724. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  725. {
  726. struct timeval _end_time;
  727. gettimeofday(&_end_time, NULL);
  728. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  729. }
  730. void ChangeTimeValue(uint8_t time)
  731. {
  732. uint8_t cmd[2];
  733. uint8_t value[2];
  734. memset(cmd, 0x00, sizeof(cmd));
  735. sprintf((char *) value, "%d", time);
  736. string2ByteArray(value, cmd);
  737. DisplayValueToLcm(_PreChargeTimer, cmd, sizeof(cmd));
  738. }
  739. void CabinetChangeLCMProcess()
  740. {
  741. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  742. if ( (pDcChargingInfo->ChangeLcmPage == _CHANGE_REFUNDAMOUNT ||
  743. pDcChargingInfo->ChangeLcmPage == _CHANGE_PREPAYMENTINFO ||
  744. pDcChargingInfo->ChangeLcmPage == _CHANGE_PAYMENT_FAIL) &&
  745. ShmDcCommonData->_ChangeLCMRequest != TRUE) {
  746. return;
  747. }
  748. switch(pDcChargingInfo->ChangeLcmPage) {
  749. case _CHANGE_REMOTESTART:
  750. break;
  751. case _CHANGE_REFUNDING:
  752. pSysInfo->SystemPage = _PAGE_REFUNDING;
  753. break;
  754. case _CHANGE_REFUNDAMOUNT:
  755. pSysInfo->SystemPage = _PAGE_REFUND_COMPLETE;
  756. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  757. break;
  758. case _CHANGE_NOREFUND:
  759. pSysInfo->SystemPage = _PAGE_REFUND_NONE;
  760. break;
  761. case _CHANGE_PREPAYMENTINFO:
  762. pSysInfo->SystemPage = _PAGE_PAY_ETICKET_SUCCESS;
  763. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  764. break;
  765. case _CHANGE_PAYMENT_OK:
  766. pSysInfo->SystemPage = _PAGE_PAY_MPAY_SUCCESS;
  767. break;
  768. case _CHANGE_PAYMENT_FAIL:
  769. pSysInfo->SystemPage = _PAGE_PAY_FAIL;
  770. ShmDcCommonData->_ChangeLCMRequest = FALSE;
  771. break;
  772. }
  773. }
  774. void ProcessPageInfo()
  775. {
  776. // Show Gun Working and Type
  777. float _current;
  778. uint8_t precharg_time;
  779. showGunWorkingType();
  780. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  781. if (pSysInfo->CurGunSelected == i) {
  782. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  783. CabinetChangeLCMProcess();
  784. switch (pSysInfo->SystemPage) {
  785. case _PAGE_AUTHORIZE:
  786. ShowHomePage();
  787. log_info("Time:%d",GetTimeoutValue(returnIdleTimer) /uSEC_VAL);
  788. if (GetTimeoutValue(returnIdleTimer) /uSEC_VAL >= RETURNIDLE_Timeout ) {
  789. pSysInfo->SystemPage = _PAGE_IDLE;
  790. gettimeofday(&returnIdleTimer, NULL);
  791. }
  792. break;
  793. case _PAGE_PLUGIN:
  794. _Text_Running_Count = 0;
  795. break;
  796. case _PAGE_PRECHARGE:
  797. if ((_Text_Running_Count/100) %2 == 0)
  798. ChangeDisplay2Value(_Text_PrepareToCharge,_Text_Running_Count%100);
  799. else
  800. ChangeDisplay2Value(_Text_PrepareToCharge,100-(_Text_Running_Count%100));
  801. _Text_Running_Count >= 200 ? _Text_Running_Count = 0 : _Text_Running_Count++;
  802. break;
  803. case _PAGE_CHARGING:
  804. if (pDcChargingInfo->PresentChargingVoltage >= 0 &&
  805. pDcChargingInfo->PresentChargingVoltage <= 950) {
  806. ChangeChargingVoltageValue(pDcChargingInfo->PresentChargingVoltage);
  807. }
  808. if (pDcChargingInfo->PresentChargingCurrent >= 0) {
  809. ChangeChargingCurrenteValue(pDcChargingInfo->PresentChargingCurrent);
  810. }
  811. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  812. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  813. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  814. } else {
  815. ChangeChargingPowerValue(0);
  816. }
  817. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  818. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  819. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  820. } else {
  821. ChangeChargingEnergyValue(0);
  822. }
  823. if (pDcChargingInfo->PresentChargedDuration >= 0 &&
  824. pDcChargingInfo->PresentChargedDuration <= TIME_MAX_SEC) {
  825. ChangeRemainTime(pDcChargingInfo->PresentChargedDuration);
  826. } else {
  827. ChangeRemainTime(0);
  828. }
  829. ChangeBattMapAndValue(_currentPage, pDcChargingInfo->EvBatterySoc);
  830. break;
  831. case _PAGE_COMPLETE:
  832. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  833. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  834. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  835. } else {
  836. ChangeChargingEnergyValue(0);
  837. }
  838. if (pSysConfig->BillingData.isBilling &&
  839. pDcChargingInfo->ChargingFee >= 0) {
  840. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  841. }
  842. ChangeBattMapAndValue(_currentPage, pDcChargingInfo->EvBatterySoc);
  843. break;
  844. case _PAGE_REFUND_SENSEING:
  845. break;
  846. case _PAGE_PLUGOUT:
  847. ChangeDisplay2Value(0x20B0, Battery_Test);
  848. Battery_Test >= 100 ? Battery_Test = 0 : Battery_Test++;
  849. break;
  850. }
  851. }
  852. }
  853. }
  854. void ChangeWarningFunc()
  855. {
  856. uint8_t cmd[7] = {0};
  857. uint8_t i = 0;
  858. //uint8_t j = 0;
  859. //log_info("ChangeWarningFunc ");
  860. // 最多一次五筆
  861. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  862. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  863. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  864. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  865. //log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  866. memset(cmd, 0x00, sizeof(cmd));
  867. if ((i) >= 5) {
  868. break;
  869. }
  870. //error code
  871. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  872. DisplayValueToLcm(0x3020 + ((i) * 6), cmd, sizeof(cmd));
  873. //警告標示
  874. memset(cmd, 0x00, sizeof(cmd));
  875. cmd[0] = 0x00;
  876. cmd[1] = 85;
  877. DisplayValueToLcm(0x1090 + ((i) * 2), cmd, 2);
  878. }
  879. memset(cmd, 0x00, sizeof(cmd));
  880. for (; i < 5; i++) {
  881. DisplayValueToLcm(0x3020 + ((i) * 6), cmd, sizeof(cmd));
  882. DisplayValueToLcm(0x1090 + ((i) * 2), cmd, 2);
  883. }
  884. }
  885. void ShowCabientVersionDefaultText()
  886. {
  887. char value[16];
  888. memset(value, 0x00, sizeof(value));
  889. sprintf((char *)value,"%s","Cabient:");
  890. DisplayValueToLcm(_Version_Cabient_Name_Text, (uint8_t *)value, sizeof(value));
  891. sprintf((char *)value,"%s","BootLoader:");
  892. DisplayValueToLcm(_Version_Cabient_BootLoader_Text, (uint8_t *)value, sizeof(value));
  893. sprintf((char *)value,"%s","Kernel Fw:");
  894. DisplayValueToLcm(_Version_Cabient_Kernel_Text, (uint8_t *)value, sizeof(value));
  895. sprintf((char *)value,"%s","CSU Fw:");
  896. DisplayValueToLcm(_Version_Cabient_CSU_Text, (uint8_t *)value, sizeof(value));
  897. sprintf((char *)value,"%s","Priamry Fw:");
  898. DisplayValueToLcm(_Version_Cabient_Priamry_Text, (uint8_t *)value, sizeof(value));
  899. sprintf((char *)value,"%s","Relay(0) Fw:");
  900. DisplayValueToLcm(_Version_Cabient_Relay0_Text, (uint8_t *)value, sizeof(value));
  901. sprintf((char *)value,"%s","Relay(1) Fw:");
  902. DisplayValueToLcm(_Version_Cabient_Relay1_Text, (uint8_t *)value, sizeof(value));
  903. sprintf((char *)value,"%s","Fan Fw:");
  904. DisplayValueToLcm(_Version_Cabient_Fan_Text, (uint8_t *)value, sizeof(value));
  905. sprintf((char *)value,"%s","IP Addr:");
  906. DisplayValueToLcm(_Version_Cabient_IPAddr_Text, (uint8_t *)value, sizeof(value));
  907. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number <= 12) {
  908. sprintf((char *)value,"%s","Primary");
  909. DisplayValueToLcm(_Version_Cabient_Primary_Text, (uint8_t *)value, sizeof(value));
  910. sprintf((char *)value,"%s","Secondary");
  911. DisplayValueToLcm(_Version_Cabient_Secondary_Text, (uint8_t *)value, sizeof(value));
  912. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  913. sprintf((char *)value,"PSU(%d):",i+1);
  914. DisplayValueToLcm(_Version_Cabient_PSU1_Text+i*0x10, (uint8_t *)value, sizeof(value));
  915. }
  916. }
  917. }
  918. void ShowDispenserVersionDefautlText()
  919. {
  920. char value[16];
  921. memset(value, 0x00, sizeof(value));
  922. sprintf((char *)value,"%s","Dispenser:");
  923. DisplayValueToLcm(_Version_Dispenser_Name_Text, (uint8_t *)value, sizeof(value));
  924. sprintf((char *)value,"%s","BootLoader:");
  925. DisplayValueToLcm(_Version_Dispenser_BootLoader_Text, (uint8_t *)value, sizeof(value));
  926. sprintf((char *)value,"%s","Kernel Fw:");
  927. DisplayValueToLcm(_Version_Dispenser_Kernel_Text, (uint8_t *)value, sizeof(value));
  928. sprintf((char *)value,"%s","CSU Fw:");
  929. DisplayValueToLcm(_Version_Dispenser_CSU_Text, (uint8_t *)value, sizeof(value));
  930. sprintf((char *)value,"%s","Relay Fw:");
  931. DisplayValueToLcm(_Version_Dispenser_Relay_Text, (uint8_t *)value, sizeof(value));
  932. sprintf((char *)value,"%s","Fan Fw:");
  933. DisplayValueToLcm(_Version_Dispenser_Fan_Text, (uint8_t *)value, sizeof(value));
  934. sprintf((char *)value,"%s","Prim Fw:");
  935. DisplayValueToLcm(_Version_Dispenser_Priamry_Text, (uint8_t *)value, sizeof(value));
  936. sprintf((char *)value,"%s","LCM Hw:");
  937. DisplayValueToLcm(_Version_Dispenser_LCM_Text, (uint8_t *)value, sizeof(value));
  938. sprintf((char *)value,"%s","LED Fw:");
  939. DisplayValueToLcm(_Version_Dispenser_LED_Text, (uint8_t *)value, sizeof(value));
  940. sprintf((char *)value,"%s","Connector(0):");
  941. DisplayValueToLcm(_Version_Dispenser_Connector0_Text, (uint8_t *)value, sizeof(value));
  942. sprintf((char *)value,"%s","Connector(1):");
  943. DisplayValueToLcm(_Version_Dispenser_Connector1_Text, (uint8_t *)value, sizeof(value));
  944. sprintf((char *)value,"%s","IP Addr:");
  945. DisplayValueToLcm(_Version_Dispenser_IPAddr_Text, (uint8_t *)value, sizeof(value));
  946. }
  947. void ShowCabientVersion()
  948. {
  949. char value[16];
  950. memset(value, 0x00, sizeof(value));
  951. sprintf((char *)value,"%s",ShmDcCommonData->CabinetModelName);
  952. DisplayValueToLcm(_Version_Cabient_Model_value, (uint8_t *)value, sizeof(value));
  953. sprintf((char *)value,"%s",ShmDcCommonData->CabinetBoolLoaderVersion);
  954. DisplayValueToLcm(_Version_Cabient_BootLoader_value, (uint8_t *)value, sizeof(value));
  955. sprintf((char *)value,"%s",ShmDcCommonData->CabinetKernelVersion);
  956. DisplayValueToLcm(_Version_Cabient_Kernel_value, (uint8_t *)value, sizeof(value));
  957. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRFSystemVersion);
  958. DisplayValueToLcm(_Version_Cabient_CSU_value, (uint8_t *)value, sizeof(value));
  959. sprintf((char *)value,"%s",ShmDcCommonData->CabinetPrimaryVersion);
  960. DisplayValueToLcm(_Version_Cabient_Priamry_value, (uint8_t *)value, sizeof(value));
  961. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay0Version);
  962. DisplayValueToLcm(_Version_Cabient_Relay0_value, (uint8_t *)value, sizeof(value));
  963. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay1Version);
  964. DisplayValueToLcm(_Version_Cabient_Relay1_value, (uint8_t *)value, sizeof(value));
  965. sprintf((char *)value,"%s",ShmDcCommonData->CabinetFanVersion);
  966. DisplayValueToLcm(_Version_Cabient_Fan_value, (uint8_t *)value, sizeof(value));
  967. sprintf((char *)value,"%s",ShmDcCommonData->CabinetIPAddr);
  968. DisplayValueToLcm(_Version_Cabient_IPAddr_value, (uint8_t *)value, sizeof(value));
  969. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number < 12) {
  970. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  971. if (i>=6) {
  972. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].DCVersion);
  973. DisplayValueToLcm(_Version_Cabient_PSU_Prim7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  974. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].FPCVersion);
  975. DisplayValueToLcm(_Version_Cabient_PSU_Sec7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  976. continue;
  977. }
  978. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].DCVersion);
  979. DisplayValueToLcm(_Version_Cabient_PSU_Prim1_value+i*0x10, (uint8_t *)value, sizeof(value));
  980. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].FPCVersion);
  981. DisplayValueToLcm(_Version_Cabient_PSU_Sec1_value+i*0x10, (uint8_t *)value, sizeof(value));
  982. }
  983. }
  984. }
  985. void ShowDispenserVersion()
  986. {
  987. char value[32];
  988. memset(value, 0x00, sizeof(value));
  989. sprintf((char *)value,"%s",pSysConfig->ModelName);
  990. DisplayValueToLcm(_Version_Dispenser_Model_value, (uint8_t *)value, sizeof(value));
  991. sprintf((char *)value,"%s",pSysInfo->CsuBootLoadFwRev);
  992. DisplayValueToLcm(_Version_Dispenser_BootLoader_value, (uint8_t *)value, sizeof(value));
  993. sprintf((char *)value,"%s",pSysInfo->CsuKernelFwRev);
  994. DisplayValueToLcm(_Version_Dispenser_Kernel_value, (uint8_t *)value, sizeof(value));
  995. sprintf((char *)value,"%s",pSysInfo->CsuRootFsFwRev);
  996. DisplayValueToLcm(_Version_Dispenser_CSU_value, (uint8_t *)value, sizeof(value));
  997. sprintf((char *)value,"%s",pSysInfo->RelayModuleFwRev);
  998. DisplayValueToLcm(_Version_Dispenser_Relay_value, (uint8_t *)value, sizeof(value));
  999. sprintf((char *)value,"%s",pSysInfo->FanModuleFwRev);
  1000. DisplayValueToLcm(_Version_Dispenser_Fan_value, (uint8_t *)value, sizeof(value));
  1001. sprintf((char *)value,"%s",pSysInfo->CsuPrimFwRev);
  1002. DisplayValueToLcm(_Version_Dispenser_Priamry_value, (uint8_t *)value, sizeof(value));
  1003. sprintf((char *)value,"%s",pSysInfo->LcmHwRev);
  1004. DisplayValueToLcm(_Version_Dispenser_LCM_value, (uint8_t *)value, sizeof(value));
  1005. sprintf((char *)value,"%s",pSysInfo->LedModuleFwRev);
  1006. DisplayValueToLcm(_Version_Dispenser_LED_value, (uint8_t *)value, sizeof(value));
  1007. sprintf((char *)value,"%s",pSysInfo->Connector1FwRev);
  1008. DisplayValueToLcm(_Version_Dispenser_Connector0_value, (uint8_t *)value, sizeof(value));
  1009. sprintf((char *)value,"%s",pSysInfo->Connector2FwRev);
  1010. DisplayValueToLcm(_Version_Dispenser_Connector1_value, (uint8_t *)value, sizeof(value));
  1011. sprintf((char *)value,"%s",pSysConfig->Eth0Interface.EthIpAddress);
  1012. DisplayValueToLcm(_Version_Dispenser_IPAddr_value, (uint8_t *)value, sizeof(value));
  1013. }
  1014. void InformationShow()
  1015. {
  1016. is_show = true;
  1017. if (_showInformIndex == 0 ) {
  1018. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  1019. } else {
  1020. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  1021. ShowDispenserVersion();
  1022. }
  1023. }
  1024. void DefautLayOut()
  1025. {
  1026. ChangeDisplay2Value(_CellPhone_Mode,_ICON_cellphone_mode);
  1027. ChangeDisplay2Value(_Screen_Mode,_ICON_screen_mode);
  1028. ChangeDisplay2Value(_PlugIn_String,_ICON_Plugin);
  1029. ChangeDisplay2Value(_Communication_Status,_ICON_Communication_on);
  1030. ChangeDisplay2Value(_SaftyDetect_Status,_ICON_SaftyDetect_off);
  1031. ChangeDisplay2Value(_PreCharge_Status,_ICON_PrepareCharge_off);
  1032. ChangeDisplay2Value(_Text_Voltage,_ICON_text_Voltage);
  1033. ChangeDisplay2Value(_Text_Current,_ICON_text_Current);
  1034. ChangeDisplay2Value(_Text_Power,_ICON_text_Power);
  1035. ChangeDisplay2Value(_Text_Rate,_ICON_text_Rate);
  1036. ChangeDisplay2Value(_Text_Time,_ICON_text_time);
  1037. ChangeDisplay2Value(_Battery_Progress_0,_ICON_battery_0);
  1038. ChangeDisplay2Value(_Symbol_V,_ICON_symbol_V);
  1039. ChangeDisplay2Value(_Symbol_A,_ICON_symbol_A);
  1040. ChangeDisplay2Value(_Symbol_KW,_ICON_symbol_KW);
  1041. ChangeDisplay2Value(_Symbol_Rate,_ICON_symbol_rate);
  1042. ChangeDisplay2Value(_Symbol_Percent,_ICON_symbol_percent);
  1043. ChangeDisplay2Value(_Text_ChargeRate,_ICON_text_ChargereRate);
  1044. ChangeDisplay2Value(_Text_ChargePay,_ICON_text_ChargePay);
  1045. ChangeDisplay2Value(_Battery_Progress_1,_ICON_text_battery_0);
  1046. ChangeDisplay2Value(_Symbol_Dollar,_ICON_text_dollor);
  1047. ChangeDisplay2Value(_Text_ChargeComplete,_ICON_text_ChargeComplete);
  1048. }
  1049. int main(void)
  1050. {
  1051. bool defaulttext = false;
  1052. if (CreateAllCsuShareMemory() == FAIL) {
  1053. log_error("create share memory error");
  1054. return FAIL;
  1055. }
  1056. MappingGunChargingInfo("LCM Control Task");
  1057. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1058. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1059. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1060. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  1061. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1062. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1063. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1064. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  1065. struct ChargingInfoData *pDcChargingInfo_0 = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  1066. struct ChargingInfoData *pDcChargingInfo_1 = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1067. _port = CreateCommunicationLcmPort();
  1068. uint8_t changeWarningPriority = 0;
  1069. uint8_t curWarningCount = 255;
  1070. ChangeBackLight(true);
  1071. _totalCount = pSysConfig->TotalConnectorCount;
  1072. _everyPageRollChange = 0;
  1073. //Initialization();
  1074. //printf("_LCM_COMPLETE ");
  1075. //ChangeToOtherPage(_LCM_COMPLETE);
  1076. DefautLayOut();
  1077. //return 0;
  1078. //uint8_t index = 1;
  1079. ShmDcCommonData->PSU_Number = 12;
  1080. CheckLCMPressed();
  1081. while (_port != -1) {
  1082. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  1083. GetCurrentPage();
  1084. sleep(1);
  1085. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1086. } else {
  1087. UpdateLcmFunction(ShmDcCommonData,_port);
  1088. // Warning 處理
  1089. if (curWarningCount != pSysWarning->WarningCount) {
  1090. changeWarningPriority = 0;
  1091. pSysWarning->PageIndex = 0;
  1092. curWarningCount = pSysWarning->WarningCount;
  1093. ChangeWarningFunc();
  1094. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  1095. // 當有兩頁 Warning 則每隔三秒改變一次
  1096. if (pSysWarning->PageIndex == 0) {
  1097. pSysWarning->PageIndex = 1;
  1098. } else {
  1099. pSysWarning->PageIndex = 0;
  1100. }
  1101. ChangeWarningFunc();
  1102. }
  1103. /*
  1104. // Show Default Text
  1105. if (!defaulttext) {
  1106. ShowCabientVersionDefaultText();
  1107. ShowDispenserVersionDefautlText();
  1108. defaulttext = true;
  1109. }
  1110. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1111. // 頁面資訊處理
  1112. ProcessPageInfo();
  1113. // 換頁處理
  1114. //GetCurrentPage(); //DS60-120 add
  1115. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1116. InformationShow();
  1117. ChangeToOtherPage(pSysInfo->PageIndex);
  1118. usleep(100000);
  1119. continue;
  1120. } else {
  1121. if (is_show)
  1122. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1123. is_show = false;
  1124. }
  1125. GetCurrentPage(); //DS60-120 add
  1126. ChangeCurPage();
  1127. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1128. usleep(10000); //*/
  1129. ///*
  1130. ProcessPageInfo();
  1131. GetCurrentPage();
  1132. ChangeCurPage();
  1133. usleep(10000);
  1134. //*/
  1135. }
  1136. } //while
  1137. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1138. log_info("Close LCM Uart Port");
  1139. CloseCommunicationLcmPort();
  1140. return FAIL;
  1141. }