Module_LcmControl.c 65 KB

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