Module_LcmControl.c 63 KB

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