Module_LcmControl.c 61 KB

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