Module_LcmControl.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  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->SystemStatus == S_CHARGING) {
  769. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  770. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  771. ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CCS1);
  772. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  773. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  774. ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CCS2);
  775. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  776. ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CHAdeMo);
  777. }
  778. } else {
  779. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  780. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  781. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS1);
  782. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  783. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  784. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS2);
  785. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  786. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CHAdeMo);
  787. }
  788. }
  789. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  790. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  791. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  792. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  793. ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CCS1);
  794. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  795. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  796. ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CCS2);
  797. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  798. ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CHAdeMo);
  799. }
  800. } else {
  801. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  802. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  803. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS1);
  804. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  805. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  806. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS2);
  807. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  808. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CHAdeMo);
  809. }
  810. }
  811. }
  812. void ChangeChargingPowerValue(float pow)
  813. {
  814. uint8_t cmd[10];
  815. uint8_t value[10];
  816. memset(cmd, 0x00, sizeof(cmd));
  817. sprintf((char *) value, "%d",(int)pow);
  818. string2ByteArray(value, cmd);
  819. DisplayValueToLcm(_String_ChargePower, cmd, sizeof(cmd));
  820. }
  821. void ChangeChargingRateValue(int rate)
  822. {
  823. uint8_t cmd[10];
  824. uint8_t value[10];
  825. memset(cmd, 0x00, sizeof(cmd));
  826. sprintf((char *) value, "%d",rate);
  827. string2ByteArray(value, cmd);
  828. DisplayValueToLcm(_String_ChargeRate, cmd, sizeof(cmd));
  829. }
  830. void ChangeChargingFeeValue(float fee)
  831. {
  832. uint8_t cmd[10];
  833. uint8_t value[10];
  834. memset(cmd, 0x00, sizeof(cmd));
  835. sprintf((char *) value, "%d", (int)fee);
  836. string2ByteArray(value, cmd);
  837. DisplayValueToLcm(_String_Money, cmd, sizeof(cmd));
  838. }
  839. void ChangeCarBonValue(float data)
  840. {
  841. uint8_t cmd[10];
  842. uint8_t value[10];
  843. float _carbon = 0;
  844. memset(cmd, 0x00, sizeof(cmd));
  845. _carbon = (data*9)/10*2.36 - data*0.637;
  846. //log_info("Carbon:%d",(int)_carbon);
  847. sprintf((char *) value, "%d", (int)_carbon);
  848. string2ByteArray(value, cmd);
  849. DisplayValueToLcm(_String_Carbon, cmd, sizeof(cmd));
  850. }
  851. void ChangeChargingEnergyValue(float energy)
  852. {
  853. uint8_t cmd[10];
  854. uint8_t value[10];
  855. memset(cmd, 0x00, sizeof(cmd));
  856. if (energy >= 0.05) {
  857. energy -= 0.05;
  858. }
  859. if (energy < 0 )
  860. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0);
  861. else if (energy > 100)
  862. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0+100);
  863. else
  864. ChangeDisplay2Value(_Icon_ChargeBar,(int)energy+_TCC_Charging_Bar0);
  865. if (energy < 10)
  866. sprintf((char *) value, "%.1f", energy);
  867. else
  868. sprintf((char *) value, "%d", (int)energy);
  869. string2ByteArray(value, cmd);
  870. DisplayValueToLcm(_Strting_Energy, cmd, sizeof(cmd));
  871. }
  872. uint8_t _battery_display_count = 0;
  873. void ChangeBattMapAndValue(int soc)
  874. {
  875. int i = (soc*36)/100;
  876. uint8_t cmd[5];
  877. uint8_t value[5];
  878. _battery_display_count++;
  879. if (_battery_display_count == 3 ) {
  880. if (_battery_display_ani == 0)
  881. _battery_display_ani= TRUE;
  882. else
  883. _battery_display_ani= FALSE ;
  884. _battery_display_count = 0;
  885. }
  886. if (pSysInfo->SystemPage == _PAGE_CHARGING) {
  887. if (i>=36)
  888. ChangeDisplay2Value(_Icon_ChargeCircle,_TCC_Charging_Circle0+36);
  889. else {
  890. if (_battery_display_ani) {
  891. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i);
  892. } else {
  893. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i+1);
  894. }
  895. }
  896. } else if (pSysInfo->SystemPage == _PAGE_COMPLETE)
  897. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  898. else
  899. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  900. memset(cmd, 0x00, sizeof(cmd));
  901. memset(value, 0x00, sizeof(value));
  902. sprintf((char *)value, "%d", soc);
  903. string2ByteArray(value, cmd);
  904. DisplayValueToLcm(_String_Battery, cmd, sizeof(cmd));
  905. }
  906. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  907. {
  908. struct timeval _end_time;
  909. gettimeofday(&_end_time, NULL);
  910. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  911. }
  912. void ChangeTimeValue(int time)
  913. {
  914. uint8_t cmd[6];
  915. uint8_t value[6];
  916. memset(cmd, 0x00, sizeof(cmd));
  917. sprintf((char *) value, "%d", time);
  918. string2ByteArray(value, cmd);
  919. DisplayValueToLcm(_String_ChargeTime, cmd, sizeof(cmd));
  920. }
  921. void changeWeatherValue(int _weather)
  922. {
  923. switch (_weather) {
  924. case _WEATHER_TYPE_SUN:
  925. ChangeDisplay2Value(_Icon_Weather,_TCC_Sun);
  926. break;
  927. case _WEATHER_TYPE_CLOUDY:
  928. ChangeDisplay2Value(_Icon_Weather,_TCC_Cloudy);
  929. break;
  930. case _WEATHER_TYPE_RAIN:
  931. ChangeDisplay2Value(_Icon_Weather,_TCC_Rain);
  932. break;
  933. case _WEATHER_TYPE_THUNDER:
  934. ChangeDisplay2Value(_Icon_Weather,_TCC_Thunder);
  935. break;
  936. case _WEATHER_TYPE_SNOW:
  937. ChangeDisplay2Value(_Icon_Weather,_TCC_Snow);
  938. break;
  939. case _WEATHER_TYPE_FOG:
  940. ChangeDisplay2Value(_Icon_Weather,_TCC_Fog);
  941. break;
  942. }
  943. }
  944. void changeWeekValue(int _week)
  945. {
  946. time_t t = time(NULL);
  947. struct tm *now = localtime(&t);
  948. _week = now->tm_wday;
  949. if (_week == 0 )
  950. _week = 7;
  951. ChangeDisplay2Value(_Icon_Week,_week);
  952. }
  953. void changeDegreeValue(int _degree)
  954. {
  955. char value[16];
  956. memset(value, 0x00, sizeof(value));
  957. sprintf((char *)value,"%d",_degree);
  958. DisplayValueToLcm(_String_Tempture, (uint8_t *)value, sizeof(value));
  959. }
  960. void changeDateValue(char* _date)
  961. {
  962. char value[16];
  963. memset(value, 0x00, sizeof(value));
  964. sprintf((char *)value,"%s",_date);
  965. DisplayValueToLcm(_String_Date, (uint8_t *)value, sizeof(value));
  966. }
  967. void changeLocationValue(int _location)
  968. {
  969. //_location+=1000;
  970. //log_info("location:%d",_location);
  971. ChangeDisplay2Value(_Icon_Location,(short)_location);
  972. }
  973. int old_money = 0;
  974. int ClearQR_flag[2];
  975. void ProcessPageInfo()
  976. {
  977. // Show Gun Working and Type
  978. if (pSysInfo->SystemPage == _PAGE_IDLE) {
  979. changeWeatherValue(ShmDcCommonData->WeatherID);
  980. changeWeekValue(0);
  981. changeDegreeValue((int)ShmDcCommonData->Temperature);
  982. changeDateValue(&ShmDcCommonData->PresentTime[0]);
  983. changeLocationValue(ShmDcCommonData->Location);
  984. return;
  985. }
  986. if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
  987. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  988. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  989. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  990. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  991. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  992. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  993. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  994. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  995. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  996. }
  997. // Set Right Gun
  998. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  999. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1000. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1001. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  1002. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1003. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1004. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  1005. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1006. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  1007. }
  1008. return;
  1009. }
  1010. showGunWorkingType();
  1011. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1012. if (pSysInfo->CurGunSelected == i) {
  1013. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1014. switch (pSysInfo->SystemPage) {
  1015. case _PAGE_IDLE:
  1016. break;
  1017. case _PAGE_SELECT_PAY:
  1018. if (ShmDcCommonData->donate_flag[i] == TRUE) {
  1019. ChangeDisplay2Value(_Icon_WordAddFriend,_ICON_Empty);
  1020. } else
  1021. ChangeDisplay2Value(_Icon_WordAddFriend,_TCC_SelectPayMode);
  1022. StartSystemTimeoutDet(Timeout_SelectPayMode);
  1023. break;
  1024. case _PAGE_SELECT_GUN:
  1025. ShowSelectGun();
  1026. ClearQR_flag[i] = FALSE;
  1027. break;
  1028. case _PAGE_BILL:
  1029. if(ClearQR_flag[i] == FALSE) {
  1030. ClearQrCode();
  1031. ClearQR_flag[i] = TRUE;
  1032. }
  1033. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1034. break;
  1035. case _PAGE_AUTHORIZE:
  1036. /*
  1037. int card_result = CreditCardPreAuth(CardReadFd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
  1038. if (card_result > 0 ) {
  1039. strcpy((char *)pSysConfig->UserId, (char *)ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo);
  1040. } else if (card_result < 0) {
  1041. pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
  1042. }*/
  1043. //ChangeDisplay2Value(_Icon_Precharge,0);
  1044. //ChangeDisplay2Value(_Icon_Precharge,1);
  1045. if (ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] == TRUE &&
  1046. ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] != TRUE) {
  1047. ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
  1048. ShmDcCommonData->PreAuth_Result = 0;
  1049. sleep(3);
  1050. pSysInfo->SystemPage = _PAGE_SENSING;
  1051. }
  1052. _Text_Running_Count = 1;
  1053. ChangeChargingRateValue(ShmDcCommonData->ChargingRate);
  1054. break;
  1055. case _PAGE_SENSING:
  1056. break;
  1057. case _PAGE_PLUGIN:
  1058. _everyPageRollChange = 0;
  1059. break;
  1060. case _PAGE_PRECHARGE:
  1061. //ChangeDisplay2Value(_Icon_Precharge,1);
  1062. RefreshProgressAnimation();
  1063. if (_everyPageRollChange == 0) {
  1064. ChangeDisplay2Value(_Icon_Precharge,_Text_Running_Count);
  1065. _Text_Running_Count >= 24 ? _Text_Running_Count = 24 : _Text_Running_Count++;
  1066. }
  1067. break;
  1068. case _PAGE_CHARGING:
  1069. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  1070. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1071. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  1072. } else {
  1073. ChangeChargingPowerValue(0);
  1074. }
  1075. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1076. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1077. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1078. } else {
  1079. ChangeChargingEnergyValue(0);
  1080. }
  1081. if ( pDcChargingInfo->ChargingFee >= 0) {
  1082. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  1083. }
  1084. if (pDcChargingInfo->RemainChargingDuration >= 0 &&
  1085. pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
  1086. ChangeTimeValue(pDcChargingInfo->RemainChargingDuration/60);
  1087. } else {
  1088. ChangeTimeValue(0);
  1089. }
  1090. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1091. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1092. break;
  1093. case _PAGE_COMPLETE:
  1094. case _PAGE_PAYFAIL:
  1095. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1096. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1097. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1098. } else {
  1099. ChangeChargingEnergyValue(0);
  1100. }
  1101. if ( ShmDcCommonData->finalcost[i] >= 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
  1102. StopGunInfoTimeoutDet(i);
  1103. ChangeChargingFeeValue(ShmDcCommonData->finalcost[i]);
  1104. //ShmDcCommonData->finalcost_flag[i] = FALSE;
  1105. }
  1106. ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
  1107. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1108. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1109. break;
  1110. case _PAGE_PLUGOUT:
  1111. /*
  1112. if (pSysConfig->isQRCode) {
  1113. if (pSysConfig->QRCodeMadeMode == NO) {
  1114. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  1115. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1116. } else {
  1117. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  1118. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  1119. }
  1120. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1121. }*/
  1122. break;
  1123. case _PAGE_PAYING:
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. void ChangeWarningFunc()
  1130. {
  1131. uint8_t cmd[7] = {0};
  1132. uint8_t i = 0;
  1133. //uint8_t j = 0;
  1134. //log_info("ChangeWarningFunc ");
  1135. // 最多一次五筆
  1136. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  1137. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  1138. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1139. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  1140. log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  1141. memset(cmd, 0x00, sizeof(cmd));
  1142. if ((i) >= 5) {
  1143. break;
  1144. }
  1145. //error code
  1146. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  1147. DisplayValueToLcm(_Strting_Warming0 + ((i) * 0x10), cmd, sizeof(cmd));
  1148. //警告標示
  1149. memset(cmd, 0x00, sizeof(cmd));
  1150. cmd[0] = 0x00;
  1151. cmd[1] = 1;
  1152. DisplayValueToLcm(_Icon_Warming0 + ((i) * 2), cmd, 2);
  1153. }
  1154. memset(cmd, 0x00, sizeof(cmd));
  1155. for (; i < 5; i++) {
  1156. DisplayValueToLcm(_Strting_Warming0 + ((i) * 0x10), cmd, sizeof(cmd));
  1157. DisplayValueToLcm(_Icon_Warming0 + ((i) * 2), cmd, 2);
  1158. }
  1159. }
  1160. void ShowCabientVersionDefaultText()
  1161. {
  1162. char value[16];
  1163. memset(value, 0x00, sizeof(value));
  1164. sprintf((char *)value,"%s","Cabient:");
  1165. DisplayValueToLcm(_Version_Cabient_Name_Text, (uint8_t *)value, sizeof(value));
  1166. sprintf((char *)value,"%s","BootLoader:");
  1167. DisplayValueToLcm(_Version_Cabient_BootLoader_Text, (uint8_t *)value, sizeof(value));
  1168. sprintf((char *)value,"%s","Kernel Fw:");
  1169. DisplayValueToLcm(_Version_Cabient_Kernel_Text, (uint8_t *)value, sizeof(value));
  1170. sprintf((char *)value,"%s","CSU Fw:");
  1171. DisplayValueToLcm(_Version_Cabient_CSU_Text, (uint8_t *)value, sizeof(value));
  1172. sprintf((char *)value,"%s","Priamry Fw:");
  1173. DisplayValueToLcm(_Version_Cabient_Priamry_Text, (uint8_t *)value, sizeof(value));
  1174. sprintf((char *)value,"%s","Relay(0) Fw:");
  1175. DisplayValueToLcm(_Version_Cabient_Relay0_Text, (uint8_t *)value, sizeof(value));
  1176. sprintf((char *)value,"%s","Relay(1) Fw:");
  1177. DisplayValueToLcm(_Version_Cabient_Relay1_Text, (uint8_t *)value, sizeof(value));
  1178. sprintf((char *)value,"%s","Fan Fw:");
  1179. DisplayValueToLcm(_Version_Cabient_Fan_Text, (uint8_t *)value, sizeof(value));
  1180. sprintf((char *)value,"%s","IP Addr:");
  1181. DisplayValueToLcm(_Version_Cabient_IPAddr_Text, (uint8_t *)value, sizeof(value));
  1182. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number <= 12) {
  1183. sprintf((char *)value,"%s","Primary");
  1184. DisplayValueToLcm(_Version_Cabient_Primary_Text, (uint8_t *)value, sizeof(value));
  1185. sprintf((char *)value,"%s","Secondary");
  1186. DisplayValueToLcm(_Version_Cabient_Secondary_Text, (uint8_t *)value, sizeof(value));
  1187. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  1188. sprintf((char *)value,"PSU(%d):",i+1);
  1189. DisplayValueToLcm(_Version_Cabient_PSU1_Text+i*0x10, (uint8_t *)value, sizeof(value));
  1190. }
  1191. }
  1192. }
  1193. void ShowDispenserVersionDefautlText()
  1194. {
  1195. char value[16];
  1196. memset(value, 0x00, sizeof(value));
  1197. sprintf((char *)value,"%s","Dispenser:");
  1198. DisplayValueToLcm(_Version_Dispenser_Name_Text, (uint8_t *)value, sizeof(value));
  1199. sprintf((char *)value,"%s","BootLoader:");
  1200. DisplayValueToLcm(_Version_Dispenser_BootLoader_Text, (uint8_t *)value, sizeof(value));
  1201. sprintf((char *)value,"%s","Kernel Fw:");
  1202. DisplayValueToLcm(_Version_Dispenser_Kernel_Text, (uint8_t *)value, sizeof(value));
  1203. sprintf((char *)value,"%s","CSU Fw:");
  1204. DisplayValueToLcm(_Version_Dispenser_CSU_Text, (uint8_t *)value, sizeof(value));
  1205. sprintf((char *)value,"%s","Relay Fw:");
  1206. DisplayValueToLcm(_Version_Dispenser_Relay_Text, (uint8_t *)value, sizeof(value));
  1207. sprintf((char *)value,"%s","Fan Fw:");
  1208. DisplayValueToLcm(_Version_Dispenser_Fan_Text, (uint8_t *)value, sizeof(value));
  1209. sprintf((char *)value,"%s","Prim Fw:");
  1210. DisplayValueToLcm(_Version_Dispenser_Priamry_Text, (uint8_t *)value, sizeof(value));
  1211. sprintf((char *)value,"%s","LCM Hw:");
  1212. DisplayValueToLcm(_Version_Dispenser_LCM_Text, (uint8_t *)value, sizeof(value));
  1213. sprintf((char *)value,"%s","LED Fw:");
  1214. DisplayValueToLcm(_Version_Dispenser_LED_Text, (uint8_t *)value, sizeof(value));
  1215. sprintf((char *)value,"%s","Connector(0):");
  1216. DisplayValueToLcm(_Version_Dispenser_Connector0_Text, (uint8_t *)value, sizeof(value));
  1217. sprintf((char *)value,"%s","Connector(1):");
  1218. DisplayValueToLcm(_Version_Dispenser_Connector1_Text, (uint8_t *)value, sizeof(value));
  1219. sprintf((char *)value,"%s","IP Addr:");
  1220. DisplayValueToLcm(_Version_Dispenser_IPAddr_Text, (uint8_t *)value, sizeof(value));
  1221. }
  1222. void ShowCabientVersion()
  1223. {
  1224. char value[16];
  1225. memset(value, 0x00, sizeof(value));
  1226. sprintf((char *)value,"%s",ShmDcCommonData->CabinetModelName);
  1227. DisplayValueToLcm(_Version_Cabient_Model_value, (uint8_t *)value, sizeof(value));
  1228. sprintf((char *)value,"%s",ShmDcCommonData->CabinetBoolLoaderVersion);
  1229. DisplayValueToLcm(_Version_Cabient_BootLoader_value, (uint8_t *)value, sizeof(value));
  1230. sprintf((char *)value,"%s",ShmDcCommonData->CabinetKernelVersion);
  1231. DisplayValueToLcm(_Version_Cabient_Kernel_value, (uint8_t *)value, sizeof(value));
  1232. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRFSystemVersion);
  1233. DisplayValueToLcm(_Version_Cabient_CSU_value, (uint8_t *)value, sizeof(value));
  1234. sprintf((char *)value,"%s",ShmDcCommonData->CabinetPrimaryVersion);
  1235. DisplayValueToLcm(_Version_Cabient_Priamry_value, (uint8_t *)value, sizeof(value));
  1236. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay0Version);
  1237. DisplayValueToLcm(_Version_Cabient_Relay0_value, (uint8_t *)value, sizeof(value));
  1238. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay1Version);
  1239. DisplayValueToLcm(_Version_Cabient_Relay1_value, (uint8_t *)value, sizeof(value));
  1240. sprintf((char *)value,"%s",ShmDcCommonData->CabinetFanVersion);
  1241. DisplayValueToLcm(_Version_Cabient_Fan_value, (uint8_t *)value, sizeof(value));
  1242. sprintf((char *)value,"%s",ShmDcCommonData->CabinetIPAddr);
  1243. DisplayValueToLcm(_Version_Cabient_IPAddr_value, (uint8_t *)value, sizeof(value));
  1244. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number < 12) {
  1245. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  1246. if (i>=6) {
  1247. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].DCVersion);
  1248. DisplayValueToLcm(_Version_Cabient_PSU_Prim7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  1249. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].FPCVersion);
  1250. DisplayValueToLcm(_Version_Cabient_PSU_Sec7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  1251. continue;
  1252. }
  1253. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].DCVersion);
  1254. DisplayValueToLcm(_Version_Cabient_PSU_Prim1_value+i*0x10, (uint8_t *)value, sizeof(value));
  1255. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].FPCVersion);
  1256. DisplayValueToLcm(_Version_Cabient_PSU_Sec1_value+i*0x10, (uint8_t *)value, sizeof(value));
  1257. }
  1258. }
  1259. }
  1260. void ShowDispenserVersion()
  1261. {
  1262. char value[32];
  1263. memset(value, 0x00, sizeof(value));
  1264. sprintf((char *)value,"%s",pSysConfig->ModelName);
  1265. DisplayValueToLcm(_Version_Dispenser_Model_value, (uint8_t *)value, sizeof(value));
  1266. sprintf((char *)value,"%s",pSysInfo->CsuBootLoadFwRev);
  1267. DisplayValueToLcm(_Version_Dispenser_BootLoader_value, (uint8_t *)value, sizeof(value));
  1268. sprintf((char *)value,"%s",pSysInfo->CsuKernelFwRev);
  1269. DisplayValueToLcm(_Version_Dispenser_Kernel_value, (uint8_t *)value, sizeof(value));
  1270. sprintf((char *)value,"%s",pSysInfo->CsuRootFsFwRev);
  1271. DisplayValueToLcm(_Version_Dispenser_CSU_value, (uint8_t *)value, sizeof(value));
  1272. sprintf((char *)value,"%s",pSysInfo->RelayModuleFwRev);
  1273. DisplayValueToLcm(_Version_Dispenser_Relay_value, (uint8_t *)value, sizeof(value));
  1274. sprintf((char *)value,"%s",pSysInfo->FanModuleFwRev);
  1275. DisplayValueToLcm(_Version_Dispenser_Fan_value, (uint8_t *)value, sizeof(value));
  1276. sprintf((char *)value,"%s",pSysInfo->CsuPrimFwRev);
  1277. DisplayValueToLcm(_Version_Dispenser_Priamry_value, (uint8_t *)value, sizeof(value));
  1278. sprintf((char *)value,"%s",pSysInfo->LcmHwRev);
  1279. DisplayValueToLcm(_Version_Dispenser_LCM_value, (uint8_t *)value, sizeof(value));
  1280. sprintf((char *)value,"%s",pSysInfo->LedModuleFwRev);
  1281. DisplayValueToLcm(_Version_Dispenser_LED_value, (uint8_t *)value, sizeof(value));
  1282. sprintf((char *)value,"%s",pSysInfo->Connector1FwRev);
  1283. DisplayValueToLcm(_Version_Dispenser_Connector0_value, (uint8_t *)value, sizeof(value));
  1284. sprintf((char *)value,"%s",pSysInfo->Connector2FwRev);
  1285. DisplayValueToLcm(_Version_Dispenser_Connector1_value, (uint8_t *)value, sizeof(value));
  1286. sprintf((char *)value,"%s",pSysConfig->Eth0Interface.EthIpAddress);
  1287. DisplayValueToLcm(_Version_Dispenser_IPAddr_value, (uint8_t *)value, sizeof(value));
  1288. }
  1289. /*
  1290. void InformationShow()
  1291. {
  1292. is_show = true;
  1293. if (_showInformIndex == 0 ) {
  1294. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  1295. } else {
  1296. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  1297. ShowDispenserVersion();
  1298. }
  1299. }
  1300. */
  1301. void DefautLayOut()
  1302. {
  1303. int i;
  1304. for (i = 0 ; i <= 0x5C ; i+=2 ) {
  1305. ChangeDisplay2Value(0x1000+i,1);
  1306. if (i==0x28 || i ==0x2A)
  1307. continue;
  1308. }
  1309. ChangeDisplay2Value(_Icon_MobilePay,0);
  1310. ChangeDisplay2Value(_Icon_CardPay,0);
  1311. ChangeDisplay2Value(0x5000,1);
  1312. ShowSelectGun();
  1313. }
  1314. /*
  1315. static int InitialRfidPort(void)
  1316. {
  1317. int fd = open(rfidPortName, O_RDWR);
  1318. struct termios tios;
  1319. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1320. if (fd != FAIL) {
  1321. ioctl (fd, TCGETS, &tios);
  1322. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  1323. tios.c_lflag = 0;
  1324. tios.c_iflag = 0;
  1325. tios.c_oflag = 0;
  1326. tios.c_cc[VMIN] = 0;
  1327. tios.c_cc[VTIME] = (uint8_t) 1;
  1328. tios.c_lflag = 0;
  1329. tcflush(fd, TCIFLUSH);
  1330. ioctl(fd, TCSETS, &tios);
  1331. }
  1332. if (fd < 0) {
  1333. pAlarmCode->AlarmEvents.bits.RfidModuleCommFail = 1;
  1334. }
  1335. return fd;
  1336. }
  1337. */
  1338. int main(void)
  1339. {
  1340. bool defaulttext = false;
  1341. if (CreateAllCsuShareMemory() == FAIL) {
  1342. log_error("create share memory error");
  1343. return FAIL;
  1344. }
  1345. MappingGunChargingInfo("LCM Control Task");
  1346. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1347. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1348. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1349. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  1350. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1351. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1352. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1353. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  1354. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  1355. _port = CreateCommunicationLcmPort();
  1356. uint8_t changeWarningPriority = 0;
  1357. uint8_t curWarningCount = 255;
  1358. ChangeBackLight(true);
  1359. _totalCount = pSysConfig->TotalConnectorCount;
  1360. _everyPageRollChange = 0;
  1361. //Initialization();
  1362. //printf("_LCM_COMPLETE ");
  1363. //ChangeToOtherPage(_LCM_COMPLETE);
  1364. DefautLayOut();
  1365. //return 0;
  1366. //uint8_t index = 1;
  1367. int result = 0;
  1368. ShmDcCommonData->PSU_Number = 12;
  1369. /*
  1370. CardReadFd = InitialRfidPort();
  1371. if (CardReadFd <0) {
  1372. log_info("Card Read Port open fail!");
  1373. }*/
  1374. CheckLCMPressed();
  1375. while (_port != -1) {
  1376. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  1377. GetCurrentPage();
  1378. sleep(1);
  1379. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1380. } else {
  1381. UpdateLcmFunction(ShmDcCommonData,_port);
  1382. ///*
  1383. // Warning 處理
  1384. if (curWarningCount != pSysWarning->WarningCount) {
  1385. changeWarningPriority = 0;
  1386. pSysWarning->PageIndex = 0;
  1387. curWarningCount = pSysWarning->WarningCount;
  1388. ChangeWarningFunc();
  1389. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  1390. // 當有兩頁 Warning 則每隔三秒改變一次
  1391. if (pSysWarning->PageIndex == 0) {
  1392. pSysWarning->PageIndex = 1;
  1393. } else {
  1394. pSysWarning->PageIndex = 0;
  1395. }
  1396. ChangeWarningFunc();
  1397. }
  1398. ///*
  1399. // Show Default Text
  1400. if (!defaulttext) {
  1401. ShowCabientVersionDefaultText();
  1402. ShowDispenserVersionDefautlText();
  1403. defaulttext = true;
  1404. }
  1405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1406. // 頁面資訊處理
  1407. ProcessPageInfo();
  1408. // 換頁處理
  1409. //GetCurrentPage(); //DS60-120 add
  1410. /*
  1411. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1412. InformationShow();
  1413. ChangeToOtherPage(pSysInfo->PageIndex);
  1414. usleep(100000);
  1415. continue;
  1416. } else {
  1417. if (is_show)
  1418. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1419. is_show = false;
  1420. }*/
  1421. GetCurrentPage(); //DS60-120 add
  1422. ChangeCurPage();
  1423. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1424. usleep(10000); //*/
  1425. /*
  1426. ProcessPageInfo();
  1427. GetCurrentPage();
  1428. ChangeCurPage();
  1429. usleep(10000);
  1430. //*/
  1431. }
  1432. } //while
  1433. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1434. log_info("Close LCM Uart Port");
  1435. CloseCommunicationLcmPort();
  1436. return FAIL;
  1437. }