Module_LcmControl.c 59 KB

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