Module_LcmControl.c 60 KB

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