Module_LcmControl.c 63 KB

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