Module_LcmControl.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  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. #include "../timeout.h"
  19. #define uSEC_VAL (1000000)
  20. //------------------------------------------------------------------------------
  21. //struct SysConfigAndInfo *ShmSysConfigAndInfo;
  22. //struct StatusCodeData *ShmStatusCodeData;
  23. static struct SysConfigData *pSysConfig = NULL;
  24. static struct SysInfoData *pSysInfo = NULL;
  25. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  26. static struct OCPP16Data *ShmOCPP16Data = NULL;
  27. static struct FanModuleData *ShmFanModuleData;
  28. static struct PrimaryMcuData *ShmPrimaryMcuData;
  29. static SelectGunInfo *ShmSelectGunInfo = NULL;
  30. static struct ChargingInfoData *pDcChargingInfo = NULL;
  31. static DcCommonInfo *ShmDcCommonData = NULL;
  32. //int CardReadFd = -1;
  33. short _currentPage = _PAGE_NONE;
  34. uint8_t _totalCount;
  35. uint8_t _showInformIndex = 0;
  36. float ChargeMaxPower_0 = 0;
  37. float ChargeMaxPower_1 = 0;
  38. bool _battery_display_ani = false;
  39. int _port;
  40. //char* pPortName = "/dev/ttyO2";
  41. char *pPortName = "/dev/ttyS3";
  42. char *moduleName = "DMT80480T070_09WT";
  43. bool is_show = false;
  44. bool is_stop = false;
  45. uint8_t _everyPageRollChange;
  46. uint8_t _btn_press = 0;
  47. short _btn_press_id = 0;
  48. uint8_t _btn_press_count = 0;
  49. int _Text_Running_Count = 1;
  50. int Battery_Test = 0;
  51. extern void UpdateLcmFunction(DcCommonInfo *ShmDcCommonData,int _lcmport);
  52. //==========================================
  53. // Open and Close RS232 and R/W
  54. //==========================================
  55. void AuthorizingStart(void)
  56. {
  57. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
  58. pSysInfo->AuthorizeFlag = YES;
  59. }
  60. void GetClockTime(struct timespec *_now_time, void *null)
  61. {
  62. clock_gettime(CLOCK_MONOTONIC, _now_time);
  63. }
  64. void StartSystemTimeoutDet(uint8_t flag)
  65. {
  66. if (pSysInfo->SystemTimeoutFlag != flag) {
  67. GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
  68. }
  69. pSysInfo->SystemTimeoutFlag = flag;
  70. }
  71. void StopSystemTimeoutDet(void)
  72. {
  73. GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
  74. pSysInfo->SystemTimeoutFlag = Timeout_None;
  75. }
  76. void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
  77. {
  78. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  79. if (gunIndex < pSysConfig->TotalConnectorCount) {
  80. if (pDcChargingInfo->TimeoutFlag != flag) {
  81. gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
  82. }
  83. pDcChargingInfo->TimeoutFlag = flag;
  84. }
  85. }
  86. void StopGunInfoTimeoutDet(uint8_t gunIndex)
  87. {
  88. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  89. if (gunIndex < pSysConfig->TotalConnectorCount) {
  90. pDcChargingInfo->TimeoutFlag = Timeout_None;
  91. }
  92. }
  93. unsigned long GetClockTimeoutValue(struct timespec _start_time)
  94. {
  95. struct timespec ts_end;
  96. unsigned long ret = 0;
  97. clock_gettime(CLOCK_MONOTONIC, &ts_end);
  98. ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
  99. return ret;
  100. }
  101. int CreateCommunicationLcmPort()
  102. {
  103. int fd;
  104. struct termios tios;
  105. fd = open(pPortName, O_RDWR);
  106. if (fd <= 0) {
  107. log_error("open /dev/ttyS3 NG ");
  108. return -1;
  109. }
  110. ioctl(fd, TCGETS, &tios);
  111. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  112. tios.c_lflag = 0;
  113. tios.c_iflag = 0;
  114. tios.c_oflag = 0;
  115. tios.c_cc[VMIN] = 0;
  116. tios.c_cc[VTIME] = (uint8_t) 5;
  117. tios.c_lflag = 0;
  118. tcflush(fd, TCIFLUSH);
  119. ioctl(fd, TCSETS, &tios);
  120. return fd;
  121. }
  122. void CloseCommunicationLcmPort()
  123. {
  124. close(_port);
  125. }
  126. void setSelGunWaitToAuthor(uint8_t curSel)
  127. {
  128. if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
  129. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
  130. log_info("setSelGunWaitToAuthor left");
  131. } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
  132. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
  133. log_info("setSelGunWaitToAuthor right");
  134. }
  135. }
  136. void confirmSelGun(uint8_t selGun)
  137. {
  138. if (selGun == LEFT_GUN_NUM) {
  139. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  140. //printf("confirmSelGun left");
  141. } else if (selGun == RIGHT_GUN_NUM) {
  142. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  143. //printf("confirmSelGun right");
  144. }
  145. //changeLcmPage(_PAGE_PLUGIN);
  146. //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
  147. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  148. }
  149. void GetDeviceInfoStatus(short address, uint8_t len)
  150. {
  151. uint8_t cmd[8];
  152. memset(cmd, 0x00, sizeof(cmd));
  153. uint8_t msg[11];
  154. memset(msg, 0x00, sizeof(msg));
  155. cmd[0] = CMD_TITLE_1;
  156. cmd[1] = CMD_TITLE_2;
  157. cmd[2] = 0x04;
  158. cmd[3] = CMD_MULTI_READ;
  159. cmd[4] = (address >> 8) & 0xff;
  160. cmd[5] = (address >> 0) & 0xff;
  161. cmd[6] = len;
  162. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  163. usleep(1000);
  164. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  165. }
  166. void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
  167. {
  168. int len = write(_port, cmd, cmdLen);
  169. if (len < sizeof(cmd)) {
  170. log_error("Write cmd to LCM Failure. ");
  171. }
  172. }
  173. void CheckIdlePress()
  174. {
  175. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  176. log_info("IDLE Enter Select Gun Page");
  177. }
  178. void CheckReturnPress()
  179. {
  180. int i;
  181. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  182. //pDcChargingInfo->SystemStatus = S_IDLE;
  183. StopSystemTimeoutDet();
  184. if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
  185. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE || pSysInfo->SystemPage == _PAGE_PLUGIN ) {
  186. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  187. }
  188. pDcChargingInfo->SystemStatus = S_IDLE;
  189. ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
  190. ShmDcCommonData->PreAuth_Result = 0;
  191. for(i=0;i<=30;i++) {
  192. if(ShmDcCommonData->PreAuth_Result != 0)
  193. break;
  194. sleep(1);
  195. }
  196. ShmDcCommonData->PreAuth_Result = 0;
  197. strcpy((char *)pSysConfig->UserId, "");
  198. return;
  199. }
  200. if ( pSysInfo->SystemPage == _PAGE_EXIT ) {
  201. pDcChargingInfo->SystemStatus = S_IDLE;
  202. pSysInfo->SystemPage = _PAGE_IDLE;
  203. return;
  204. }
  205. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  206. }
  207. void CheckStopPress()
  208. {
  209. is_stop = TRUE;
  210. //ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
  211. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
  212. pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_LEFT;
  213. else
  214. pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_RIGHT;
  215. }
  216. void CheckStopConfirmPress()
  217. {
  218. int result;
  219. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  220. pDcChargingInfo->SystemStatus = S_TERMINATING;
  221. pSysInfo->SystemPage = _PAGE_PAYING;
  222. is_stop = FALSE;
  223. ShmDcCommonData->StopCharge[pSysInfo->CurGunSelected] = TRUE;
  224. StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_FinalCost);
  225. /*
  226. ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
  227. ShmDcCommonData->PreAuth_Result = 0;
  228. */
  229. }
  230. void CheckStopCancelPress()
  231. {
  232. is_stop = FALSE;
  233. //ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
  234. pSysInfo->SystemPage = _PAGE_CHARGING;
  235. }
  236. void CheckConfirmGun(uint8_t gunIndex)
  237. {
  238. pSysInfo->CurGunSelected = gunIndex;
  239. pSysInfo->SystemPage = _PAGE_BILL;
  240. }
  241. void CheckDonateBill(uint8_t gunIndex)
  242. {
  243. if (gunIndex == LEFT_GUN_NUM) {
  244. pSysInfo->SystemPage = _PAGE_DONATE_LEFT;
  245. } else
  246. pSysInfo->SystemPage = _PAGE_DONATE_RIGHT;
  247. }
  248. void CheckDonateYes()
  249. {
  250. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  251. ShmDcCommonData->donate_flag[pSysInfo->CurGunSelected] = TRUE;
  252. }
  253. void CheckDonateNo()
  254. {
  255. pSysInfo->SystemPage = _PAGE_BILL;
  256. ShmDcCommonData->donate_flag[pSysInfo->CurGunSelected] = FALSE;
  257. }
  258. void CheckPayCreditCard()
  259. {
  260. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  261. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  262. confirmSelGun(pSysInfo->CurGunSelected);
  263. setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
  264. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  265. //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
  266. //
  267. AuthorizingStart();
  268. }
  269. }
  270. void CheckPayIcash()
  271. {
  272. }
  273. void CheckPayLinePay()
  274. {
  275. }
  276. void CheckTouchPress(short id)
  277. {
  278. GetDeviceInfoStatus(id,1);
  279. if (_btn_press >= 1 && _btn_press_id == id ) {
  280. _btn_press_count++;
  281. }
  282. if (_btn_press >= 1 && _btn_press_id == id && _btn_press_count >= 3) {
  283. ChangeDisplay2Value(id, 0);
  284. //log_info("Press id : 0x%04x",id);
  285. _btn_press_count = 0;
  286. switch (id) {
  287. case _Touch_Show_Left:
  288. if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
  289. log_info("Authorize Process can't select gun");
  290. return;
  291. }
  292. // Show log
  293. if(pSysInfo->CurGunSelected != LEFT_GUN_NUM) {
  294. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  295. pSysInfo->CurGunSelected = LEFT_GUN_NUM;
  296. if(pDcChargingInfo->SystemStatus == S_IDLE) {
  297. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  298. }
  299. log_info("LCM left Gun down...............................%x %x %x",
  300. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  301. }
  302. if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
  303. pSysInfo->SystemPage == _PAGE_PAYFAIL) {
  304. StopSystemTimeoutDet();
  305. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  306. }
  307. break;
  308. case _Touch_Show_Right:
  309. if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
  310. log_info("Authorize Process can't select gun");
  311. return;
  312. }
  313. // Show log
  314. if(pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
  315. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  316. pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
  317. if(pDcChargingInfo->SystemStatus == S_IDLE) {
  318. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  319. }
  320. log_info("LCM Right Gun down...............................%x %x %x",
  321. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  322. }
  323. if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
  324. pSysInfo->SystemPage == _PAGE_PAYFAIL) {
  325. StopSystemTimeoutDet();
  326. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  327. }
  328. break;
  329. case _Touch_Return:
  330. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE)
  331. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  332. CheckReturnPress();
  333. break;
  334. case _Touch_IDLE:
  335. CheckIdlePress();
  336. break;
  337. case _Touch_StopCharge:
  338. CheckStopPress();
  339. is_stop = TRUE;
  340. break;
  341. case _Touch_Stop_Confirm:
  342. CheckStopConfirmPress();
  343. is_stop = FALSE;
  344. break;
  345. case _Touch_Stop_Cancel:
  346. CheckStopCancelPress();
  347. is_stop = FALSE;
  348. break;
  349. case _Touch_Select_Left:
  350. CheckConfirmGun(LEFT_GUN_NUM);
  351. break;
  352. case _Touch_Select_Right:
  353. CheckConfirmGun(RIGHT_GUN_NUM);
  354. break;
  355. case _Touch_DonateBill:
  356. StopSystemTimeoutDet();
  357. CheckDonateBill(pSysInfo->CurGunSelected);
  358. break;
  359. case _Touch_DonateYes:
  360. CheckDonateYes();
  361. break;
  362. case _Touch_DonateNo:
  363. StartSystemTimeoutDet(Timeout_AddLine);
  364. CheckDonateNo();
  365. break;
  366. case _Touch_Pay_CreditCard:
  367. CheckPayCreditCard();
  368. break;
  369. case _Touch_Pay_Icash:
  370. CheckPayIcash();
  371. break;
  372. case _Touch_Pay_LinePay:
  373. CheckPayLinePay();
  374. break;
  375. } // switch
  376. } //if (_btn_press >= 3)
  377. }
  378. void CheckLCMPressed()
  379. {
  380. int i;
  381. pid_t Pid = fork();
  382. if ( Pid == 0 ) {
  383. while (1) {
  384. if (pSysInfo->SystemPage != _PAGE_SELECT_GUN) {
  385. CheckTouchPress(_Touch_Show_Left);
  386. CheckTouchPress(_Touch_Show_Right);
  387. }
  388. switch (pSysInfo->SystemPage) {
  389. case _PAGE_IDLE:
  390. CheckTouchPress(_Touch_IDLE);
  391. break;
  392. case _PAGE_SELECT_GUN:
  393. CheckTouchPress(_Touch_Select_Left);
  394. CheckTouchPress(_Touch_Select_Right);
  395. break;
  396. case _PAGE_BILL:
  397. CheckTouchPress(_Touch_Return);
  398. CheckTouchPress(_Touch_DonateBill);
  399. break;
  400. case _PAGE_ADD_FRIEND:
  401. CheckTouchPress(_Touch_Return);
  402. CheckTouchPress(_Touch_DonateBill);
  403. break;
  404. case _PAGE_DONATE_LEFT:
  405. case _PAGE_DONATE_RIGHT:
  406. CheckTouchPress(_Touch_Return);
  407. CheckTouchPress(_Touch_DonateYes);
  408. CheckTouchPress(_Touch_DonateNo);
  409. break;
  410. case _PAGE_SELECT_PAY:
  411. CheckTouchPress(_Touch_Return);
  412. CheckTouchPress(_Touch_Pay_CreditCard);
  413. break;
  414. case _PAGE_PLUGIN:
  415. CheckTouchPress(_Touch_Return);
  416. break;
  417. ///*
  418. case _PAGE_CHARGING:
  419. CheckTouchPress(_Touch_StopCharge);
  420. break;
  421. case _PAGE_AUTHORIZE:
  422. CheckTouchPress(_Touch_Return);
  423. break;
  424. case _PAGE_STOP_CONFIRM_LEFT:
  425. case _PAGE_STOP_CONFIRM_RIGHT:
  426. StopSystemTimeoutDet();
  427. CheckTouchPress(_Touch_Stop_Confirm);
  428. CheckTouchPress(_Touch_Stop_Cancel);
  429. break;
  430. case _PAGE_EXIT:
  431. CheckTouchPress(_Touch_Return);
  432. break;
  433. case _PAGE_AUTHORIZE_FAIL:
  434. CheckTouchPress(_Touch_Return);
  435. break;
  436. } // switch
  437. usleep(5000);
  438. } //while
  439. } // if pid
  440. log_info("Create LCM fork:%d",Pid);
  441. }
  442. void ReadMsgFromLcm(uint8_t *msg, uint8_t readLen)
  443. {
  444. read(_port, msg, readLen);
  445. // 5a : CMD_TITLE_1
  446. // a5 : CMD_TITLE_2
  447. // 5
  448. // 81 : CMD_WRITE
  449. // 3 : CMD_REGISTER
  450. // 2 : Data length
  451. // 0 : High byte
  452. // 1 : Low byte
  453. // printf("-------------------------------------------- \n");
  454. // printf("msg = %x \n", *msg); // A5
  455. // printf("msg = %x \n", *(msg + 1)); // 5A
  456. // printf("msg = %x \n", *(msg + 2)); // Len : [3] ~ [6] + Data Len
  457. // printf("msg = %x \n", *(msg + 3)); // cmd : 0x83
  458. // printf("msg = %x \n", *(msg + 4)); // addr : H
  459. // printf("msg = %x \n", *(msg + 5)); // addr : L
  460. // printf("msg = %x \n", *(msg + 6)); // Data Len
  461. //
  462. // printf("msg = %x \n", *(msg + 7));
  463. // printf("msg = %x \n", *(msg + 8));
  464. // printf("msg = %x \n", *(msg + 9));
  465. // printf("msg = %x \n", *(msg + 10));
  466. // printf("msg = %x \n", *(msg + 11));
  467. // printf("msg = %x \n", *(msg + 12));
  468. // printf("msg = %x \n", *(msg + 13));
  469. // printf("msg = %x \n", *(msg + 14));
  470. /*
  471. for(uint8_t i = 0 ; i<readLen+3; i++) {
  472. log_info("Read data[%d]:0x%x",i,msg[i]);
  473. }*/
  474. if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
  475. {
  476. if(*(msg + 3) == CMD_WRITE)
  477. {
  478. switch (*(msg + 4))
  479. {
  480. case CMD_REGISTER:
  481. {
  482. // 頁面
  483. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  484. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  485. _currentPage = *(msg + 7);
  486. log_info("Current Page:%d",_currentPage);
  487. // if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
  488. // printf("_currentPage = %d \n", _currentPage);
  489. }
  490. break;
  491. }
  492. }
  493. else if (*(msg + 3) == CMD_MULTI_READ)
  494. {
  495. short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
  496. if(strcmp((char *)pSysInfo->LcmHwRev, "") != EQUAL)
  497. strcpy((char *)pSysInfo->LcmHwRev, moduleName);
  498. if (key == 0x0014)
  499. _currentPage = *(msg + 8);
  500. if ( key >= _Touch_IDLE && key <=_Touch_Pay_LinePay ) {
  501. _btn_press_id = key;
  502. _btn_press = *(msg + 8);
  503. }
  504. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  505. // {
  506. // case BUTTON_GUN_INDEX:
  507. // {
  508. // // 當前選的槍號
  509. // _curGunIndex = (*(msg + 8));
  510. // }
  511. // break;
  512. // }
  513. }
  514. }
  515. }
  516. void GetHrFormTimeString(char* time,char* hr)
  517. {
  518. //char tm[] = "2021-12-06 17:29:08:084";
  519. for(int i = 0 ; i < 2 ; i++) {
  520. hr[i] = time[i+11];
  521. }
  522. if( atoi(hr) == NULL ) {
  523. strcmp(hr,"");
  524. }
  525. }
  526. void GetMinFormTimeString(char* time,char* min)
  527. {
  528. //char tm[] = "2021-12-06 17:29:08:084";
  529. for(int i = 0 ; i < 2 ; i++) {
  530. min[i] = time[i+14];
  531. }
  532. if( atoi(min) == NULL || atoi(min) > 60) {
  533. strcmp(min,"");
  534. }
  535. }
  536. //================================================
  537. // Function
  538. //================================================
  539. void ChangeToOtherPage(short newPage)
  540. {
  541. uint8_t cmd[10];
  542. memset(cmd, 0x00, sizeof(cmd));
  543. uint8_t msg[9];
  544. memset(msg, 0x00, sizeof(msg));
  545. cmd[0] = CMD_TITLE_1;
  546. cmd[1] = CMD_TITLE_2;
  547. cmd[2] = 0x07;
  548. cmd[3] = 0x82;
  549. cmd[4] = 0x00;
  550. cmd[5] = 0x84;
  551. cmd[6] = 0x5A;
  552. cmd[7] = 0x01;
  553. cmd[8] = newPage >> 8;
  554. cmd[9] = newPage & 0x00FF;
  555. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  556. usleep(5000);
  557. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  558. }
  559. void ChangeBackLight(bool islight)
  560. {
  561. uint8_t value = 0x01;
  562. uint8_t msg[9];
  563. memset(msg, 0x00, sizeof(msg));
  564. // 0x00 ~ 0x40
  565. if (islight)
  566. {
  567. value = 0x20;
  568. }
  569. uint8_t cmd[7];
  570. memset(cmd, 0x00, sizeof(cmd));
  571. cmd[0] = CMD_TITLE_1;
  572. cmd[1] = CMD_TITLE_2;
  573. cmd[2] = 0x03;
  574. cmd[3] = CMD_READ;
  575. cmd[4] = CMD_BACKLIGHT;
  576. cmd[5] = value;
  577. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  578. usleep(10000);
  579. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  580. }
  581. void GetCurrentPage()
  582. {
  583. uint8_t cmd[7];
  584. memset(cmd, 0x00, sizeof(cmd));
  585. uint8_t msg[9];
  586. memset(msg, 0x00, sizeof(msg));
  587. cmd[0] = CMD_TITLE_1;
  588. cmd[1] = CMD_TITLE_2;
  589. cmd[2] = 0x04; // 底下總長度
  590. cmd[3] = 0x83;
  591. cmd[4] = 0x00;
  592. cmd[5] = 0x14;
  593. cmd[6] = 0x01;
  594. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  595. usleep(5000);
  596. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  597. }
  598. void DisplayValueToLcm(short address, uint8_t *data, uint8_t len)
  599. {
  600. uint8_t cmd[256];
  601. memset(cmd, 0x00, sizeof(cmd));
  602. uint8_t msg[9];
  603. memset(msg, 0x00, sizeof(msg));
  604. cmd[0] = CMD_TITLE_1;
  605. cmd[1] = CMD_TITLE_2;
  606. cmd[2] = 0x03 + len;
  607. cmd[3] = CMD_MULTI_WRITE;
  608. cmd[4] = address >> 8;
  609. cmd[5] = address & 0x00FF;
  610. for(uint8_t count = 0; count < len; count++)
  611. {
  612. cmd[6 + count] = *(data + count);
  613. }
  614. WriteCmdToLcm(cmd, cmd[2] + 3);
  615. usleep(10000);
  616. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  617. }
  618. void ChangeDisplay2Value(short address, short value)
  619. {
  620. uint8_t data[2];
  621. data[0] = value >> 8;
  622. data[1] = value & 0x00FF;
  623. //log_info("Addr:0x%x, value:%d",address,value);
  624. DisplayValueToLcm(address, data, sizeof(data));
  625. }
  626. //================================================
  627. // Warning process
  628. //================================================
  629. void string2ByteArray(uint8_t *input, uint8_t *output)
  630. {
  631. int loop;
  632. int i;
  633. loop = 0;
  634. i = 0;
  635. while (input[loop] != '\0') {
  636. output[i++] = input[loop++];
  637. }
  638. output[loop] = '\0';
  639. }
  640. void RefreshProgressAnimation()
  641. {
  642. _everyPageRollChange >= 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  643. }
  644. //================================================
  645. // Change current page
  646. //================================================
  647. void ChangeCurPage()
  648. {
  649. //log_info("cur = %d ,system = %d, lcm = %d ",_currentPage, pSysInfo->SystemPage, pSysInfo->PageIndex);
  650. pSysInfo->PageIndex = pSysInfo->SystemPage;
  651. if (_currentPage != pSysInfo->PageIndex) {
  652. switch (pSysInfo->SystemPage) {
  653. case _PAGE_AUTHORIZE:
  654. break;
  655. case _PAGE_PLUGIN:
  656. break;
  657. case _PAGE_PRECHARGE:
  658. break;
  659. case _PAGE_CHARGING:
  660. is_stop = false;
  661. break;
  662. case _PAGE_COMPLETE:
  663. break;
  664. }
  665. _currentPage = pSysInfo->PageIndex;
  666. //log_info("Chagne Page:%d",pSysInfo->PageIndex);
  667. ChangeToOtherPage(pSysInfo->PageIndex);
  668. }
  669. }
  670. /*
  671. * View Page
  672. *
  673. */
  674. unsigned long GetTimeoutValue(struct timeval _sour_time)
  675. {
  676. struct timeval _end_time;
  677. gettimeofday(&_end_time, NULL);
  678. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  679. }
  680. void showGunWorkingType()
  681. {
  682. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
  683. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  684. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  685. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  686. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_On);
  687. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  688. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  689. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_On);
  690. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  691. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_On);
  692. }
  693. // Set Right Gun
  694. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  695. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  696. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  697. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  698. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  699. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  700. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  701. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  702. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  703. }
  704. } else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM){
  705. // Left Gun
  706. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  707. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  708. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  709. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  710. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  711. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  712. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  713. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  714. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  715. }
  716. // Right Gun
  717. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  718. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  719. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  720. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_On);
  721. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  722. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  723. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_On);
  724. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  725. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_On);
  726. }
  727. }
  728. }
  729. void ClearQrCode()
  730. {
  731. char cmd[200];
  732. memset(cmd,0,200);
  733. DisplayValueToLcm(_QRCode_AddLine, cmd, 200);
  734. }
  735. void ChangeQrCode_Idle(char *input)
  736. {
  737. char cmd[256];
  738. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  739. // https://nhoatcc.lineapid.tw/web/tologin?sn=ABC123&cid=2
  740. memset(cmd,0,256);
  741. int len = sprintf(cmd,"https://nhoatcc.lineapid.tw/web/tologin?sn=%s&cid=%d",input,ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
  742. //log_info("QR Code:URL:%s",cmd);
  743. if (pSysInfo->SystemPage == _PAGE_BILL)
  744. DisplayValueToLcm(_QRCode_AddLine, cmd, len+1);
  745. }
  746. /*
  747. void ChangeRemainTime(int sec)
  748. {
  749. int h, m, s;
  750. uint8_t cmd[10];
  751. uint8_t value[10];
  752. memset(cmd, 0x00, sizeof(cmd));
  753. // srand(time(NULL));
  754. // int min = 0;
  755. // int max = 65536;
  756. // sec = rand() % (max - min + 1) + min;
  757. h = (sec / 3600);
  758. m = (sec - (3600 * h)) / 60;
  759. s = (sec - (3600 * h) - (m * 60));
  760. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  761. string2ByteArray(value, cmd);
  762. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  763. }
  764. */
  765. void ShowSelectGun()
  766. {
  767. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  768. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  769. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  770. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS1);
  771. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  772. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  773. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS2);
  774. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  775. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CHAdeMo);
  776. }
  777. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  778. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  779. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  780. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS1);
  781. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  782. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  783. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS2);
  784. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  785. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CHAdeMo);
  786. }
  787. }
  788. void ChangeChargingPowerValue(float pow)
  789. {
  790. uint8_t cmd[10];
  791. uint8_t value[10];
  792. memset(cmd, 0x00, sizeof(cmd));
  793. sprintf((char *) value, "%d",(int)pow);
  794. string2ByteArray(value, cmd);
  795. DisplayValueToLcm(_String_ChargePower, cmd, sizeof(cmd));
  796. }
  797. void ChangeChargingFeeValue(float fee)
  798. {
  799. uint8_t cmd[10];
  800. uint8_t value[10];
  801. memset(cmd, 0x00, sizeof(cmd));
  802. sprintf((char *) value, "%d", (int)fee);
  803. string2ByteArray(value, cmd);
  804. DisplayValueToLcm(_String_Money, cmd, sizeof(cmd));
  805. }
  806. void ChangeCarBonValue(float data)
  807. {
  808. uint8_t cmd[10];
  809. uint8_t value[10];
  810. float _carbon = 0;
  811. memset(cmd, 0x00, sizeof(cmd));
  812. _carbon = (data*9)/10*2.36 - data*0.637;
  813. //log_info("Carbon:%d",(int)_carbon);
  814. sprintf((char *) value, "%d", (int)_carbon);
  815. string2ByteArray(value, cmd);
  816. DisplayValueToLcm(_String_Carbon, cmd, sizeof(cmd));
  817. }
  818. void ChangeChargingEnergyValue(float energy)
  819. {
  820. uint8_t cmd[10];
  821. uint8_t value[10];
  822. memset(cmd, 0x00, sizeof(cmd));
  823. if (energy >= 0.05) {
  824. energy -= 0.05;
  825. }
  826. if (energy < 0 )
  827. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0);
  828. else if (energy > 100)
  829. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0+100);
  830. else
  831. ChangeDisplay2Value(_Icon_ChargeBar,(int)energy+_TCC_Charging_Bar0);
  832. if (energy < 10)
  833. sprintf((char *) value, "%.1f", energy);
  834. else
  835. sprintf((char *) value, "%d", (int)energy);
  836. string2ByteArray(value, cmd);
  837. DisplayValueToLcm(_Strting_Energy, cmd, sizeof(cmd));
  838. }
  839. uint8_t _battery_display_count = 0;
  840. void ChangeBattMapAndValue(int soc)
  841. {
  842. int i = (soc*36)/100;
  843. uint8_t cmd[5];
  844. uint8_t value[5];
  845. _battery_display_count++;
  846. if (_battery_display_count == 3 ) {
  847. if (_battery_display_ani == 0)
  848. _battery_display_ani= TRUE;
  849. else
  850. _battery_display_ani= FALSE ;
  851. _battery_display_count = 0;
  852. }
  853. if (pSysInfo->SystemPage == _PAGE_CHARGING) {
  854. if (i>=36)
  855. ChangeDisplay2Value(_Icon_ChargeCircle,_TCC_Charging_Circle0+36);
  856. else {
  857. if (_battery_display_ani) {
  858. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i);
  859. } else {
  860. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i+1);
  861. }
  862. }
  863. } else if (pSysInfo->SystemPage == _PAGE_COMPLETE)
  864. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  865. else
  866. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  867. memset(cmd, 0x00, sizeof(cmd));
  868. memset(value, 0x00, sizeof(value));
  869. sprintf((char *)value, "%d", soc);
  870. string2ByteArray(value, cmd);
  871. DisplayValueToLcm(_String_Battery, cmd, sizeof(cmd));
  872. }
  873. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  874. {
  875. struct timeval _end_time;
  876. gettimeofday(&_end_time, NULL);
  877. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  878. }
  879. void ChangeTimeValue(int time)
  880. {
  881. uint8_t cmd[6];
  882. uint8_t value[6];
  883. memset(cmd, 0x00, sizeof(cmd));
  884. sprintf((char *) value, "%d", time);
  885. string2ByteArray(value, cmd);
  886. DisplayValueToLcm(_String_ChargeTime, cmd, sizeof(cmd));
  887. }
  888. void changeWeatherValue(int _weather)
  889. {
  890. switch (_weather) {
  891. case _WEATHER_TYPE_SUN:
  892. ChangeDisplay2Value(_Icon_Weather,_TCC_Sun);
  893. break;
  894. case _WEATHER_TYPE_CLOUDY:
  895. ChangeDisplay2Value(_Icon_Weather,_TCC_Cloudy);
  896. break;
  897. case _WEATHER_TYPE_RAIN:
  898. ChangeDisplay2Value(_Icon_Weather,_TCC_Rain);
  899. break;
  900. case _WEATHER_TYPE_THUNDER:
  901. ChangeDisplay2Value(_Icon_Weather,_TCC_Thunder);
  902. break;
  903. case _WEATHER_TYPE_SNOW:
  904. ChangeDisplay2Value(_Icon_Weather,_TCC_Snow);
  905. break;
  906. case _WEATHER_TYPE_FOG:
  907. ChangeDisplay2Value(_Icon_Weather,_TCC_Fog);
  908. break;
  909. }
  910. }
  911. void changeWeekValue(int _week)
  912. {
  913. time_t t = time(NULL);
  914. struct tm *now = localtime(&t);
  915. _week = now->tm_wday;
  916. if (_week == 0 )
  917. _week = 7;
  918. ChangeDisplay2Value(_Icon_Week,_week);
  919. }
  920. void changeDegreeValue(int _degree)
  921. {
  922. char value[16];
  923. memset(value, 0x00, sizeof(value));
  924. sprintf((char *)value,"%d",_degree);
  925. DisplayValueToLcm(_String_Tempture, (uint8_t *)value, sizeof(value));
  926. }
  927. void changeDateValue(char* _date)
  928. {
  929. char value[16];
  930. memset(value, 0x00, sizeof(value));
  931. sprintf((char *)value,"%s",_date);
  932. DisplayValueToLcm(_String_Date, (uint8_t *)value, sizeof(value));
  933. }
  934. void changeLocationValue(int _location)
  935. {
  936. //_location+=1000;
  937. //log_info("location:%d",_location);
  938. ChangeDisplay2Value(_Icon_Location,(short)_location);
  939. }
  940. int old_money = 0;
  941. int ClearQR_flag[2];
  942. void ProcessPageInfo()
  943. {
  944. // Show Gun Working and Type
  945. if (pSysInfo->SystemPage == _PAGE_IDLE) {
  946. changeWeatherValue(ShmDcCommonData->WeatherID);
  947. changeWeekValue(0);
  948. changeDegreeValue((int)ShmDcCommonData->Temperature);
  949. changeDateValue(&ShmDcCommonData->PresentTime[0]);
  950. changeLocationValue(ShmDcCommonData->Location);
  951. return;
  952. }
  953. if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
  954. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  955. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  956. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  957. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  958. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  959. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  960. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  961. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  962. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  963. }
  964. // Set Right Gun
  965. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  966. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  967. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  968. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  969. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  970. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  971. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  972. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  973. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  974. }
  975. return;
  976. }
  977. showGunWorkingType();
  978. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  979. if (pSysInfo->CurGunSelected == i) {
  980. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  981. switch (pSysInfo->SystemPage) {
  982. case _PAGE_IDLE:
  983. break;
  984. case _PAGE_SELECT_PAY:
  985. if (ShmDcCommonData->donate_flag[i] == TRUE) {
  986. ChangeDisplay2Value(_Icon_WordAddFriend,_ICON_Empty);
  987. } else
  988. ChangeDisplay2Value(_Icon_WordAddFriend,_TCC_SelectPayMode);
  989. StartSystemTimeoutDet(Timeout_SelectPayMode);
  990. break;
  991. case _PAGE_SELECT_GUN:
  992. ShowSelectGun();
  993. ClearQR_flag[i] = FALSE;
  994. break;
  995. case _PAGE_BILL:
  996. if(ClearQR_flag[i] == FALSE) {
  997. ClearQrCode();
  998. ClearQR_flag[i] = TRUE;
  999. }
  1000. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1001. break;
  1002. case _PAGE_AUTHORIZE:
  1003. /*
  1004. int card_result = CreditCardPreAuth(CardReadFd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
  1005. if (card_result > 0 ) {
  1006. strcpy((char *)pSysConfig->UserId, (char *)ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo);
  1007. } else if (card_result < 0) {
  1008. pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
  1009. }*/
  1010. //ChangeDisplay2Value(_Icon_Precharge,0);
  1011. //ChangeDisplay2Value(_Icon_Precharge,1);
  1012. if (ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] == TRUE &&
  1013. ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] != TRUE) {
  1014. ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
  1015. ShmDcCommonData->PreAuth_Result = 0;
  1016. sleep(3);
  1017. pSysInfo->SystemPage = _PAGE_SENSING;
  1018. }
  1019. _Text_Running_Count = 1;
  1020. break;
  1021. case _PAGE_PLUGIN:
  1022. _everyPageRollChange = 0;
  1023. break;
  1024. case _PAGE_PRECHARGE:
  1025. //ChangeDisplay2Value(_Icon_Precharge,1);
  1026. RefreshProgressAnimation();
  1027. if (_everyPageRollChange == 0) {
  1028. ChangeDisplay2Value(_Icon_Precharge,_Text_Running_Count);
  1029. _Text_Running_Count >= 24 ? _Text_Running_Count = 24 : _Text_Running_Count++;
  1030. }
  1031. break;
  1032. case _PAGE_CHARGING:
  1033. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  1034. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1035. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  1036. } else {
  1037. ChangeChargingPowerValue(0);
  1038. }
  1039. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1040. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1041. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1042. } else {
  1043. ChangeChargingEnergyValue(0);
  1044. }
  1045. if ( pDcChargingInfo->ChargingFee >= 0) {
  1046. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  1047. }
  1048. if (pDcChargingInfo->RemainChargingDuration >= 0 &&
  1049. pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
  1050. ChangeTimeValue(pDcChargingInfo->RemainChargingDuration/60);
  1051. } else {
  1052. ChangeTimeValue(0);
  1053. }
  1054. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1055. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1056. break;
  1057. case _PAGE_COMPLETE:
  1058. case _PAGE_PAYFAIL:
  1059. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1060. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1061. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1062. } else {
  1063. ChangeChargingEnergyValue(0);
  1064. }
  1065. if ( ShmDcCommonData->finalcost[i] >= 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
  1066. StopGunInfoTimeoutDet(i);
  1067. ChangeChargingFeeValue(ShmDcCommonData->finalcost[i]);
  1068. //ShmDcCommonData->finalcost_flag[i] = FALSE;
  1069. }
  1070. ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
  1071. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1072. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1073. break;
  1074. case _PAGE_PLUGOUT:
  1075. /*
  1076. if (pSysConfig->isQRCode) {
  1077. if (pSysConfig->QRCodeMadeMode == NO) {
  1078. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  1079. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1080. } else {
  1081. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  1082. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  1083. }
  1084. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1085. }*/
  1086. break;
  1087. case _PAGE_PAYING:
  1088. break;
  1089. }
  1090. }
  1091. }
  1092. }
  1093. void ChangeWarningFunc()
  1094. {
  1095. uint8_t cmd[7] = {0};
  1096. uint8_t i = 0;
  1097. //uint8_t j = 0;
  1098. //log_info("ChangeWarningFunc ");
  1099. // 最多一次五筆
  1100. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  1101. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  1102. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1103. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  1104. log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  1105. memset(cmd, 0x00, sizeof(cmd));
  1106. if ((i) >= 5) {
  1107. break;
  1108. }
  1109. //error code
  1110. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  1111. DisplayValueToLcm(_Strting_Warming0 + ((i) * 0x10), cmd, sizeof(cmd));
  1112. //警告標示
  1113. memset(cmd, 0x00, sizeof(cmd));
  1114. cmd[0] = 0x00;
  1115. cmd[1] = 1;
  1116. DisplayValueToLcm(_Icon_Warming0 + ((i) * 2), cmd, 2);
  1117. }
  1118. memset(cmd, 0x00, sizeof(cmd));
  1119. for (; i < 5; i++) {
  1120. DisplayValueToLcm(_Strting_Warming0 + ((i) * 0x10), cmd, sizeof(cmd));
  1121. DisplayValueToLcm(_Icon_Warming0 + ((i) * 2), cmd, 2);
  1122. }
  1123. }
  1124. void ShowCabientVersionDefaultText()
  1125. {
  1126. char value[16];
  1127. memset(value, 0x00, sizeof(value));
  1128. sprintf((char *)value,"%s","Cabient:");
  1129. DisplayValueToLcm(_Version_Cabient_Name_Text, (uint8_t *)value, sizeof(value));
  1130. sprintf((char *)value,"%s","BootLoader:");
  1131. DisplayValueToLcm(_Version_Cabient_BootLoader_Text, (uint8_t *)value, sizeof(value));
  1132. sprintf((char *)value,"%s","Kernel Fw:");
  1133. DisplayValueToLcm(_Version_Cabient_Kernel_Text, (uint8_t *)value, sizeof(value));
  1134. sprintf((char *)value,"%s","CSU Fw:");
  1135. DisplayValueToLcm(_Version_Cabient_CSU_Text, (uint8_t *)value, sizeof(value));
  1136. sprintf((char *)value,"%s","Priamry Fw:");
  1137. DisplayValueToLcm(_Version_Cabient_Priamry_Text, (uint8_t *)value, sizeof(value));
  1138. sprintf((char *)value,"%s","Relay(0) Fw:");
  1139. DisplayValueToLcm(_Version_Cabient_Relay0_Text, (uint8_t *)value, sizeof(value));
  1140. sprintf((char *)value,"%s","Relay(1) Fw:");
  1141. DisplayValueToLcm(_Version_Cabient_Relay1_Text, (uint8_t *)value, sizeof(value));
  1142. sprintf((char *)value,"%s","Fan Fw:");
  1143. DisplayValueToLcm(_Version_Cabient_Fan_Text, (uint8_t *)value, sizeof(value));
  1144. sprintf((char *)value,"%s","IP Addr:");
  1145. DisplayValueToLcm(_Version_Cabient_IPAddr_Text, (uint8_t *)value, sizeof(value));
  1146. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number <= 12) {
  1147. sprintf((char *)value,"%s","Primary");
  1148. DisplayValueToLcm(_Version_Cabient_Primary_Text, (uint8_t *)value, sizeof(value));
  1149. sprintf((char *)value,"%s","Secondary");
  1150. DisplayValueToLcm(_Version_Cabient_Secondary_Text, (uint8_t *)value, sizeof(value));
  1151. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  1152. sprintf((char *)value,"PSU(%d):",i+1);
  1153. DisplayValueToLcm(_Version_Cabient_PSU1_Text+i*0x10, (uint8_t *)value, sizeof(value));
  1154. }
  1155. }
  1156. }
  1157. void ShowDispenserVersionDefautlText()
  1158. {
  1159. char value[16];
  1160. memset(value, 0x00, sizeof(value));
  1161. sprintf((char *)value,"%s","Dispenser:");
  1162. DisplayValueToLcm(_Version_Dispenser_Name_Text, (uint8_t *)value, sizeof(value));
  1163. sprintf((char *)value,"%s","BootLoader:");
  1164. DisplayValueToLcm(_Version_Dispenser_BootLoader_Text, (uint8_t *)value, sizeof(value));
  1165. sprintf((char *)value,"%s","Kernel Fw:");
  1166. DisplayValueToLcm(_Version_Dispenser_Kernel_Text, (uint8_t *)value, sizeof(value));
  1167. sprintf((char *)value,"%s","CSU Fw:");
  1168. DisplayValueToLcm(_Version_Dispenser_CSU_Text, (uint8_t *)value, sizeof(value));
  1169. sprintf((char *)value,"%s","Relay Fw:");
  1170. DisplayValueToLcm(_Version_Dispenser_Relay_Text, (uint8_t *)value, sizeof(value));
  1171. sprintf((char *)value,"%s","Fan Fw:");
  1172. DisplayValueToLcm(_Version_Dispenser_Fan_Text, (uint8_t *)value, sizeof(value));
  1173. sprintf((char *)value,"%s","Prim Fw:");
  1174. DisplayValueToLcm(_Version_Dispenser_Priamry_Text, (uint8_t *)value, sizeof(value));
  1175. sprintf((char *)value,"%s","LCM Hw:");
  1176. DisplayValueToLcm(_Version_Dispenser_LCM_Text, (uint8_t *)value, sizeof(value));
  1177. sprintf((char *)value,"%s","LED Fw:");
  1178. DisplayValueToLcm(_Version_Dispenser_LED_Text, (uint8_t *)value, sizeof(value));
  1179. sprintf((char *)value,"%s","Connector(0):");
  1180. DisplayValueToLcm(_Version_Dispenser_Connector0_Text, (uint8_t *)value, sizeof(value));
  1181. sprintf((char *)value,"%s","Connector(1):");
  1182. DisplayValueToLcm(_Version_Dispenser_Connector1_Text, (uint8_t *)value, sizeof(value));
  1183. sprintf((char *)value,"%s","IP Addr:");
  1184. DisplayValueToLcm(_Version_Dispenser_IPAddr_Text, (uint8_t *)value, sizeof(value));
  1185. }
  1186. void ShowCabientVersion()
  1187. {
  1188. char value[16];
  1189. memset(value, 0x00, sizeof(value));
  1190. sprintf((char *)value,"%s",ShmDcCommonData->CabinetModelName);
  1191. DisplayValueToLcm(_Version_Cabient_Model_value, (uint8_t *)value, sizeof(value));
  1192. sprintf((char *)value,"%s",ShmDcCommonData->CabinetBoolLoaderVersion);
  1193. DisplayValueToLcm(_Version_Cabient_BootLoader_value, (uint8_t *)value, sizeof(value));
  1194. sprintf((char *)value,"%s",ShmDcCommonData->CabinetKernelVersion);
  1195. DisplayValueToLcm(_Version_Cabient_Kernel_value, (uint8_t *)value, sizeof(value));
  1196. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRFSystemVersion);
  1197. DisplayValueToLcm(_Version_Cabient_CSU_value, (uint8_t *)value, sizeof(value));
  1198. sprintf((char *)value,"%s",ShmDcCommonData->CabinetPrimaryVersion);
  1199. DisplayValueToLcm(_Version_Cabient_Priamry_value, (uint8_t *)value, sizeof(value));
  1200. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay0Version);
  1201. DisplayValueToLcm(_Version_Cabient_Relay0_value, (uint8_t *)value, sizeof(value));
  1202. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay1Version);
  1203. DisplayValueToLcm(_Version_Cabient_Relay1_value, (uint8_t *)value, sizeof(value));
  1204. sprintf((char *)value,"%s",ShmDcCommonData->CabinetFanVersion);
  1205. DisplayValueToLcm(_Version_Cabient_Fan_value, (uint8_t *)value, sizeof(value));
  1206. sprintf((char *)value,"%s",ShmDcCommonData->CabinetIPAddr);
  1207. DisplayValueToLcm(_Version_Cabient_IPAddr_value, (uint8_t *)value, sizeof(value));
  1208. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number < 12) {
  1209. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  1210. if (i>=6) {
  1211. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].DCVersion);
  1212. DisplayValueToLcm(_Version_Cabient_PSU_Prim7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  1213. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].FPCVersion);
  1214. DisplayValueToLcm(_Version_Cabient_PSU_Sec7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  1215. continue;
  1216. }
  1217. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].DCVersion);
  1218. DisplayValueToLcm(_Version_Cabient_PSU_Prim1_value+i*0x10, (uint8_t *)value, sizeof(value));
  1219. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].FPCVersion);
  1220. DisplayValueToLcm(_Version_Cabient_PSU_Sec1_value+i*0x10, (uint8_t *)value, sizeof(value));
  1221. }
  1222. }
  1223. }
  1224. void ShowDispenserVersion()
  1225. {
  1226. char value[32];
  1227. memset(value, 0x00, sizeof(value));
  1228. sprintf((char *)value,"%s",pSysConfig->ModelName);
  1229. DisplayValueToLcm(_Version_Dispenser_Model_value, (uint8_t *)value, sizeof(value));
  1230. sprintf((char *)value,"%s",pSysInfo->CsuBootLoadFwRev);
  1231. DisplayValueToLcm(_Version_Dispenser_BootLoader_value, (uint8_t *)value, sizeof(value));
  1232. sprintf((char *)value,"%s",pSysInfo->CsuKernelFwRev);
  1233. DisplayValueToLcm(_Version_Dispenser_Kernel_value, (uint8_t *)value, sizeof(value));
  1234. sprintf((char *)value,"%s",pSysInfo->CsuRootFsFwRev);
  1235. DisplayValueToLcm(_Version_Dispenser_CSU_value, (uint8_t *)value, sizeof(value));
  1236. sprintf((char *)value,"%s",pSysInfo->RelayModuleFwRev);
  1237. DisplayValueToLcm(_Version_Dispenser_Relay_value, (uint8_t *)value, sizeof(value));
  1238. sprintf((char *)value,"%s",pSysInfo->FanModuleFwRev);
  1239. DisplayValueToLcm(_Version_Dispenser_Fan_value, (uint8_t *)value, sizeof(value));
  1240. sprintf((char *)value,"%s",pSysInfo->CsuPrimFwRev);
  1241. DisplayValueToLcm(_Version_Dispenser_Priamry_value, (uint8_t *)value, sizeof(value));
  1242. sprintf((char *)value,"%s",pSysInfo->LcmHwRev);
  1243. DisplayValueToLcm(_Version_Dispenser_LCM_value, (uint8_t *)value, sizeof(value));
  1244. sprintf((char *)value,"%s",pSysInfo->LedModuleFwRev);
  1245. DisplayValueToLcm(_Version_Dispenser_LED_value, (uint8_t *)value, sizeof(value));
  1246. sprintf((char *)value,"%s",pSysInfo->Connector1FwRev);
  1247. DisplayValueToLcm(_Version_Dispenser_Connector0_value, (uint8_t *)value, sizeof(value));
  1248. sprintf((char *)value,"%s",pSysInfo->Connector2FwRev);
  1249. DisplayValueToLcm(_Version_Dispenser_Connector1_value, (uint8_t *)value, sizeof(value));
  1250. sprintf((char *)value,"%s",pSysConfig->Eth0Interface.EthIpAddress);
  1251. DisplayValueToLcm(_Version_Dispenser_IPAddr_value, (uint8_t *)value, sizeof(value));
  1252. }
  1253. /*
  1254. void InformationShow()
  1255. {
  1256. is_show = true;
  1257. if (_showInformIndex == 0 ) {
  1258. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  1259. } else {
  1260. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  1261. ShowDispenserVersion();
  1262. }
  1263. }
  1264. */
  1265. void DefautLayOut()
  1266. {
  1267. int i;
  1268. for (i = 0 ; i <= 0x5C ; i+=2 ) {
  1269. ChangeDisplay2Value(0x1000+i,1);
  1270. if (i==0x28 || i ==0x2A)
  1271. continue;
  1272. }
  1273. ChangeDisplay2Value(_Icon_MobilePay,0);
  1274. ChangeDisplay2Value(_Icon_CardPay,0);
  1275. ChangeDisplay2Value(0x5000,1);
  1276. ShowSelectGun();
  1277. }
  1278. /*
  1279. static int InitialRfidPort(void)
  1280. {
  1281. int fd = open(rfidPortName, O_RDWR);
  1282. struct termios tios;
  1283. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1284. if (fd != FAIL) {
  1285. ioctl (fd, TCGETS, &tios);
  1286. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  1287. tios.c_lflag = 0;
  1288. tios.c_iflag = 0;
  1289. tios.c_oflag = 0;
  1290. tios.c_cc[VMIN] = 0;
  1291. tios.c_cc[VTIME] = (uint8_t) 1;
  1292. tios.c_lflag = 0;
  1293. tcflush(fd, TCIFLUSH);
  1294. ioctl(fd, TCSETS, &tios);
  1295. }
  1296. if (fd < 0) {
  1297. pAlarmCode->AlarmEvents.bits.RfidModuleCommFail = 1;
  1298. }
  1299. return fd;
  1300. }
  1301. */
  1302. int main(void)
  1303. {
  1304. bool defaulttext = false;
  1305. if (CreateAllCsuShareMemory() == FAIL) {
  1306. log_error("create share memory error");
  1307. return FAIL;
  1308. }
  1309. MappingGunChargingInfo("LCM Control Task");
  1310. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1311. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1312. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1313. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  1314. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1315. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1316. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1317. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  1318. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  1319. _port = CreateCommunicationLcmPort();
  1320. uint8_t changeWarningPriority = 0;
  1321. uint8_t curWarningCount = 255;
  1322. ChangeBackLight(true);
  1323. _totalCount = pSysConfig->TotalConnectorCount;
  1324. _everyPageRollChange = 0;
  1325. //Initialization();
  1326. //printf("_LCM_COMPLETE ");
  1327. //ChangeToOtherPage(_LCM_COMPLETE);
  1328. DefautLayOut();
  1329. //return 0;
  1330. //uint8_t index = 1;
  1331. int result = 0;
  1332. ShmDcCommonData->PSU_Number = 12;
  1333. /*
  1334. CardReadFd = InitialRfidPort();
  1335. if (CardReadFd <0) {
  1336. log_info("Card Read Port open fail!");
  1337. }*/
  1338. CheckLCMPressed();
  1339. while (_port != -1) {
  1340. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  1341. GetCurrentPage();
  1342. sleep(1);
  1343. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1344. } else {
  1345. UpdateLcmFunction(ShmDcCommonData,_port);
  1346. ///*
  1347. // Warning 處理
  1348. if (curWarningCount != pSysWarning->WarningCount) {
  1349. changeWarningPriority = 0;
  1350. pSysWarning->PageIndex = 0;
  1351. curWarningCount = pSysWarning->WarningCount;
  1352. ChangeWarningFunc();
  1353. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  1354. // 當有兩頁 Warning 則每隔三秒改變一次
  1355. if (pSysWarning->PageIndex == 0) {
  1356. pSysWarning->PageIndex = 1;
  1357. } else {
  1358. pSysWarning->PageIndex = 0;
  1359. }
  1360. ChangeWarningFunc();
  1361. }
  1362. ///*
  1363. // Show Default Text
  1364. if (!defaulttext) {
  1365. ShowCabientVersionDefaultText();
  1366. ShowDispenserVersionDefautlText();
  1367. defaulttext = true;
  1368. }
  1369. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1370. // 頁面資訊處理
  1371. ProcessPageInfo();
  1372. // 換頁處理
  1373. //GetCurrentPage(); //DS60-120 add
  1374. /*
  1375. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1376. InformationShow();
  1377. ChangeToOtherPage(pSysInfo->PageIndex);
  1378. usleep(100000);
  1379. continue;
  1380. } else {
  1381. if (is_show)
  1382. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1383. is_show = false;
  1384. }*/
  1385. GetCurrentPage(); //DS60-120 add
  1386. ChangeCurPage();
  1387. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1388. usleep(10000); //*/
  1389. /*
  1390. ProcessPageInfo();
  1391. GetCurrentPage();
  1392. ChangeCurPage();
  1393. usleep(10000);
  1394. //*/
  1395. }
  1396. } //while
  1397. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1398. log_info("Close LCM Uart Port");
  1399. CloseCommunicationLcmPort();
  1400. return FAIL;
  1401. }