Module_LcmControl.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  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. GetClockTime(&pDcChargingInfo->ConnectorTimeout, 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. bool isChargingEnd(gunIndex)
  123. {
  124. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  125. if (pDcChargingInfo->SystemStatus == S_COMPLETE || pDcChargingInfo->SystemStatus == S_ALARM) {
  126. return TRUE;
  127. } else {
  128. return FALSE;
  129. }
  130. }
  131. void CloseCommunicationLcmPort()
  132. {
  133. close(_port);
  134. }
  135. void setSelGunWaitToAuthor(uint8_t curSel)
  136. {
  137. if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
  138. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
  139. log_info("setSelGunWaitToAuthor left");
  140. } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
  141. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
  142. log_info("setSelGunWaitToAuthor right");
  143. }
  144. }
  145. void confirmSelGun(uint8_t selGun)
  146. {
  147. if (selGun == LEFT_GUN_NUM) {
  148. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  149. //printf("confirmSelGun left");
  150. } else if (selGun == RIGHT_GUN_NUM) {
  151. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  152. //printf("confirmSelGun right");
  153. }
  154. //changeLcmPage(_PAGE_PLUGIN);
  155. //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
  156. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  157. }
  158. void WriteCmdToLcm(uint8_t *cmd, uint8_t cmdLen)
  159. {
  160. int len = write(_port, cmd, cmdLen);
  161. if (len < sizeof(cmd)) {
  162. log_error("Write cmd to LCM Failure. ");
  163. }
  164. }
  165. void ReadMsgFromLcm(uint8_t* msg, uint8_t readLen)
  166. {
  167. read(_port, msg, readLen);
  168. // 5a : CMD_TITLE_1
  169. // a5 : CMD_TITLE_2
  170. // 5
  171. // 81 : CMD_WRITE
  172. // 3 : CMD_REGISTER
  173. // 2 : Data length
  174. // 0 : High byte
  175. // 1 : Low byte
  176. // printf("-------------------------------------------- \n");
  177. // printf("msg = %x \n", *msg); // A5
  178. // printf("msg = %x \n", *(msg + 1)); // 5A
  179. // printf("msg = %x \n", *(msg + 2)); // Len : [3] ~ [6] + Data Len
  180. // printf("msg = %x \n", *(msg + 3)); // cmd : 0x83
  181. // printf("msg = %x \n", *(msg + 4)); // addr : H
  182. // printf("msg = %x \n", *(msg + 5)); // addr : L
  183. // printf("msg = %x \n", *(msg + 6)); // Data Len
  184. //
  185. // printf("msg = %x \n", *(msg + 7));
  186. // printf("msg = %x \n", *(msg + 8));
  187. // printf("msg = %x \n", *(msg + 9));
  188. // printf("msg = %x \n", *(msg + 10));
  189. // printf("msg = %x \n", *(msg + 11));
  190. // printf("msg = %x \n", *(msg + 12));
  191. // printf("msg = %x \n", *(msg + 13));
  192. // printf("msg = %x \n", *(msg + 14));
  193. /*
  194. for(uint8_t i = 0 ; i<readLen+3; i++) {
  195. log_info("Read data[%d]:0x%x",i,msg[i]);
  196. }*/
  197. if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
  198. {
  199. if (*(msg + 3) == CMD_WRITE)
  200. {
  201. switch (*(msg + 4))
  202. {
  203. case CMD_REGISTER:
  204. {
  205. // 頁面
  206. if (strcmp((char*)pSysInfo->LcmHwRev, "") != EQUAL)
  207. strcpy((char*)pSysInfo->LcmHwRev, moduleName);
  208. _currentPage = *(msg + 7);
  209. log_info("Current Page:%d", _currentPage);
  210. // if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
  211. // printf("_currentPage = %d \n", _currentPage);
  212. }
  213. break;
  214. }
  215. } else if (*(msg + 3) == CMD_MULTI_READ)
  216. {
  217. short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
  218. if (strcmp((char*)pSysInfo->LcmHwRev, "") != EQUAL)
  219. strcpy((char*)pSysInfo->LcmHwRev, moduleName);
  220. if (key == 0x0014)
  221. _currentPage = *(msg + 8);
  222. if (key == 0x0031) {
  223. log_info("Get LCM Backlight change to 0x%x", *(msg + 8));
  224. }
  225. if (key >= _Touch_IDLE && key <= _Touch_Parking_Complete) {
  226. _btn_press_id = key;
  227. _btn_press = *(msg + 8);
  228. }
  229. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  230. // {
  231. // case BUTTON_GUN_INDEX:
  232. // {
  233. // // 當前選的槍號
  234. // _curGunIndex = (*(msg + 8));
  235. // }
  236. // break;
  237. // }
  238. }
  239. }
  240. }
  241. void GetDeviceInfoStatus(short address, uint8_t len)
  242. {
  243. uint8_t cmd[8];
  244. memset(cmd, 0x00, sizeof(cmd));
  245. uint8_t msg[11];
  246. memset(msg, 0x00, sizeof(msg));
  247. cmd[0] = CMD_TITLE_1;
  248. cmd[1] = CMD_TITLE_2;
  249. cmd[2] = 0x04;
  250. cmd[3] = CMD_MULTI_READ;
  251. cmd[4] = (address >> 8) & 0xff;
  252. cmd[5] = (address >> 0) & 0xff;
  253. cmd[6] = len;
  254. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  255. usleep(1000);
  256. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  257. }
  258. void DisplayValueToLcm(short address, uint8_t* data, uint8_t len)
  259. {
  260. uint8_t cmd[256];
  261. memset(cmd, 0x00, sizeof(cmd));
  262. uint8_t msg[9];
  263. memset(msg, 0x00, sizeof(msg));
  264. cmd[0] = CMD_TITLE_1;
  265. cmd[1] = CMD_TITLE_2;
  266. cmd[2] = 0x03 + len;
  267. cmd[3] = CMD_MULTI_WRITE;
  268. cmd[4] = address >> 8;
  269. cmd[5] = address & 0x00FF;
  270. for (uint8_t count = 0; count < len; count++)
  271. {
  272. cmd[6 + count] = *(data + count);
  273. }
  274. WriteCmdToLcm(cmd, cmd[2] + 3);
  275. usleep(10000);
  276. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  277. }
  278. void ChangeDisplay2Value(short address, short value)
  279. {
  280. uint8_t data[2];
  281. data[0] = value >> 8;
  282. data[1] = value & 0x00FF;
  283. //log_info("Addr:0x%x, value:%d",address,value);
  284. DisplayValueToLcm(address, data, sizeof(data));
  285. }
  286. void TradeRunning(uint8_t _run)
  287. {
  288. if (_run == TRUE) {
  289. ChangeDisplay2Value(_Icon_PreAuth, 1);
  290. ChangeDisplay2Value(_Icon_Ani_Dot, 1);
  291. ChangeDisplay2Value(_Icon_CountDownBG, 0);
  292. ChangeDisplay2Value(_Icon_CancelCntDownTen, 0);
  293. ChangeDisplay2Value(_Icon_CancelCntDownDigits, 0);
  294. ChangeDisplay2Value(_Icon_PreAuthWord, _TCC_PreAuthWord);
  295. }
  296. else {
  297. ChangeDisplay2Value(_Icon_PreAuth, _TCC_TradeCancelString);
  298. ChangeDisplay2Value(_Icon_Ani_Dot, 0);
  299. ChangeDisplay2Value(_Icon_PreAuthWord, 0);
  300. ChangeDisplay2Value(_Icon_CountDownBG, _TCC_TradeCancelFrame);
  301. //log_info("SystemTimeoutFlag:%d", pSysInfo->SystemTimeoutFlag);
  302. if (pSysInfo->SystemTimeoutFlag == Timeout_TradeCancel) {
  303. unsigned long _time = TCC_TRADECANCEL_TIMEOUT-(GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL);
  304. ChangeDisplay2Value(_Icon_CancelCntDownTen, (short)(_TCC_CancelNum_0 + (_time / 10)));
  305. ChangeDisplay2Value(_Icon_CancelCntDownDigits, (short)(_TCC_CancelNum_0 + (_time % 10)));
  306. }
  307. }
  308. }
  309. static void systemPageRestoreInit(void)
  310. {
  311. int is_idle = TRUE;
  312. int gunIndex;
  313. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  314. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  315. // 檢查電樁狀態是否為idle狀態
  316. if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
  317. pDcChargingInfo->SystemStatus <= S_RESERVATION) ||
  318. (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
  319. pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST0)) {
  320. is_idle = FALSE;
  321. }
  322. }
  323. if (is_idle)
  324. pSysInfo->SystemPage = _PAGE_IDLE;
  325. else
  326. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  327. }
  328. void CheckIdlePress()
  329. {
  330. systemPageRestoreInit();
  331. log_info("IDLE Enter Select Gun Page");
  332. }
  333. void CheckReturnPress()
  334. {
  335. int i;
  336. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  337. //pDcChargingInfo->SystemStatus = S_IDLE;
  338. if (pSysInfo->SystemPage >= _PAGE_BILL && pSysInfo->SystemPage <= _PAGE_PLUGIN ||
  339. pSysInfo->SystemPage == _PAGE_AUTHORIZE_FAIL || pSysInfo->SystemPage == _PAGE_DONATE_RIGHT) {
  340. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE && ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].isParking) {
  341. log_info("Parking Status cann't press return button");
  342. return;
  343. }
  344. ShmDcCommonData->OperateIDLE[pSysInfo->CurGunSelected] = 1;
  345. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  346. ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].GetParkingBill = FALSE;
  347. ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].isParking = FALSE;
  348. log_info("Operate return to IDLE");
  349. }
  350. // Cancel Trade
  351. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus) {
  352. ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].GetParkingBill = FALSE;
  353. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  354. log_info("Press Return button Cancel Sale");
  355. ShmDcCommonData->TradeCancel = TRUE;
  356. pSysInfo->SystemPage = _PAGE_SENSING;
  357. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  358. StartSystemTimeoutDet(Timeout_TradeCancel);
  359. for (i = 0; i <= 30; i++) {
  360. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  361. break;
  362. sleep(1);
  363. }
  364. ShmDcCommonData->PreAuth_Result = 0;
  365. }
  366. StopSystemTimeoutDet();
  367. ShmDcCommonData->PreAuth_Result = 0;
  368. systemPageRestoreInit();
  369. return;
  370. } else if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING ||
  371. ((pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION ) &&
  372. pSysInfo->SystemPage == _PAGE_AUTHORIZE)) {
  373. log_info("Press Return button cancel PreAuth");
  374. ShmDcCommonData->TradeCancel = TRUE;
  375. pSysInfo->SystemPage = _PAGE_SENSING;
  376. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  377. StartSystemTimeoutDet(Timeout_TradeCancel);
  378. for (i = 0; i <= 30; i++) {
  379. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  380. break;
  381. sleep(1);
  382. }
  383. ShmDcCommonData->PreAuth_Result = 0;
  384. ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] = FALSE;
  385. if (strcmp(ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].pCreditCard.VemData, "") != 0) {
  386. ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
  387. ShmDcCommonData->PreAuth_Result = 0;
  388. for (i = 0; i <= 30; i++) {
  389. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  390. break;
  391. sleep(1);
  392. }
  393. ShmDcCommonData->PreAuth_Result = 0;
  394. }
  395. StopSystemTimeoutDet();
  396. pDcChargingInfo->SystemStatus = S_IDLE;
  397. systemPageRestoreInit();
  398. strcpy((char *)pSysConfig->UserId, "");
  399. return;
  400. }
  401. if ( pSysInfo->SystemPage == _PAGE_EXIT ) {
  402. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  403. pDcChargingInfo->SystemStatus = S_IDLE;
  404. return;
  405. }
  406. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE)
  407. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  408. else
  409. systemPageRestoreInit();
  410. }
  411. void CheckStopPress()
  412. {
  413. //ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
  414. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
  415. pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_LEFT;
  416. else
  417. pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_RIGHT;
  418. }
  419. void CheckStopConfirmPress()
  420. {
  421. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  422. pDcChargingInfo->SystemStatus = S_TERMINATING;
  423. pSysInfo->SystemPage = _PAGE_PAYING;
  424. is_stop = TRUE;
  425. /*
  426. //ShmDcCommonData->StopCharge[pSysInfo->CurGunSelected] = TRUE;
  427. if (ShmDcCommonData->is_AutoStart[pSysInfo->CurGunSelected] ||
  428. ShmDcCommonData->is_RemoteStart[pSysInfo->CurGunSelected]) {
  429. pSysInfo->SystemPage = _PAGE_COMPLETE;
  430. return;
  431. }
  432. */
  433. }
  434. void CheckStopCancelPress()
  435. {
  436. //ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
  437. pSysInfo->SystemPage = _PAGE_CHARGING;
  438. is_stop = FALSE;
  439. }
  440. void CheckConfirmGun(uint8_t gunIndex)
  441. {
  442. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
  443. if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  444. log_info("Reservation can't select");
  445. return;
  446. }
  447. //log_info("Confirm Gun%d",gunIndex);
  448. pSysInfo->CurGunSelected = gunIndex;
  449. if (ShmDcCommonData->pGunInfo[gunIndex].ParkingStatus) {
  450. if (pDcChargingInfo->SystemStatus == S_IDLE)
  451. ShmDcCommonData->pGunInfo[gunIndex].ReqParkingBill = TRUE;
  452. //else if (isChargingEnd(gunIndex)) {
  453. //}
  454. if (pDcChargingInfo->SystemStatus == S_COMPLETE || pDcChargingInfo->SystemStatus == S_ALARM) {
  455. if (ShmDcCommonData->PayPass_flag[gunIndex] == TRUE)
  456. pSysInfo->SystemPage = _PAGE_COMPLETE;
  457. else {
  458. if (pDcChargingInfo->Replug_flag)
  459. pSysInfo->SystemPage = _PAGE_PLUGOUT;
  460. else
  461. pSysInfo->SystemPage = _PAGE_PAYFAIL;
  462. }
  463. } else {
  464. pSysInfo->SystemPage = _PAGE_PAYING;
  465. }
  466. } else {
  467. pSysInfo->SystemPage = _PAGE_BILL;
  468. }
  469. }
  470. void CheckDonateBill(uint8_t gunIndex)
  471. {
  472. if (gunIndex == LEFT_GUN_NUM) {
  473. pSysInfo->SystemPage = _PAGE_DONATE_LEFT;
  474. } else
  475. pSysInfo->SystemPage = _PAGE_DONATE_RIGHT;
  476. }
  477. void CheckDonateYes()
  478. {
  479. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus) {
  480. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  481. StartGunInfoTimeoutDet(pSysInfo->CurGunSelected, Timeout_ParkingSelect);
  482. ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].IsDonateInvoice = TRUE;
  483. } else {
  484. ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = TRUE;
  485. }
  486. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  487. }
  488. void CheckDonateNo()
  489. {
  490. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus) {
  491. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  492. StartGunInfoTimeoutDet(pSysInfo->CurGunSelected, Timeout_ParkingSelect);
  493. ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].IsDonateInvoice = FALSE;
  494. } else {
  495. StartSystemTimeoutDet(Timeout_AddLine);
  496. ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = FALSE;
  497. }
  498. pSysInfo->SystemPage = _PAGE_BILL;
  499. }
  500. void CheckPayCreditCard()
  501. {
  502. //ShmDcCommonData->LineStatus[pSysInfo->CurGunSelected] = 0;
  503. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  504. // 使用者進入線上支付,禁止使用者使用刷卡機
  505. if (ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].LineStatus == _LINE_PAY_OPERATE ||
  506. pDcChargingInfo->SystemStatus == S_RESERVATION ) {
  507. pSysInfo->SystemPage = _PAGE_LINEPAYING;
  508. StartSystemTimeoutDet(Timeout_LINEPAYING);
  509. log_info("Some one online operate");
  510. return;
  511. }
  512. ShmDcCommonData->TradeCancel = FALSE;
  513. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus) {
  514. if ((pDcChargingInfo->SystemStatus == S_IDLE || isChargingEnd(pSysInfo->CurGunSelected)) &&
  515. ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE) {
  516. ShmDcCommonData->PreAuth_Config = _CREDITCARD_SALE;
  517. ShmDcCommonData->PreAuth_Result = 0;
  518. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  519. }
  520. } else {
  521. if ((pDcChargingInfo->SystemStatus == S_IDLE ) &&
  522. pSysInfo->SystemPage == _PAGE_SELECT_PAY &&
  523. ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE) {
  524. ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
  525. ShmDcCommonData->PreAuth_Result = 0;
  526. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  527. //log_info("Press Credit card pay status:%d Page:%d Config:%d", pDcChargingInfo->SystemStatus,
  528. // pSysInfo->SystemPage, ShmDcCommonData->PreAuth_Config);
  529. }
  530. }
  531. }
  532. void CheckPayLinePay()
  533. {
  534. log_info("Change to Add Line Friend Page");
  535. StopSystemTimeoutDet();
  536. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  537. pSysInfo->SystemPage = _PAGE_ADD_FRIEND;
  538. }
  539. void CheckTouchPress(short id)
  540. {
  541. GetDeviceInfoStatus(id,1);
  542. if (_btn_press >= 1 && _btn_press_id == id ) {
  543. _btn_press_count++;
  544. }
  545. if (_btn_press >= 1 && _btn_press_id == id && _btn_press_count >= 2) {
  546. ChangeDisplay2Value(id, 0);
  547. //log_info("Press id : 0x%04x",id);
  548. _btn_press_count = 0;
  549. switch (id) {
  550. case _Touch_Show_Left:
  551. if (pSysInfo->SystemPage >= _PAGE_BILL && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
  552. log_info("Authorize Process can't select gun");
  553. return;
  554. }
  555. // Show log
  556. if(pSysInfo->CurGunSelected != LEFT_GUN_NUM) {
  557. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  558. pSysInfo->CurGunSelected = LEFT_GUN_NUM;
  559. if(pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
  560. systemPageRestoreInit();
  561. }
  562. log_info("LCM left Gun down...............................%x %x %x",
  563. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  564. }
  565. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  566. if (ShmDcCommonData->pGunInfo[LEFT_GUN_NUM].ParkingStatus) {
  567. if (pDcChargingInfo->SystemStatus == S_COMPLETE || pDcChargingInfo->SystemStatus == S_ALARM) {
  568. if (ShmDcCommonData->PayPass_flag[LEFT_GUN_NUM] == TRUE)
  569. pSysInfo->SystemPage = _PAGE_COMPLETE;
  570. else {
  571. if (pDcChargingInfo->Replug_flag)
  572. pSysInfo->SystemPage = _PAGE_PLUGOUT;
  573. else
  574. pSysInfo->SystemPage = _PAGE_PAYFAIL;
  575. }
  576. }
  577. }
  578. if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
  579. pSysInfo->SystemPage == _PAGE_PAYFAIL) {
  580. StopSystemTimeoutDet();
  581. }
  582. break;
  583. case _Touch_Show_Right:
  584. if (pSysInfo->SystemPage >= _PAGE_BILL && pSysInfo->SystemPage <= _PAGE_PLUGIN) {
  585. log_info("Authorize Process can't select gun");
  586. return;
  587. }
  588. // Show log
  589. if(pSysInfo->CurGunSelected != RIGHT_GUN_NUM) {
  590. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  591. pSysInfo->CurGunSelected = RIGHT_GUN_NUM;
  592. if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION) {
  593. systemPageRestoreInit();
  594. }
  595. log_info("LCM Right Gun down...............................%x %x %x",
  596. pSysInfo->CurGunSelected,pDcChargingInfo->SystemStatus,pSysInfo->SystemPage);
  597. }
  598. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  599. if (ShmDcCommonData->pGunInfo[RIGHT_GUN_NUM].ParkingStatus) {
  600. if (pDcChargingInfo->SystemStatus == S_COMPLETE || pDcChargingInfo->SystemStatus == S_ALARM) {
  601. if (ShmDcCommonData->PayPass_flag[RIGHT_GUN_NUM] == TRUE)
  602. pSysInfo->SystemPage = _PAGE_COMPLETE;
  603. else
  604. if (pDcChargingInfo->Replug_flag)
  605. pSysInfo->SystemPage = _PAGE_PLUGOUT;
  606. else
  607. pSysInfo->SystemPage = _PAGE_PAYFAIL;
  608. }
  609. }
  610. if (pSysInfo->SystemPage == _PAGE_CHARGING || pSysInfo->SystemPage == _PAGE_COMPLETE ||
  611. pSysInfo->SystemPage == _PAGE_PAYFAIL) {
  612. StopSystemTimeoutDet();
  613. }
  614. break;
  615. case _Touch_Return:
  616. CheckReturnPress();
  617. break;
  618. case _Touch_IDLE:
  619. CheckIdlePress();
  620. break;
  621. case _Touch_StopCharge:
  622. CheckStopPress();
  623. break;
  624. case _Touch_Stop_Confirm:
  625. CheckStopConfirmPress();
  626. break;
  627. case _Touch_Stop_Cancel:
  628. CheckStopCancelPress();
  629. break;
  630. case _Touch_Select_Left:
  631. CheckConfirmGun(LEFT_GUN_NUM);
  632. break;
  633. case _Touch_Select_Right:
  634. CheckConfirmGun(RIGHT_GUN_NUM);
  635. break;
  636. case _Touch_DonateBill:
  637. StopSystemTimeoutDet();
  638. CheckDonateBill(pSysInfo->CurGunSelected);
  639. break;
  640. case _Touch_DonateYes:
  641. CheckDonateYes();
  642. break;
  643. case _Touch_DonateNo:
  644. CheckDonateNo();
  645. break;
  646. case _Touch_Pay_CreditCard:
  647. CheckPayCreditCard();
  648. break;
  649. case _Touch_Pay_LinePay:
  650. CheckPayLinePay();
  651. break;
  652. case _Touch_Parking_Complete:
  653. ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ReqParkingBill = TRUE;
  654. pSysInfo->SystemPage = _PAGE_PAYING;
  655. //log_info("Set Page to %d",pSysInfo->SystemPage);
  656. break;
  657. } // switch
  658. } //if (_btn_press >= 3)
  659. }
  660. void CheckLCMPressed()
  661. {
  662. pid_t Pid = fork();
  663. if ( Pid == 0 ) {
  664. while (1) {
  665. if (pSysInfo->SystemPage != _PAGE_SELECT_GUN && pSysInfo->SystemPage != _PAGE_IDLE) {
  666. CheckTouchPress(_Touch_Show_Left);
  667. CheckTouchPress(_Touch_Show_Right);
  668. }
  669. switch (pSysInfo->SystemPage) {
  670. case _PAGE_IDLE:
  671. //CheckTouchPress(_Touch_IDLE);
  672. CheckTouchPress(_Touch_Select_Left);
  673. CheckTouchPress(_Touch_Select_Right);
  674. break;
  675. case _PAGE_SELECT_GUN:
  676. CheckTouchPress(_Touch_Select_Left);
  677. CheckTouchPress(_Touch_Select_Right);
  678. break;
  679. case _PAGE_BILL:
  680. CheckTouchPress(_Touch_Return);
  681. CheckTouchPress(_Touch_DonateBill);
  682. CheckTouchPress(_Touch_Pay_LinePay);
  683. break;
  684. case _PAGE_ADD_FRIEND:
  685. CheckTouchPress(_Touch_Return);
  686. //CheckTouchPress(_Touch_DonateBill);
  687. break;
  688. case _PAGE_DONATE_LEFT:
  689. case _PAGE_DONATE_RIGHT:
  690. CheckTouchPress(_Touch_Return);
  691. CheckTouchPress(_Touch_DonateYes);
  692. CheckTouchPress(_Touch_DonateNo);
  693. break;
  694. case _PAGE_SELECT_PAY:
  695. CheckTouchPress(_Touch_Pay_CreditCard);
  696. CheckTouchPress(_Touch_Return);
  697. break;
  698. case _PAGE_PLUGIN:
  699. CheckTouchPress(_Touch_Return);
  700. break;
  701. ///*
  702. case _PAGE_CHARGING:
  703. CheckTouchPress(_Touch_StopCharge);
  704. break;
  705. case _PAGE_AUTHORIZE:
  706. CheckTouchPress(_Touch_Return);
  707. break;
  708. case _PAGE_STOP_CONFIRM_LEFT:
  709. case _PAGE_STOP_CONFIRM_RIGHT:
  710. StopSystemTimeoutDet();
  711. CheckTouchPress(_Touch_Stop_Confirm);
  712. CheckTouchPress(_Touch_Stop_Cancel);
  713. break;
  714. case _PAGE_EXIT:
  715. CheckTouchPress(_Touch_Return);
  716. break;
  717. case _PAGE_AUTHORIZE_FAIL:
  718. CheckTouchPress(_Touch_Return);
  719. break;
  720. case _PAGE_COMPLETE:
  721. case _PAGE_PAYFAIL:
  722. case _PAGE_PLUGOUT:
  723. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus >= _TCC_PARKING_OCCUPENCY)
  724. CheckTouchPress(_Touch_Parking_Complete);
  725. break;
  726. } // switch
  727. usleep(5000);
  728. } //while
  729. } // if pid
  730. log_info("Create LCM fork:%d\n\n",Pid);
  731. }
  732. void GetHrFormTimeString(char* time,char* hr)
  733. {
  734. //char tm[] = "2021-12-06 17:29:08:084";
  735. for(int i = 0 ; i < 2 ; i++) {
  736. hr[i] = time[i+11];
  737. }
  738. if( atoi(hr) < 0 || atoi(hr) > 24) {
  739. strcmp(hr,"");
  740. }
  741. }
  742. void GetMinFormTimeString(char* time,char* min)
  743. {
  744. //char tm[] = "2021-12-06 17:29:08:084";
  745. for(int i = 0 ; i < 2 ; i++) {
  746. min[i] = time[i+14];
  747. }
  748. if( atoi(min) < 0 || atoi(min) > 60) {
  749. strcmp(min,"");
  750. }
  751. }
  752. //================================================
  753. // Function
  754. //================================================
  755. void ChangeToOtherPage(short newPage)
  756. {
  757. uint8_t cmd[10];
  758. memset(cmd, 0x00, sizeof(cmd));
  759. uint8_t msg[9];
  760. memset(msg, 0x00, sizeof(msg));
  761. cmd[0] = CMD_TITLE_1;
  762. cmd[1] = CMD_TITLE_2;
  763. cmd[2] = 0x07;
  764. cmd[3] = 0x82;
  765. cmd[4] = 0x00;
  766. cmd[5] = 0x84;
  767. cmd[6] = 0x5A;
  768. cmd[7] = 0x01;
  769. cmd[8] = newPage >> 8;
  770. cmd[9] = newPage & 0x00FF;
  771. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  772. usleep(5000);
  773. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  774. }
  775. void ChangeBackLight(uint8_t value)
  776. {
  777. //uint8_t value = 0x01;
  778. uint8_t msg[9];
  779. memset(msg, 0x00, sizeof(msg));
  780. uint8_t cmd[7];
  781. memset(cmd, 0x00, sizeof(cmd));
  782. cmd[0] = CMD_TITLE_1;
  783. cmd[1] = CMD_TITLE_2;
  784. cmd[2] = 0x05;
  785. cmd[3] = CMD_MULTI_WRITE;
  786. cmd[4] = 0x00;
  787. cmd[5] = 0x82;
  788. cmd[6] = value;
  789. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  790. usleep(10000);
  791. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  792. }
  793. void GetCurrentPage()
  794. {
  795. uint8_t cmd[7];
  796. memset(cmd, 0x00, sizeof(cmd));
  797. uint8_t msg[9];
  798. memset(msg, 0x00, sizeof(msg));
  799. cmd[0] = CMD_TITLE_1;
  800. cmd[1] = CMD_TITLE_2;
  801. cmd[2] = 0x04; // 底下總長度
  802. cmd[3] = 0x83;
  803. cmd[4] = 0x00;
  804. cmd[5] = 0x14;
  805. cmd[6] = 0x01;
  806. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  807. usleep(5000);
  808. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  809. }
  810. //================================================
  811. // Warning process
  812. //================================================
  813. void string2ByteArray(uint8_t *input, uint8_t *output)
  814. {
  815. int loop;
  816. int i;
  817. loop = 0;
  818. i = 0;
  819. while (input[loop] != '\0') {
  820. output[i++] = input[loop++];
  821. }
  822. output[loop] = '\0';
  823. }
  824. void RefreshProgressAnimation()
  825. {
  826. _everyPageRollChange >= 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  827. }
  828. //================================================
  829. // Change current page
  830. //================================================
  831. void ChangeCurPage()
  832. {
  833. //log_info("cur = %d ,system = %d, lcm = %d ",_currentPage, pSysInfo->SystemPage, pSysInfo->PageIndex);
  834. if (pSysInfo->PageIndex != pSysInfo->SystemPage)
  835. log_info("Gun[%d] Chagne LCM Page:%d",pSysInfo->CurGunSelected, pSysInfo->SystemPage);
  836. pSysInfo->PageIndex = pSysInfo->SystemPage;
  837. if (_currentPage != pSysInfo->PageIndex) {
  838. switch (pSysInfo->SystemPage) {
  839. case _PAGE_AUTHORIZE:
  840. break;
  841. case _PAGE_PLUGIN:
  842. break;
  843. case _PAGE_PRECHARGE:
  844. break;
  845. case _PAGE_CHARGING:
  846. break;
  847. case _PAGE_COMPLETE:
  848. is_stop = FALSE;
  849. break;
  850. case _PAGE_PAYFAIL:
  851. is_stop = FALSE;
  852. break;
  853. case _PAGE_MAINTAIN:
  854. break;
  855. }
  856. _currentPage = pSysInfo->PageIndex;
  857. //if (pSysInfo->PageIndex != _PAGE_IDLE)
  858. ChangeToOtherPage(pSysInfo->PageIndex);
  859. }
  860. }
  861. /*
  862. * View Page
  863. *
  864. */
  865. unsigned long GetTimeoutValue(struct timeval _sour_time)
  866. {
  867. struct timeval _end_time;
  868. gettimeofday(&_end_time, NULL);
  869. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  870. }
  871. void showGunWorkingType()
  872. {
  873. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
  874. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  875. if (ShmDcCommonData->pGunInfo[LEFT_GUN_NUM].ParkingStatus) {
  876. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_LeftParkingSel);
  877. } else {
  878. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  879. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  880. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_On);
  881. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  882. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  883. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_On);
  884. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  885. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_On);
  886. }
  887. }
  888. // Set Right Gun
  889. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  890. if (ShmDcCommonData->pGunInfo[RIGHT_GUN_NUM].ParkingStatus) {
  891. ChangeDisplay2Value(_Icon_ShowRight,_TCC_RightParkingSel);
  892. } else {
  893. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  894. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  895. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  896. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  897. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  898. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  899. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  900. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  901. }
  902. }
  903. } else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM){
  904. // Left Gun
  905. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  906. if (ShmDcCommonData->pGunInfo[LEFT_GUN_NUM].ParkingStatus) {
  907. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_LeftParkingSel);
  908. } else {
  909. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  910. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  911. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  912. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  913. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  914. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  915. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  916. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  917. }
  918. }
  919. // Right Gun
  920. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  921. if (ShmDcCommonData->pGunInfo[RIGHT_GUN_NUM].ParkingStatus) {
  922. ChangeDisplay2Value(_Icon_ShowRight,_TCC_RightParkingSel);
  923. } else {
  924. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  925. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  926. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_On);
  927. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  928. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  929. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_On);
  930. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  931. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_On);
  932. }
  933. }
  934. }
  935. }
  936. void ClearQrCode_Idle()
  937. {
  938. char cmd[200];
  939. memset(cmd,0,200);
  940. DisplayValueToLcm(_QRCode_AddLine, cmd, 200);
  941. }
  942. void ChangeQrCode_Idle(char *input)
  943. {
  944. char cmd[256];
  945. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  946. int len = 0;
  947. memset(cmd,0,256);
  948. time_t timep;
  949. struct tm* tm;
  950. time(&timep);
  951. char SN[37];
  952. memset(SN,'\0',sizeof(SN));
  953. memcpy(SN,ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].OccupancySN,36);
  954. tm = localtime(&timep);
  955. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus && !ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingCntDownFlag) {
  956. tm->tm_year -= 50;
  957. ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingStopTime = mktime(tm) + 120 +(ShmDcCommonData->TZOffset * 60);
  958. ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingCntDownFlag = TRUE;
  959. tm = gmtime(&ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingStopTime);
  960. log_info("QR Code Show Time:(%d)%s",ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingStopTime,asctime(tm));
  961. }
  962. if (!ShmDcCommonData->tccdev) {
  963. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus) {
  964. len = sprintf(cmd, "https://nhoatcc.lineapid.tw/web/placeholder?sn=%s&ts=%d",SN,
  965. ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingStopTime);
  966. } else
  967. len = sprintf(cmd, "https://nhoatcc.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
  968. } else {
  969. if (ShmDcCommonData->pGunInfo[pSysInfo->CurGunSelected].ParkingStatus) {
  970. len = sprintf(cmd, "https://nhoatcctest.lineapid.tw/web/placeholder?sn=%s&ts=%d",SN,
  971. ShmDcCommonData->ParkingInfo[pSysInfo->CurGunSelected].ParkingStopTime);
  972. } else {
  973. len = sprintf(cmd, "https://nhoatcctest.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
  974. }
  975. }
  976. //log_info("QR Code:URL:%s",cmd);
  977. if (pSysInfo->SystemPage == _PAGE_ADD_FRIEND)
  978. DisplayValueToLcm(_QRCode_AddLine, cmd, len+1);
  979. }
  980. void ClearQrCode_Error()
  981. {
  982. char cmd[200];
  983. memset(cmd, 0, 200);
  984. DisplayValueToLcm(_QRCode_Service, cmd, 200);
  985. }
  986. void ChangeQrCode_Error()
  987. {
  988. char cmd[200];
  989. memset(cmd, 0, 200);
  990. sprintf(cmd, "https://line.me/R/ti/p/@217tcevc");
  991. //log_info("QR Code:URL:%s",cmd);
  992. DisplayValueToLcm(_QRCode_Service, cmd, 200);
  993. }
  994. /*
  995. void ChangeRemainTime(int sec)
  996. {
  997. int h, m, s;
  998. uint8_t cmd[10];
  999. uint8_t value[10];
  1000. memset(cmd, 0x00, sizeof(cmd));
  1001. // srand(time(NULL));
  1002. // int min = 0;
  1003. // int max = 65536;
  1004. // sec = rand() % (max - min + 1) + min;
  1005. h = (sec / 3600);
  1006. m = (sec - (3600 * h)) / 60;
  1007. s = (sec - (3600 * h) - (m * 60));
  1008. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  1009. string2ByteArray(value, cmd);
  1010. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  1011. }
  1012. */
  1013. void ShowSelectGun()
  1014. {
  1015. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  1016. if (ShmDcCommonData->pGunInfo[LEFT_GUN_NUM].ParkingStatus){
  1017. ChangeDisplay2Value(_Icon_Select_Left,_TCC_LeftParkingIdle);
  1018. } else if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
  1019. pDcChargingInfo->SystemStatus <= S_ALARM) ||
  1020. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
  1021. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
  1022. // 使用中
  1023. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1024. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1025. ChangeDisplay2Value(_Icon_Select_Left, _TCC_ShowLeftGunCharging_CCS1);
  1026. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1027. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1028. ChangeDisplay2Value(_Icon_Select_Left, _TCC_ShowLeftGunCharging_CCS2);
  1029. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1030. ChangeDisplay2Value(_Icon_Select_Left, _TCC_ShowLeftGunCharging_CHAdeMo);
  1031. }
  1032. } else if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  1033. // 預約中
  1034. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1035. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1036. ChangeDisplay2Value(_Icon_Select_Left, _TCC_ShowLeftGunReservation_CCS1);
  1037. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1038. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1039. ChangeDisplay2Value(_Icon_Select_Left, _TCC_ShowLeftGunReservation_CCS2);
  1040. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1041. ChangeDisplay2Value(_Icon_Select_Left, _TCC_ShowLeftGunReservation_CHAdeMo);
  1042. }
  1043. } else {
  1044. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1045. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1046. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS1);
  1047. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1048. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1049. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS2);
  1050. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1051. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CHAdeMo);
  1052. }
  1053. }
  1054. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1055. if (ShmDcCommonData->pGunInfo[RIGHT_GUN_NUM].ParkingStatus) {
  1056. ChangeDisplay2Value(_Icon_Select_Right,_TCC_RightParkingIdle);
  1057. } else if ((pDcChargingInfo->SystemStatus >= S_AUTHORIZING &&
  1058. pDcChargingInfo->SystemStatus <= S_ALARM) ||
  1059. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0 ||
  1060. pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1) {
  1061. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1062. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1063. ChangeDisplay2Value(_Icon_Select_Right, _TCC_ShowRightGunCharging_CCS1);
  1064. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1065. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1066. ChangeDisplay2Value(_Icon_Select_Right, _TCC_ShowRightGunCharging_CCS2);
  1067. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1068. ChangeDisplay2Value(_Icon_Select_Right, _TCC_ShowRightGunCharging_CHAdeMo);
  1069. }
  1070. } else if (pDcChargingInfo->SystemStatus == S_RESERVATION) {
  1071. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1072. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1073. ChangeDisplay2Value(_Icon_Select_Right, _TCC_ShowRightGunReservation_CCS1);
  1074. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1075. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1076. ChangeDisplay2Value(_Icon_Select_Right, _TCC_ShowRightGunReservation_CCS2);
  1077. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1078. ChangeDisplay2Value(_Icon_Select_Right, _TCC_ShowRightGunReservation_CHAdeMo);
  1079. }
  1080. } else {
  1081. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1082. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1083. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS1);
  1084. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1085. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1086. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS2);
  1087. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1088. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CHAdeMo);
  1089. }
  1090. }
  1091. }
  1092. void ChangeChargingPowerValue(float pow)
  1093. {
  1094. uint8_t cmd[10];
  1095. uint8_t value[10];
  1096. memset(cmd, 0x00, sizeof(cmd));
  1097. sprintf((char *) value, "%d",(int)pow);
  1098. string2ByteArray(value, cmd);
  1099. DisplayValueToLcm(_String_ChargePower, cmd, sizeof(cmd));
  1100. }
  1101. void ChangeChargingRateValue(float rate,int show)
  1102. {
  1103. uint8_t cmd[10];
  1104. uint8_t value[10];
  1105. memset(cmd, 0x00, sizeof(cmd));
  1106. if (show)
  1107. sprintf((char *) value, "%.1f",rate);
  1108. else
  1109. sprintf((char *) value, "");
  1110. string2ByteArray(value, cmd);
  1111. DisplayValueToLcm(_String_ChargeRate, cmd, sizeof(cmd));
  1112. }
  1113. void ChangeChargingFeeValue(float fee)
  1114. {
  1115. uint8_t cmd[10];
  1116. uint8_t value[10];
  1117. memset(cmd, 0x00, sizeof(cmd));
  1118. sprintf((char *) value, "%d", (int)fee);
  1119. string2ByteArray(value, cmd);
  1120. DisplayValueToLcm(_String_Money, cmd, sizeof(cmd));
  1121. }
  1122. void ChangeCarBonValue(float data)
  1123. {
  1124. uint8_t cmd[10];
  1125. uint8_t value[10];
  1126. float _carbon = 0;
  1127. memset(cmd, 0x00, sizeof(cmd));
  1128. _carbon = data * 0.577;
  1129. //log_info("Carbon:%d",(int)_carbon);
  1130. sprintf((char *) value, "%.1f", _carbon);
  1131. string2ByteArray(value, cmd);
  1132. DisplayValueToLcm(_String_Carbon, cmd, sizeof(cmd));
  1133. }
  1134. void ChangeChargingEnergyValue(float energy)
  1135. {
  1136. uint8_t cmd[10];
  1137. uint8_t value[10];
  1138. memset(cmd, 0x00, sizeof(cmd));
  1139. if (energy >= 0.05) {
  1140. energy -= 0.05;
  1141. }
  1142. if (energy < 0 )
  1143. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0);
  1144. else if (energy > 100)
  1145. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0+100);
  1146. else
  1147. ChangeDisplay2Value(_Icon_ChargeBar,(int)energy+_TCC_Charging_Bar0);
  1148. if (energy < 10)
  1149. sprintf((char *) value, "%.1f", energy);
  1150. else
  1151. sprintf((char *) value, "%d", (int)energy);
  1152. string2ByteArray(value, cmd);
  1153. DisplayValueToLcm(_Strting_Energy, cmd, sizeof(cmd));
  1154. }
  1155. void ChangeParkingRateValue(float fee,int show)
  1156. {
  1157. uint8_t cmd[10];
  1158. uint8_t value[10];
  1159. memset(cmd, 0x00, sizeof(cmd));
  1160. if (show)
  1161. sprintf((char *) value, "%d", (int)fee);
  1162. else
  1163. sprintf((char *) value, "");
  1164. string2ByteArray(value, cmd);
  1165. DisplayValueToLcm(_String_ParkRate, cmd, sizeof(cmd));
  1166. }
  1167. void ChangeParkingLeaveTime(int min,int show)
  1168. {
  1169. uint8_t cmd[10];
  1170. uint8_t value[10];
  1171. memset(cmd, 0x00, sizeof(cmd));
  1172. if (show)
  1173. sprintf((char *) value, "%d", (int)min);
  1174. else
  1175. sprintf((char *) value, "");
  1176. string2ByteArray(value, cmd);
  1177. DisplayValueToLcm(_String_ParkingLeaveTime, cmd, sizeof(cmd));
  1178. }
  1179. void ChangeSaleLeaveTime(int min,int show)
  1180. {
  1181. uint8_t cmd[10];
  1182. uint8_t value[10];
  1183. memset(cmd, 0x00, sizeof(cmd));
  1184. if (show)
  1185. sprintf((char *) value, "%d", (int)min);
  1186. else
  1187. sprintf((char *) value, "");
  1188. string2ByteArray(value, cmd);
  1189. DisplayValueToLcm(_String_SaleLeaveTime, cmd, sizeof(cmd));
  1190. }
  1191. uint8_t _battery_display_count = 0;
  1192. void ChangeBattMapAndValue(int soc)
  1193. {
  1194. int i = (soc*36)/100;
  1195. uint8_t cmd[5];
  1196. uint8_t value[5];
  1197. _battery_display_count++;
  1198. if (_battery_display_count == 3 ) {
  1199. if (_battery_display_ani == 0)
  1200. _battery_display_ani= TRUE;
  1201. else
  1202. _battery_display_ani= FALSE ;
  1203. _battery_display_count = 0;
  1204. }
  1205. if (pSysInfo->SystemPage == _PAGE_CHARGING) {
  1206. if (i>=36)
  1207. ChangeDisplay2Value(_Icon_ChargeCircle,_TCC_Charging_Circle0+36);
  1208. else {
  1209. if (_battery_display_ani) {
  1210. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i);
  1211. } else {
  1212. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i+1);
  1213. }
  1214. }
  1215. } else if (pSysInfo->SystemPage == _PAGE_COMPLETE)
  1216. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  1217. else
  1218. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_FAILCircle0 +i);
  1219. memset(cmd, 0x00, sizeof(cmd));
  1220. memset(value, 0x00, sizeof(value));
  1221. sprintf((char *)value, "%d", soc);
  1222. string2ByteArray(value, cmd);
  1223. DisplayValueToLcm(_String_Battery, cmd, sizeof(cmd));
  1224. }
  1225. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  1226. {
  1227. struct timeval _end_time;
  1228. gettimeofday(&_end_time, NULL);
  1229. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  1230. }
  1231. void ChangeTimeValue(int time)
  1232. {
  1233. uint8_t cmd[6];
  1234. uint8_t value[6];
  1235. memset(cmd, 0x00, sizeof(cmd));
  1236. sprintf((char *) value, "%d", time);
  1237. string2ByteArray(value, cmd);
  1238. DisplayValueToLcm(_String_ChargeTime, cmd, sizeof(cmd));
  1239. }
  1240. void changeWeatherValue(int _weather)
  1241. {
  1242. switch (_weather) {
  1243. case _WEATHER_TYPE_SUN:
  1244. ChangeDisplay2Value(_Icon_Weather,_TCC_Sun);
  1245. break;
  1246. case _WEATHER_TYPE_CLOUDY:
  1247. ChangeDisplay2Value(_Icon_Weather,_TCC_Cloudy);
  1248. break;
  1249. case _WEATHER_TYPE_RAIN:
  1250. ChangeDisplay2Value(_Icon_Weather,_TCC_Rain);
  1251. break;
  1252. case _WEATHER_TYPE_THUNDER:
  1253. ChangeDisplay2Value(_Icon_Weather,_TCC_Thunder);
  1254. break;
  1255. case _WEATHER_TYPE_SNOW:
  1256. ChangeDisplay2Value(_Icon_Weather,_TCC_Snow);
  1257. break;
  1258. case _WEATHER_TYPE_FOG:
  1259. ChangeDisplay2Value(_Icon_Weather,_TCC_Fog);
  1260. break;
  1261. }
  1262. }
  1263. void changeWeekValue(int _week)
  1264. {
  1265. time_t timep;
  1266. struct tm* tm;
  1267. time(&timep);
  1268. timep += (ShmDcCommonData->TZOffset * 60);
  1269. tm = localtime(&timep);
  1270. _week = tm->tm_wday;
  1271. if (_week == 0 )
  1272. _week = 7;
  1273. ChangeDisplay2Value(_Icon_Week,_week);
  1274. }
  1275. void changeDegreeValue(int _degree)
  1276. {
  1277. char value[16];
  1278. memset(value, 0x00, sizeof(value));
  1279. sprintf((char *)value,"%d",_degree);
  1280. DisplayValueToLcm(_String_Tempture, (uint8_t *)value, sizeof(value));
  1281. }
  1282. void changeDateValue(char* _date)
  1283. {
  1284. time_t timep;
  1285. struct tm* tm;
  1286. time(&timep);
  1287. timep += (ShmDcCommonData->TZOffset * 60);
  1288. tm = localtime(&timep);
  1289. sprintf(_date, "%04d/%02d/%02d",
  1290. tm->tm_year + 1900,
  1291. tm->tm_mon + 1,
  1292. tm->tm_mday);
  1293. char value[16];
  1294. memset(value, 0x00, sizeof(value));
  1295. sprintf((char *)value,"%s",_date);
  1296. DisplayValueToLcm(_String_Date, (uint8_t *)value, sizeof(value));
  1297. }
  1298. void changeLocationValue(int _location)
  1299. {
  1300. //_location+=1000;
  1301. //log_info("location:%d",_location);
  1302. ChangeDisplay2Value(_Icon_Location,(short)_location);
  1303. }
  1304. void ShowLineRegisterCountDown(int _show)
  1305. {
  1306. if(!_show) {
  1307. ChangeDisplay2Value(_Icon_ScanCntDw_BG,_ICON_Empty);
  1308. ChangeDisplay2Value(_Icon_ScanCntDownTen, _ICON_Empty);
  1309. ChangeDisplay2Value(_Icon_ScanCntDownDigits, _ICON_Empty);
  1310. return;
  1311. }
  1312. int _ten, _digits;
  1313. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1314. if (pDcChargingInfo->TimeoutFlag == Timeout_LineReigster) {
  1315. _ten = (TCC_LINEREGISTER_TIMEOUT - (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL)) / 10;
  1316. _digits = (TCC_LINEREGISTER_TIMEOUT - (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL)) % 10;
  1317. ChangeDisplay2Value(_Icon_ScanCntDw_BG,_TCC_Scan_CntDw_BG);
  1318. ChangeDisplay2Value(_Icon_ScanCntDownTen, (short)_TCC_CntDownNumber0+_ten);
  1319. ChangeDisplay2Value(_Icon_ScanCntDownDigits, (short)_TCC_CntDownNumber0+ _digits);
  1320. } else {
  1321. //log_info("Not get Line Register Count Down");
  1322. }
  1323. }
  1324. void ShowAuthorizeCountDown()
  1325. {
  1326. int _ten, _digits;
  1327. if (pSysInfo->SystemTimeoutFlag == Timeout_ScanCard) {
  1328. ChangeDisplay2Value(_Icon_ScanCntDw_BG,_TCC_Scan_CntDw_BG);
  1329. _ten = (TCC_SCANCARD_TIMEOUT - (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL)) / 10;
  1330. _digits = (TCC_SCANCARD_TIMEOUT - (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL)) % 10;
  1331. ChangeDisplay2Value(_Icon_AuthCntDownTen, (short)_TCC_CntDownNumber0 + _ten);
  1332. ChangeDisplay2Value(_Icon_AuthCntDownDigits, (short)_TCC_CntDownNumber0 + _digits);
  1333. }
  1334. else {
  1335. log_info("Not get Line Register Count Down");
  1336. }
  1337. }
  1338. void ShowParkingCountDown(int is_parking)
  1339. {
  1340. int _ten, _digits , _hun;
  1341. unsigned char time_flag;
  1342. int TimeoutTime;
  1343. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1344. if (is_parking) {
  1345. if (pSysInfo->SystemPage == _PAGE_ADD_FRIEND) {
  1346. time_flag = Timeout_ParkingBill;
  1347. TimeoutTime = TCC_PARKINGBILL_TIMEOUT;
  1348. } else {
  1349. time_flag = Timeout_ParkingSelect;
  1350. TimeoutTime = TCC_PARK_SELECTPAY_TIMEOUT;
  1351. }
  1352. if (pDcChargingInfo->TimeoutFlag == time_flag ) {
  1353. _hun = (TimeoutTime - (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL)) / 100;
  1354. _ten = ((TimeoutTime - (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL)) / 10)%10;
  1355. _digits = (TimeoutTime - (GetClockTimeoutValue(pDcChargingInfo->ConnectorTimeout) / uSEC_VAL)) % 10;
  1356. if (pSysInfo->SystemPage == _PAGE_ADD_FRIEND) {
  1357. ChangeDisplay2Value(_Icon_ParkingCntDw_BG, (short)_TCC_ParkingCntDown_BG3);
  1358. ChangeDisplay2Value(_Icon_ParkingCntDw_Hun, (short)_TCC_ParkingCD_0 + _hun);
  1359. ChangeDisplay2Value(_Icon_ParkingCntDw_Tens, (short)_TCC_ParkingCD_0 + _ten);
  1360. ChangeDisplay2Value(_Icon_ParkingCntDw_Digits, (short)_TCC_ParkingCD_0 + _digits);
  1361. } else {
  1362. ChangeDisplay2Value(_Icon_ParkingCntDw_BG, (short)_TCC_ParkingCntDown_BG);
  1363. ChangeDisplay2Value(_Icon_ParkingCntDw_Tens, (short)_TCC_ParkingCD_0 + _ten);
  1364. ChangeDisplay2Value(_Icon_ParkingCntDw_Digits, (short)_TCC_ParkingCD_0 + _digits);
  1365. }
  1366. }
  1367. else {
  1368. log_info("Not get Parking Count Down(%d)",pDcChargingInfo->TimeoutFlag);
  1369. }
  1370. } else {
  1371. ChangeDisplay2Value(_Icon_ParkingCntDw_BG, NULL);
  1372. ChangeDisplay2Value(_Icon_ParkingCntDw_Hun, NULL);
  1373. ChangeDisplay2Value(_Icon_ParkingCntDw_Tens, NULL);
  1374. ChangeDisplay2Value(_Icon_ParkingCntDw_Digits, NULL);
  1375. }
  1376. }
  1377. void changeGunType()
  1378. {
  1379. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
  1380. if (ShmDcCommonData->pGunInfo[LEFT_GUN_NUM].ParkingStatus) {
  1381. ChangeDisplay2Value(_Icon_Select_Left,_TCC_LeftParkingIdle);
  1382. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1383. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1384. ChangeDisplay2Value(_Icon_Select_Left, _TCC_IDLE_LEFT_CCS1);
  1385. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1386. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1387. ChangeDisplay2Value(_Icon_Select_Left, _TCC_IDLE_LEFT_CCS2);
  1388. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1389. ChangeDisplay2Value(_Icon_Select_Left, _TCC_IDLE_LEFT_CHAdeMo);
  1390. }
  1391. // Set Right Gun
  1392. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1393. if (ShmDcCommonData->pGunInfo[RIGHT_GUN_NUM].ParkingStatus) {
  1394. ChangeDisplay2Value(_Icon_Select_Right,_TCC_RightParkingIdle);
  1395. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1396. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1397. ChangeDisplay2Value(_Icon_Select_Right, _TCC_IDLE_RIGHT_CCS1);
  1398. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1399. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1400. ChangeDisplay2Value(_Icon_Select_Right, _TCC_IDLE_RIGHT_CCS2);
  1401. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1402. ChangeDisplay2Value(_Icon_Select_Right, _TCC_IDLE_RIGHT_CHAdeMo);
  1403. }
  1404. }
  1405. void ShowParkingInfo(bool is_show,uint8_t gunIndex)
  1406. {
  1407. char cmd[32];
  1408. if (is_show) {
  1409. ChangeDisplay2Value(_Icon_ParkingInfo,_TCC_ParkingInfo);
  1410. memset(cmd, 0x00, sizeof(cmd));
  1411. sprintf((char *)cmd,"%s",ShmDcCommonData->ParkingInfo[gunIndex].ParkingStartTime);
  1412. DisplayValueToLcm(_String_ParkingStartTime, (uint8_t *)cmd, sizeof(cmd));
  1413. memset(cmd, 0x00, sizeof(cmd));
  1414. sprintf((char *)cmd,"%d",ShmDcCommonData->ParkingInfo[gunIndex].ParkingDuration);
  1415. DisplayValueToLcm(_String_ParkingDuration, (uint8_t *)cmd, sizeof(cmd));
  1416. memset(cmd, 0x00, sizeof(cmd));
  1417. sprintf((char *)cmd,"%d",(int)ShmDcCommonData->ParkingInfo[gunIndex].Amount);
  1418. DisplayValueToLcm(_String_ParkingFee, (uint8_t *)cmd, sizeof(cmd));
  1419. } else {
  1420. if (pSysInfo->SystemPage == _PAGE_BILL) {
  1421. ChangeDisplay2Value(_Icon_ParkingInfo,_TCC_ICON_SelectChargeMode);
  1422. } else if (pSysInfo->SystemPage >= _PAGE_ADD_FRIEND && pSysInfo->SystemPage <= _PAGE_AUTHORIZE) {
  1423. ChangeDisplay2Value(_Icon_ParkingInfo,_TCC_ICON_SelectPayMode);
  1424. } else {
  1425. ChangeDisplay2Value(_Icon_ParkingInfo,NULL);
  1426. }
  1427. memset(cmd, 0x00, sizeof(cmd));
  1428. DisplayValueToLcm(_String_ParkingStartTime, (uint8_t *)cmd, sizeof(cmd));
  1429. DisplayValueToLcm(_String_ParkingDuration, (uint8_t *)cmd, sizeof(cmd));
  1430. DisplayValueToLcm(_String_ParkingFee, (uint8_t *)cmd, sizeof(cmd));
  1431. }
  1432. if (pSysInfo->SystemPage >= _PAGE_BILL && pSysInfo->SystemPage <= _PAGE_SELECT_PAY)
  1433. ShowParkingCountDown(is_show);
  1434. }
  1435. int old_money = 0;
  1436. int ClearQR_flag[2];
  1437. void ProcessPageInfo()
  1438. {
  1439. if (ShmDcCommonData->CreditCardUpload) {
  1440. pSysInfo->SystemPage = _PAGE_PAYING;
  1441. }
  1442. // Show Gun Working and Type
  1443. if (pSysInfo->SystemPage == _PAGE_IDLE) {
  1444. changeWeatherValue(ShmDcCommonData->WeatherID);
  1445. changeWeekValue(0);
  1446. changeDegreeValue((int)ShmDcCommonData->Temperature);
  1447. changeDateValue(&ShmDcCommonData->PresentTime[0]);
  1448. changeLocationValue(1000);
  1449. changeGunType();
  1450. ClearQR_flag[pSysInfo->CurGunSelected] = FALSE;
  1451. return;
  1452. }
  1453. if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
  1454. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  1455. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1456. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1457. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  1458. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1459. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1460. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  1461. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1462. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  1463. }
  1464. // Set Right Gun
  1465. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1466. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1467. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1468. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  1469. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1470. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1471. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  1472. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1473. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  1474. }
  1475. ChangeQrCode_Error();
  1476. return;
  1477. }
  1478. showGunWorkingType();
  1479. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1480. if (pSysInfo->CurGunSelected == i) {
  1481. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(i);
  1482. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  1483. _everyPageRollChange = 0;
  1484. _Text_Running_Count = 1;
  1485. }
  1486. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1487. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1488. ChangeDisplay2Value(_Icon_Return,NULL);
  1489. } else {
  1490. ChangeDisplay2Value(_Icon_Return,_TCC_Return);
  1491. }
  1492. ShowParkingCountDown(FALSE);
  1493. } else {
  1494. ChangeDisplay2Value(_Icon_Return,_TCC_Return);
  1495. }
  1496. switch (pSysInfo->SystemPage) {
  1497. case _PAGE_IDLE:
  1498. ShowSelectGun();
  1499. ClearQR_flag[i] = FALSE;
  1500. break;
  1501. case _PAGE_SELECT_PAY:
  1502. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1503. ShowParkingInfo(true,i);
  1504. } else {
  1505. ShowParkingInfo(false,i);
  1506. }
  1507. break;
  1508. case _PAGE_SELECT_GUN:
  1509. ShowSelectGun();
  1510. ClearQR_flag[i] = FALSE;
  1511. break;
  1512. case _PAGE_BILL:
  1513. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1514. ChangeDisplay2Value(_Icon_Add_Line,_TCC_ParkingLine);
  1515. ChangeDisplay2Value(_Icon_Donate,_TCC_ParkingDonate);
  1516. ShowParkingInfo(true,i);
  1517. } else {
  1518. ChangeDisplay2Value(_Icon_Add_Line,_TCC_GetBill);
  1519. ChangeDisplay2Value(_Icon_Donate,_TCC_DonateBill);
  1520. ShowParkingInfo(false,i);
  1521. }
  1522. break;
  1523. case _PAGE_AUTHORIZE:
  1524. StartSystemTimeoutDet(Timeout_ScanCard);
  1525. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1526. ShowParkingInfo(true,i);
  1527. ChangeDisplay2Value(_Icon_CreditCardFrame,_TCC_ParkingFee);
  1528. ChangeChargingRateValue(ShmDcCommonData->ChargingRate,FALSE);
  1529. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,FALSE);
  1530. ChangeParkingLeaveTime(ShmDcCommonData->ParkingLeaveTime,FALSE);
  1531. } else {
  1532. ShowParkingInfo(false,i);
  1533. ChangeDisplay2Value(_Icon_CreditCardFrame,_TCC_CardSensing_Frame);
  1534. ChangeChargingRateValue(ShmDcCommonData->ChargingRate,TRUE);
  1535. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,TRUE);
  1536. ChangeParkingLeaveTime(ShmDcCommonData->ParkingLeaveTime,TRUE);
  1537. }
  1538. ShowAuthorizeCountDown();
  1539. break;
  1540. case _PAGE_SENSING:
  1541. if (ShmDcCommonData->TradeCancel == TRUE) {
  1542. TradeRunning(FALSE);
  1543. }
  1544. else
  1545. TradeRunning(TRUE);
  1546. break;
  1547. case _PAGE_PLUGIN:
  1548. _everyPageRollChange = 0;
  1549. if (ShmDcCommonData->pGunInfo[i].isParking) {
  1550. ChangeDisplay2Value(_Icon_PreAuth_Complete,_TCC_ParkingLeave);
  1551. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,FALSE);
  1552. ChangeParkingLeaveTime(ShmDcCommonData->ParkingLeaveTime,FALSE);
  1553. ChangeSaleLeaveTime(ShmDcCommonData->SaleLeaveTime,TRUE);
  1554. } else {
  1555. ChangeDisplay2Value(_Icon_PreAuth_Complete,_TCC_PaySuccess);
  1556. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,TRUE);
  1557. ChangeParkingLeaveTime(ShmDcCommonData->ParkingLeaveTime,TRUE);
  1558. ChangeSaleLeaveTime(ShmDcCommonData->SaleLeaveTime,FALSE);
  1559. }
  1560. break;
  1561. case _PAGE_ADD_FRIEND:
  1562. if(ClearQR_flag[i] == FALSE) {
  1563. ClearQrCode_Idle();
  1564. ClearQR_flag[i] = TRUE;
  1565. }
  1566. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1567. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1568. ShowParkingInfo(true,i);
  1569. ShowLineRegisterCountDown(FALSE);
  1570. } else {
  1571. ShowLineRegisterCountDown(TRUE);
  1572. ShowParkingInfo(false,i);
  1573. }
  1574. break;
  1575. case _PAGE_PRECHARGE:
  1576. RefreshProgressAnimation();
  1577. if (_everyPageRollChange == 0) {
  1578. ChangeDisplay2Value(_Icon_Precharge,_Text_Running_Count);
  1579. _Text_Running_Count >= 24 ? _Text_Running_Count = 24 : _Text_Running_Count++;
  1580. }
  1581. break;
  1582. case _PAGE_CHARGING:
  1583. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  1584. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1585. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  1586. } else {
  1587. ChangeChargingPowerValue(0);
  1588. }
  1589. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1590. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1591. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1592. } else {
  1593. ChangeChargingEnergyValue(0);
  1594. }
  1595. if ( pDcChargingInfo->ChargingFee >= 0) {
  1596. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  1597. }
  1598. if (pDcChargingInfo->RemainChargingDuration >= 0 &&
  1599. pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
  1600. ChangeTimeValue(pDcChargingInfo->RemainChargingDuration/60);
  1601. } else {
  1602. ChangeTimeValue(0);
  1603. }
  1604. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1605. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1606. break;
  1607. case _PAGE_COMPLETE:
  1608. case _PAGE_PAYFAIL:
  1609. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1610. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1611. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1612. } else {
  1613. ChangeChargingEnergyValue(0);
  1614. }
  1615. ChangeChargingFeeValue(ShmDcCommonData->TransactionInfo[i].Amount);
  1616. ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
  1617. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1618. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1619. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,FALSE);
  1620. ChangeDisplay2Value(_Icon_CompleteBtn,_TCC_ParkingComplete);
  1621. } else {
  1622. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,TRUE);
  1623. ChangeDisplay2Value(_Icon_CompleteBtn,_TCC_NoParkingComplete);
  1624. }
  1625. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1626. break;
  1627. case _PAGE_PLUGOUT:
  1628. if (ShmDcCommonData->pGunInfo[i].ParkingStatus) {
  1629. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,FALSE);
  1630. ChangeDisplay2Value(_Icon_CompleteBtn,_TCC_ParkingComplete);
  1631. } else {
  1632. ChangeParkingRateValue(ShmDcCommonData->ParkingRate,TRUE);
  1633. ChangeDisplay2Value(_Icon_CompleteBtn,NULL);
  1634. }
  1635. break;
  1636. case _PAGE_PAYING:
  1637. ChangeDisplay2Value(_Icon_Ani_Dot, 1);
  1638. if (ShmDcCommonData->CreditCardUpload) {
  1639. ChangeDisplay2Value(_Icon_Uploading, _TCC_Uploading);
  1640. ChangeDisplay2Value(_Icon_Paying, _ICON_Empty);
  1641. } else {
  1642. if (ShmDcCommonData->StopCharge[i]) {
  1643. ChangeDisplay2Value(_Icon_Uploading, _ICON_Empty);
  1644. ChangeDisplay2Value(_Icon_Paying, _TCC_Paying);
  1645. } else if (ShmDcCommonData->pGunInfo[i].isParking){
  1646. ChangeDisplay2Value(_Icon_Uploading, _TCC_WaitParkInfo);
  1647. ChangeDisplay2Value(_Icon_Paying, _ICON_Empty);
  1648. }
  1649. }
  1650. break;
  1651. case _PAGE_EXIT:
  1652. break;
  1653. case _PAGE_LINEPAYING:
  1654. StartSystemTimeoutDet(Timeout_LINEPAYING);
  1655. break;
  1656. case _PAGE_MAINTAIN:
  1657. ChangeQrCode_Error();
  1658. break;
  1659. }
  1660. }
  1661. }
  1662. }
  1663. /*
  1664. void InformationShow()
  1665. {
  1666. is_show = true;
  1667. if (_showInformIndex == 0 ) {
  1668. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  1669. } else {
  1670. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  1671. ShowDispenserVersion();
  1672. }
  1673. }
  1674. */
  1675. void DefautLayOut()
  1676. {
  1677. int i;
  1678. for (i = 0 ; i <= 0x5C ; i+=2 ) {
  1679. ChangeDisplay2Value(0x1000+i,1);
  1680. if (i==0x28 || i ==0x2A)
  1681. continue;
  1682. }
  1683. ChangeDisplay2Value(_Icon_MobilePay,0);
  1684. ChangeDisplay2Value(_Icon_CardPay,0);
  1685. ChangeDisplay2Value(0x5000,1);
  1686. //ChangeDisplay2Value(_QRCode_Service, 1);
  1687. ShowSelectGun();
  1688. }
  1689. /*
  1690. static int InitialRfidPort(void)
  1691. {
  1692. int fd = open(rfidPortName, O_RDWR);
  1693. struct termios tios;
  1694. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1695. if (fd != FAIL) {
  1696. ioctl (fd, TCGETS, &tios);
  1697. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  1698. tios.c_lflag = 0;
  1699. tios.c_iflag = 0;
  1700. tios.c_oflag = 0;
  1701. tios.c_cc[VMIN] = 0;
  1702. tios.c_cc[VTIME] = (uint8_t) 1;
  1703. tios.c_lflag = 0;
  1704. tcflush(fd, TCIFLUSH);
  1705. ioctl(fd, TCSETS, &tios);
  1706. }
  1707. if (fd < 0) {
  1708. pAlarmCode->AlarmEvents.bits.RfidModuleCommFail = 1;
  1709. }
  1710. return fd;
  1711. }
  1712. */
  1713. void DemoFunction(int index)
  1714. {
  1715. int i;
  1716. showGunWorkingType();
  1717. switch (index) {
  1718. case 1: // _PAGE_IDLE
  1719. /*
  1720. for (i = 0; i <= 100; i++) {
  1721. changeWeatherValue(i / 20);
  1722. ChangeDisplay2Value(_Icon_Week, i / 15);
  1723. changeDegreeValue(i);
  1724. sprintf(text, "20%02d/%02d/%02d %02d:%02d:%02d", i, i, i, i, i, i);
  1725. DisplayValueToLcm(_String_Date, (uint8_t*)text, 30);
  1726. usleep(100000);
  1727. }
  1728. */
  1729. break;
  1730. case 3:
  1731. ChangeQrCode_Idle((char*)pSysConfig->SystemId);
  1732. sleep(3);
  1733. break;
  1734. case 4: //_PAGE_ADD_FRIEND
  1735. for (i = 0; i <= 10; i++) {
  1736. ChangeDisplay2Value(_Icon_ScanCntDownTen, (short)_TCC_CntDownNumber0 + i);
  1737. ChangeDisplay2Value(_Icon_ScanCntDownDigits, (short)_TCC_CntDownNumber0 + i);
  1738. usleep(100000);
  1739. }
  1740. break;
  1741. case 7: //_PAGE_AUTHORIZE
  1742. for (i = 0; i < 10; i++) {
  1743. ChangeChargingRateValue(i+i*10,TRUE);
  1744. ChangeDisplay2Value(_Icon_AuthCntDownTen, (short)_TCC_CntDownNumber0 + i);
  1745. ChangeDisplay2Value(_Icon_AuthCntDownDigits, (short)_TCC_CntDownNumber0 + i);
  1746. usleep(100000);
  1747. }
  1748. break;
  1749. case 8: //_PAGE_SENSING
  1750. for (i = 0; i < 10; i++) {
  1751. ChangeDisplay2Value(_Icon_CancelCntDownTen, (short)(_TCC_CancelNum_0 + i));
  1752. ChangeDisplay2Value(_Icon_CancelCntDownDigits, (short)(_TCC_CancelNum_0 + i));
  1753. usleep(100000);
  1754. }
  1755. break;
  1756. case 10: //_PAGE_PRECHARGE
  1757. for (i = 1; i <= 24; i++) {
  1758. ChangeDisplay2Value(_Icon_Precharge, i);
  1759. usleep(100000);
  1760. }
  1761. break;
  1762. case 11: //_PAGE_CHARGING
  1763. for (i = 0; i <= 100; i++) {
  1764. ChangeChargingPowerValue(i);
  1765. ChangeChargingEnergyValue(i);
  1766. ChangeChargingFeeValue(i);
  1767. ChangeTimeValue(i);
  1768. ChangeBattMapAndValue(i);
  1769. usleep(100000);
  1770. }
  1771. break;
  1772. case 13: //_PAGE_PAYING
  1773. break;
  1774. case 14: //_PAGE_COMPLETE
  1775. case 20: //_PAGE_PAYFAIL
  1776. for (i = 0; i <= 100; i++) {
  1777. ChangeChargingEnergyValue(i);
  1778. ChangeChargingFeeValue(i);
  1779. ChangeCarBonValue(i*2);
  1780. ChangeBattMapAndValue(i);
  1781. usleep(100000);
  1782. }
  1783. break;
  1784. }
  1785. sleep(1);
  1786. }
  1787. int main(void)
  1788. {
  1789. bool defaulttext = false;
  1790. if (CreateAllCsuShareMemory() == FAIL) {
  1791. log_error("create share memory error");
  1792. return FAIL;
  1793. }
  1794. MappingGunChargingInfo("LCM Control Task");
  1795. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1796. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1797. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1798. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  1799. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1800. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1801. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1802. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  1803. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  1804. _port = CreateCommunicationLcmPort();
  1805. uint8_t changeWarningPriority = 0;
  1806. uint8_t curWarningCount = 255;
  1807. uint8_t light = 0x64;
  1808. ShmDcCommonData->BackLight = light;
  1809. ChangeBackLight(light);
  1810. _totalCount = pSysConfig->TotalConnectorCount;
  1811. _everyPageRollChange = 0;
  1812. //Initialization();
  1813. //printf("_LCM_COMPLETE ");
  1814. //ChangeToOtherPage(_LCM_COMPLETE);
  1815. DefautLayOut();
  1816. //return 0;
  1817. uint8_t index = 1;
  1818. ShmDcCommonData->PSU_Number = 12;
  1819. /*
  1820. CardReadFd = InitialRfidPort();
  1821. if (CardReadFd <0) {
  1822. log_info("Card Read Port open fail!");
  1823. }*/
  1824. CheckLCMPressed();
  1825. while (_port != -1) {
  1826. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  1827. GetCurrentPage();
  1828. sleep(1);
  1829. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1830. } else {
  1831. UpdateLcmFunction(ShmDcCommonData,_port);
  1832. if (ShmDcCommonData->BackLight != light) {
  1833. ChangeBackLight(ShmDcCommonData->BackLight);
  1834. light = ShmDcCommonData->BackLight;
  1835. log_info("Set Backlight:%d",light);
  1836. }
  1837. ///*
  1838. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1839. // 頁面資訊處理
  1840. if (!ShmDcCommonData->lcmtest)
  1841. ProcessPageInfo();
  1842. else
  1843. pSysInfo->SystemPage = index;
  1844. // 換頁處理
  1845. //GetCurrentPage(); //DS60-120 add
  1846. /*
  1847. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1848. InformationShow();
  1849. ChangeToOtherPage(pSysInfo->PageIndex);
  1850. usleep(100000);
  1851. continue;
  1852. } else {
  1853. if (is_show)
  1854. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1855. is_show = false;
  1856. }*/
  1857. GetCurrentPage(); //DS60-120 add
  1858. ChangeCurPage();
  1859. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1860. if (ShmDcCommonData->lcmtest) {
  1861. DemoFunction(index);
  1862. index >= 20 ? index = 1 : index++;
  1863. }
  1864. usleep(10000); //*/
  1865. /*
  1866. GetCurrentPage();
  1867. ChangeCurPage();
  1868. usleep(10000);
  1869. //*/
  1870. }
  1871. } //while
  1872. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1873. log_info("Close LCM Uart Port");
  1874. CloseCommunicationLcmPort();
  1875. return FAIL;
  1876. }