Module_LcmControl.c 63 KB

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