Module_LcmControl.c 46 KB

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