Module_LcmControl.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755
  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. if ( pDcChargingInfo->SystemStatus == S_AUTHORIZING ) {
  310. ShmDcCommonData->TradeCancel = TRUE;
  311. /*
  312. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE ) {
  313. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  314. } else if (pSysInfo->SystemPage == _PAGE_PLUGIN)
  315. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  316. */
  317. for (i = 0; i <= 30; i++) {
  318. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  319. break;
  320. sleep(1);
  321. }
  322. pSysInfo->SystemPage = _PAGE_SENSING;
  323. StopGunInfoTimeoutDet(pSysInfo->CurGunSelected);
  324. StartSystemTimeoutDet(Timeout_TradeCancel);
  325. ShmDcCommonData->PreAuth_Result = 0;
  326. log_info("Press Return button cancel PreAuth");
  327. ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
  328. ShmDcCommonData->PreAuth_Result = 0;
  329. for(i=0;i<=30;i++) {
  330. if(ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  331. break;
  332. sleep(1);
  333. }
  334. ShmDcCommonData->PreAuth_Result = 0;
  335. StopSystemTimeoutDet();
  336. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  337. pDcChargingInfo->SystemStatus = S_IDLE;
  338. strcpy((char *)pSysConfig->UserId, "");
  339. return;
  340. }
  341. if (pDcChargingInfo->SystemStatus == S_IDLE && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  342. ShmDcCommonData->TradeCancel = TRUE;
  343. pSysInfo->SystemPage = _PAGE_SENSING;
  344. StartSystemTimeoutDet(Timeout_TradeCancel);
  345. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_PREAUTH) {
  346. for (i = 0; i <= 30; i++) {
  347. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  348. break;
  349. sleep(1);
  350. }
  351. ShmDcCommonData->PreAuth_Result = 0;
  352. if (ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] == TRUE) {
  353. ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
  354. ShmDcCommonData->PreAuth_Result = 0;
  355. for (i = 0; i <= 30; i++) {
  356. if (ShmDcCommonData->PreAuth_Config == _CREDITCARD_IDLE)
  357. break;
  358. sleep(1);
  359. }
  360. }
  361. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  362. }
  363. return;
  364. }
  365. if ( pSysInfo->SystemPage == _PAGE_EXIT ) {
  366. StopSystemTimeoutDet();
  367. pDcChargingInfo->SystemStatus = S_IDLE;
  368. pSysInfo->SystemPage = _PAGE_IDLE;
  369. return;
  370. }
  371. if (pSysInfo->SystemPage == _PAGE_AUTHORIZE)
  372. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  373. else
  374. pSysInfo->SystemPage = _PAGE_SELECT_GUN;
  375. }
  376. void CheckStopPress()
  377. {
  378. is_stop = TRUE;
  379. //ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
  380. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM)
  381. pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_LEFT;
  382. else
  383. pSysInfo->SystemPage = _PAGE_STOP_CONFIRM_RIGHT;
  384. }
  385. void CheckStopConfirmPress()
  386. {
  387. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  388. pDcChargingInfo->SystemStatus = S_TERMINATING;
  389. pSysInfo->SystemPage = _PAGE_PAYING;
  390. is_stop = FALSE;
  391. ShmDcCommonData->StopCharge[pSysInfo->CurGunSelected] = TRUE;
  392. if (ShmDcCommonData->is_AutoStart[pSysInfo->CurGunSelected] == TRUE) {
  393. pSysInfo->SystemPage = _PAGE_COMPLETE;
  394. return;
  395. }
  396. StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_FinalCost);
  397. /*
  398. ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
  399. ShmDcCommonData->PreAuth_Result = 0;
  400. */
  401. }
  402. void CheckStopCancelPress()
  403. {
  404. is_stop = FALSE;
  405. //ChangeDisplay2Value(_ConfirmStopIcon,is_stop);
  406. pSysInfo->SystemPage = _PAGE_CHARGING;
  407. }
  408. void CheckConfirmGun(uint8_t gunIndex)
  409. {
  410. pSysInfo->CurGunSelected = gunIndex;
  411. pSysInfo->SystemPage = _PAGE_BILL;
  412. }
  413. void CheckDonateBill(uint8_t gunIndex)
  414. {
  415. if (gunIndex == LEFT_GUN_NUM) {
  416. pSysInfo->SystemPage = _PAGE_DONATE_LEFT;
  417. } else
  418. pSysInfo->SystemPage = _PAGE_DONATE_RIGHT;
  419. }
  420. void CheckDonateYes()
  421. {
  422. pSysInfo->SystemPage = _PAGE_SELECT_PAY;
  423. ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = TRUE;
  424. }
  425. void CheckDonateNo()
  426. {
  427. pSysInfo->SystemPage = _PAGE_BILL;
  428. ShmDcCommonData->TransactionInfo[pSysInfo->CurGunSelected].IsDonateInvoice = FALSE;
  429. }
  430. void CheckPayCreditCard()
  431. {
  432. ShmDcCommonData->LineStatus[pSysInfo->CurGunSelected] = 0;
  433. ShmDcCommonData->TradeCancel = FALSE;
  434. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  435. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  436. //confirmSelGun(pSysInfo->CurGunSelected);
  437. ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
  438. ShmDcCommonData->PreAuth_Result = 0;
  439. //setSelGunWaitToAuthor(pSysInfo->CurGunSelected);
  440. pSysInfo->SystemPage = _PAGE_AUTHORIZE;
  441. //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
  442. //
  443. //AuthorizingStart();
  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",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. //log_info("Chagne Page:%d",pSysInfo->PageIndex);
  741. ChangeToOtherPage(pSysInfo->PageIndex);
  742. }
  743. }
  744. /*
  745. * View Page
  746. *
  747. */
  748. unsigned long GetTimeoutValue(struct timeval _sour_time)
  749. {
  750. struct timeval _end_time;
  751. gettimeofday(&_end_time, NULL);
  752. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  753. }
  754. void showGunWorkingType()
  755. {
  756. if (pSysInfo->CurGunSelected == LEFT_GUN_NUM) {
  757. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  758. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  759. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  760. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_On);
  761. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  762. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  763. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_On);
  764. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  765. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_On);
  766. }
  767. // Set Right Gun
  768. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  769. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  770. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  771. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  772. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  773. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  774. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  775. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  776. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  777. }
  778. } else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM){
  779. // Left Gun
  780. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  781. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  782. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  783. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  784. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  785. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  786. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  787. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  788. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  789. }
  790. // Right Gun
  791. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  792. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  793. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  794. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_On);
  795. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  796. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  797. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_On);
  798. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  799. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_On);
  800. }
  801. }
  802. }
  803. void ClearQrCode_Idle()
  804. {
  805. char cmd[200];
  806. memset(cmd,0,200);
  807. DisplayValueToLcm(_QRCode_AddLine, cmd, 200);
  808. }
  809. void ChangeQrCode_Idle(char *input)
  810. {
  811. char cmd[256];
  812. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  813. // https://nhoatcc.lineapid.tw/web/tologin?sn=ABC123&cid=2
  814. memset(cmd,0,256);
  815. int len = sprintf(cmd,"https://nhoatcc.lineapid.tw/web/tologin?sn=%s&cid=%d",input,ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
  816. //int len = sprintf(cmd, "https://nhoatcctest.lineapid.tw/web/tologin?sn=%s&cid=%d", input, ShmDcCommonData->ConnectorID[pSysInfo->CurGunSelected]);
  817. //log_info("QR Code:URL:%s",cmd);
  818. if (pSysInfo->SystemPage == _PAGE_BILL)
  819. DisplayValueToLcm(_QRCode_AddLine, cmd, len+1);
  820. }
  821. void ClearQrCode_Error()
  822. {
  823. char cmd[200];
  824. memset(cmd, 0, 200);
  825. DisplayValueToLcm(_QRCode_Service, cmd, 200);
  826. }
  827. void ChangeQrCode_Error()
  828. {
  829. char cmd[200];
  830. memset(cmd, 0, 200);
  831. int len = sprintf(cmd, "https://line.me/R/ti/p/@217tcevc");
  832. //log_info("QR Code:URL:%s",cmd);
  833. DisplayValueToLcm(_QRCode_Service, cmd, 200);
  834. }
  835. /*
  836. void ChangeRemainTime(int sec)
  837. {
  838. int h, m, s;
  839. uint8_t cmd[10];
  840. uint8_t value[10];
  841. memset(cmd, 0x00, sizeof(cmd));
  842. // srand(time(NULL));
  843. // int min = 0;
  844. // int max = 65536;
  845. // sec = rand() % (max - min + 1) + min;
  846. h = (sec / 3600);
  847. m = (sec - (3600 * h)) / 60;
  848. s = (sec - (3600 * h) - (m * 60));
  849. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  850. string2ByteArray(value, cmd);
  851. DisplayValueToLcm(_Text_Time, cmd, sizeof(cmd));
  852. }
  853. */
  854. void ShowSelectGun()
  855. {
  856. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  857. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  858. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  859. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  860. ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CCS1);
  861. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  862. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  863. ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CCS2);
  864. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  865. ChangeDisplay2Value(_Icon_Select_Left,_TCC_ShowLeftGunCharging_CHAdeMo);
  866. }
  867. } else {
  868. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  869. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  870. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS1);
  871. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  872. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  873. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CCS2);
  874. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  875. ChangeDisplay2Value(_Icon_Select_Left,_TCC_SelectLeft_CHAdeMo);
  876. }
  877. }
  878. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  879. if (pDcChargingInfo->SystemStatus == S_CHARGING) {
  880. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  881. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  882. ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CCS1);
  883. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  884. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  885. ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CCS2);
  886. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  887. ChangeDisplay2Value(_Icon_Select_Right,_TCC_ShowRightGunCharging_CHAdeMo);
  888. }
  889. } else {
  890. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  891. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  892. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS1);
  893. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  894. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  895. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CCS2);
  896. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  897. ChangeDisplay2Value(_Icon_Select_Right,_TCC_SelectRight_CHAdeMo);
  898. }
  899. }
  900. }
  901. void ChangeChargingPowerValue(float pow)
  902. {
  903. uint8_t cmd[10];
  904. uint8_t value[10];
  905. memset(cmd, 0x00, sizeof(cmd));
  906. sprintf((char *) value, "%d",(int)pow);
  907. string2ByteArray(value, cmd);
  908. DisplayValueToLcm(_String_ChargePower, cmd, sizeof(cmd));
  909. }
  910. void ChangeChargingRateValue(int rate)
  911. {
  912. uint8_t cmd[10];
  913. uint8_t value[10];
  914. memset(cmd, 0x00, sizeof(cmd));
  915. if (rate == 0) {
  916. log_info("Doesn't get Charge Fee");
  917. }
  918. sprintf((char *) value, "%d",rate);
  919. string2ByteArray(value, cmd);
  920. DisplayValueToLcm(_String_ChargeRate, cmd, sizeof(cmd));
  921. }
  922. void ChangeChargingFeeValue(float fee)
  923. {
  924. uint8_t cmd[10];
  925. uint8_t value[10];
  926. memset(cmd, 0x00, sizeof(cmd));
  927. sprintf((char *) value, "%d", (int)fee);
  928. string2ByteArray(value, cmd);
  929. DisplayValueToLcm(_String_Money, cmd, sizeof(cmd));
  930. }
  931. void ChangeCarBonValue(float data)
  932. {
  933. uint8_t cmd[10];
  934. uint8_t value[10];
  935. float _carbon = 0;
  936. memset(cmd, 0x00, sizeof(cmd));
  937. _carbon = data * 0.577;
  938. //log_info("Carbon:%d",(int)_carbon);
  939. if (data > 0 && _carbon < 1)
  940. _carbon = 1;
  941. sprintf((char *) value, "%d", (int)_carbon);
  942. string2ByteArray(value, cmd);
  943. DisplayValueToLcm(_String_Carbon, cmd, sizeof(cmd));
  944. }
  945. void ChangeChargingEnergyValue(float energy)
  946. {
  947. uint8_t cmd[10];
  948. uint8_t value[10];
  949. memset(cmd, 0x00, sizeof(cmd));
  950. if (energy >= 0.05) {
  951. energy -= 0.05;
  952. }
  953. if (energy < 0 )
  954. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0);
  955. else if (energy > 100)
  956. ChangeDisplay2Value(_Icon_ChargeBar,_TCC_Charging_Bar0+100);
  957. else
  958. ChangeDisplay2Value(_Icon_ChargeBar,(int)energy+_TCC_Charging_Bar0);
  959. if (energy < 10)
  960. sprintf((char *) value, "%.1f", energy);
  961. else
  962. sprintf((char *) value, "%d", (int)energy);
  963. string2ByteArray(value, cmd);
  964. DisplayValueToLcm(_Strting_Energy, cmd, sizeof(cmd));
  965. }
  966. uint8_t _battery_display_count = 0;
  967. void ChangeBattMapAndValue(int soc)
  968. {
  969. int i = (soc*36)/100;
  970. uint8_t cmd[5];
  971. uint8_t value[5];
  972. _battery_display_count++;
  973. if (_battery_display_count == 3 ) {
  974. if (_battery_display_ani == 0)
  975. _battery_display_ani= TRUE;
  976. else
  977. _battery_display_ani= FALSE ;
  978. _battery_display_count = 0;
  979. }
  980. if (pSysInfo->SystemPage == _PAGE_CHARGING) {
  981. if (i>=36)
  982. ChangeDisplay2Value(_Icon_ChargeCircle,_TCC_Charging_Circle0+36);
  983. else {
  984. if (_battery_display_ani) {
  985. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i);
  986. } else {
  987. ChangeDisplay2Value(_Icon_ChargeCircle, _TCC_Charging_Circle0+i+1);
  988. }
  989. }
  990. } else if (pSysInfo->SystemPage == _PAGE_COMPLETE)
  991. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  992. else
  993. ChangeDisplay2Value(_Icon_CompleteCircle, _TCC_CompleteCircle0+i);
  994. memset(cmd, 0x00, sizeof(cmd));
  995. memset(value, 0x00, sizeof(value));
  996. sprintf((char *)value, "%d", soc);
  997. string2ByteArray(value, cmd);
  998. DisplayValueToLcm(_String_Battery, cmd, sizeof(cmd));
  999. }
  1000. unsigned long GetPreChargeTimeoutValue(struct timeval _sour_time)
  1001. {
  1002. struct timeval _end_time;
  1003. gettimeofday(&_end_time, NULL);
  1004. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  1005. }
  1006. void ChangeTimeValue(int time)
  1007. {
  1008. uint8_t cmd[6];
  1009. uint8_t value[6];
  1010. memset(cmd, 0x00, sizeof(cmd));
  1011. sprintf((char *) value, "%d", time);
  1012. string2ByteArray(value, cmd);
  1013. DisplayValueToLcm(_String_ChargeTime, cmd, sizeof(cmd));
  1014. }
  1015. void changeWeatherValue(int _weather)
  1016. {
  1017. switch (_weather) {
  1018. case _WEATHER_TYPE_SUN:
  1019. ChangeDisplay2Value(_Icon_Weather,_TCC_Sun);
  1020. break;
  1021. case _WEATHER_TYPE_CLOUDY:
  1022. ChangeDisplay2Value(_Icon_Weather,_TCC_Cloudy);
  1023. break;
  1024. case _WEATHER_TYPE_RAIN:
  1025. ChangeDisplay2Value(_Icon_Weather,_TCC_Rain);
  1026. break;
  1027. case _WEATHER_TYPE_THUNDER:
  1028. ChangeDisplay2Value(_Icon_Weather,_TCC_Thunder);
  1029. break;
  1030. case _WEATHER_TYPE_SNOW:
  1031. ChangeDisplay2Value(_Icon_Weather,_TCC_Snow);
  1032. break;
  1033. case _WEATHER_TYPE_FOG:
  1034. ChangeDisplay2Value(_Icon_Weather,_TCC_Fog);
  1035. break;
  1036. }
  1037. }
  1038. void changeWeekValue(int _week)
  1039. {
  1040. time_t timep;
  1041. struct tm* tm;
  1042. time(&timep);
  1043. timep += (ShmDcCommonData->TZOffset * 60);
  1044. tm = localtime(&timep);
  1045. _week = tm->tm_wday;
  1046. if (_week == 0 )
  1047. _week = 7;
  1048. ChangeDisplay2Value(_Icon_Week,_week);
  1049. }
  1050. void changeDegreeValue(int _degree)
  1051. {
  1052. char value[16];
  1053. memset(value, 0x00, sizeof(value));
  1054. sprintf((char *)value,"%d",_degree);
  1055. DisplayValueToLcm(_String_Tempture, (uint8_t *)value, sizeof(value));
  1056. }
  1057. void changeDateValue(char* _date)
  1058. {
  1059. time_t timep;
  1060. struct tm* tm;
  1061. time(&timep);
  1062. timep += (ShmDcCommonData->TZOffset * 60);
  1063. tm = localtime(&timep);
  1064. sprintf(_date, "%04d/%02d/%02d",
  1065. tm->tm_year + 1900,
  1066. tm->tm_mon + 1,
  1067. tm->tm_mday);
  1068. char value[16];
  1069. memset(value, 0x00, sizeof(value));
  1070. sprintf((char *)value,"%s",_date);
  1071. DisplayValueToLcm(_String_Date, (uint8_t *)value, sizeof(value));
  1072. }
  1073. void changeLocationValue(int _location)
  1074. {
  1075. //_location+=1000;
  1076. //log_info("location:%d",_location);
  1077. ChangeDisplay2Value(_Icon_Location,(short)_location);
  1078. }
  1079. void ShowLineRegisterCountDown()
  1080. {
  1081. int _ten, _digits;
  1082. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1083. if (pDcChargingInfo->TimeoutFlag == Timeout_LineReigster) {
  1084. _ten = (TCC_LINEREGISTER_TIMEOUT - (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL)) / 10;
  1085. _digits = (TCC_LINEREGISTER_TIMEOUT - (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL)) % 10;
  1086. ChangeDisplay2Value(_Icon_ScanCntDownTen, (short)_TCC_CntDownNumber0+_ten);
  1087. ChangeDisplay2Value(_Icon_ScanCntDownDigits, (short)_TCC_CntDownNumber0+ _digits);
  1088. } else {
  1089. log_info("Not get Line Register Count Down");
  1090. }
  1091. }
  1092. void ShowAuthorizeCountDown()
  1093. {
  1094. int _ten, _digits;
  1095. if (pSysInfo->SystemTimeoutFlag == Timeout_ScanCard) {
  1096. _ten = (TCC_SCANCARD_TIMEOUT - (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL)) / 10;
  1097. _digits = (TCC_SCANCARD_TIMEOUT - (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL)) % 10;
  1098. ChangeDisplay2Value(_Icon_AuthCntDownTen, (short)_TCC_CntDownNumber0 + _ten);
  1099. ChangeDisplay2Value(_Icon_AuthCntDownDigits, (short)_TCC_CntDownNumber0 + _digits);
  1100. }
  1101. else {
  1102. log_info("Not get Line Register Count Down");
  1103. }
  1104. }
  1105. int old_money = 0;
  1106. int ClearQR_flag[2];
  1107. void ProcessPageInfo()
  1108. {
  1109. // Show Gun Working and Type
  1110. if (pSysInfo->SystemPage == _PAGE_IDLE) {
  1111. changeWeatherValue(ShmDcCommonData->WeatherID);
  1112. changeWeekValue(0);
  1113. changeDegreeValue((int)ShmDcCommonData->Temperature);
  1114. changeDateValue(&ShmDcCommonData->PresentTime[0]);
  1115. changeLocationValue(ShmDcCommonData->Location);
  1116. return;
  1117. }
  1118. if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
  1119. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(LEFT_GUN_NUM);
  1120. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1121. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1122. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS1_Off);
  1123. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1124. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1125. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CCS2_Off);
  1126. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1127. ChangeDisplay2Value(_Icon_ShowLeft,_TCC_ShowLeft_CHAdeMo_Off);
  1128. }
  1129. // Set Right Gun
  1130. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(RIGHT_GUN_NUM);
  1131. if (pDcChargingInfo->CCSGunType == _TYPE_CCS1_Liquid ||
  1132. pDcChargingInfo->CCSGunType == _TYPE_CCS1_Natural) {
  1133. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS1_Off);
  1134. } else if (pDcChargingInfo->CCSGunType == _TYPE_CCS2_Liquid ||
  1135. pDcChargingInfo->CCSGunType == _TYPE_CCS2_Natural) {
  1136. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CCS2_Off);
  1137. } else if (pDcChargingInfo->Type == _Type_Chademo) {
  1138. ChangeDisplay2Value(_Icon_ShowRight,_TCC_ShowRight_CHAdeMo_Off);
  1139. }
  1140. /*
  1141. if (ShmDcCommonData->ClearServiceQR == FALSE) {
  1142. ShmDcCommonData->ClearServiceQR = TRUE;
  1143. ClearQrCode_Error();
  1144. ChangeQrCode_Error();
  1145. }
  1146. */
  1147. return;
  1148. }
  1149. showGunWorkingType();
  1150. for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1151. if (pSysInfo->CurGunSelected == i) {
  1152. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
  1153. switch (pSysInfo->SystemPage) {
  1154. case _PAGE_IDLE:
  1155. StopSystemTimeoutDet();
  1156. break;
  1157. case _PAGE_SELECT_PAY:
  1158. if (ShmDcCommonData->TransactionInfo[i].IsDonateInvoice == TRUE) {
  1159. ChangeDisplay2Value(_Icon_WordAddFriend,_ICON_Empty);
  1160. } else
  1161. ChangeDisplay2Value(_Icon_WordAddFriend,_TCC_SelectPayMode);
  1162. StartSystemTimeoutDet(Timeout_SelectPayMode);
  1163. break;
  1164. case _PAGE_SELECT_GUN:
  1165. ShowSelectGun();
  1166. ClearQR_flag[i] = FALSE;
  1167. break;
  1168. case _PAGE_BILL:
  1169. if(ClearQR_flag[i] == FALSE) {
  1170. ClearQrCode_Idle();
  1171. ClearQR_flag[i] = TRUE;
  1172. }
  1173. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1174. break;
  1175. case _PAGE_AUTHORIZE:
  1176. StartSystemTimeoutDet(Timeout_ScanCard);
  1177. /*
  1178. int card_result = CreditCardPreAuth(CardReadFd, PREAUTHMONEY,"TCC Test", &ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected]);
  1179. if (card_result > 0 ) {
  1180. strcpy((char *)pSysConfig->UserId, (char *)ShmDcCommonData->pCreditCard[pSysInfo->CurGunSelected].CardNo);
  1181. } else if (card_result < 0) {
  1182. pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
  1183. }*/
  1184. //ChangeDisplay2Value(_Icon_Precharge,0);
  1185. //ChangeDisplay2Value(_Icon_Precharge,1);
  1186. /*
  1187. if (ShmDcCommonData->GetCardNo[pSysInfo->CurGunSelected] == TRUE &&
  1188. ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] != TRUE) {
  1189. //ShmDcCommonData->PreAuth_Config = _CREDITCARD_PREAUTH;
  1190. //ShmDcCommonData->PreAuth_Result = 0;
  1191. //sleep(3);
  1192. pSysInfo->SystemPage = _PAGE_SENSING;
  1193. }
  1194. */
  1195. ChangeChargingRateValue((int)ShmDcCommonData->ChargingRate);
  1196. ShowAuthorizeCountDown();
  1197. _Text_Running_Count = 1;
  1198. break;
  1199. case _PAGE_SENSING:
  1200. if (ShmDcCommonData->TradeCancel == TRUE) {
  1201. TradeRunning(FALSE);
  1202. }
  1203. else
  1204. TradeRunning(TRUE);
  1205. break;
  1206. case _PAGE_PLUGIN:
  1207. _everyPageRollChange = 0;
  1208. break;
  1209. case _PAGE_ADD_FRIEND:
  1210. ShowLineRegisterCountDown();
  1211. break;
  1212. case _PAGE_PRECHARGE:
  1213. //ChangeDisplay2Value(_Icon_Precharge,1);
  1214. RefreshProgressAnimation();
  1215. if (_everyPageRollChange == 0) {
  1216. ChangeDisplay2Value(_Icon_Precharge,_Text_Running_Count);
  1217. _Text_Running_Count >= 24 ? _Text_Running_Count = 24 : _Text_Running_Count++;
  1218. }
  1219. break;
  1220. case _PAGE_CHARGING:
  1221. if (pDcChargingInfo->PresentChargingPower >= 0 &&
  1222. pDcChargingInfo->PresentChargingPower <= POWER_MAX_KW) {
  1223. ChangeChargingPowerValue(pDcChargingInfo->PresentChargingPower);
  1224. } else {
  1225. ChangeChargingPowerValue(0);
  1226. }
  1227. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1228. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1229. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1230. } else {
  1231. ChangeChargingEnergyValue(0);
  1232. }
  1233. if ( pDcChargingInfo->ChargingFee >= 0) {
  1234. ChangeChargingFeeValue(pDcChargingInfo->ChargingFee);
  1235. }
  1236. if (pDcChargingInfo->RemainChargingDuration >= 0 &&
  1237. pDcChargingInfo->RemainChargingDuration <= TIME_MAX_SEC) {
  1238. ChangeTimeValue(pDcChargingInfo->RemainChargingDuration/60);
  1239. } else {
  1240. ChangeTimeValue(0);
  1241. }
  1242. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1243. StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1244. break;
  1245. case _PAGE_COMPLETE:
  1246. case _PAGE_PAYFAIL:
  1247. if (pDcChargingInfo->PresentChargedEnergy >= 0.1 &&
  1248. pDcChargingInfo->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1249. ChangeChargingEnergyValue(pDcChargingInfo->PresentChargedEnergy);
  1250. } else {
  1251. ChangeChargingEnergyValue(0);
  1252. }
  1253. if ( ShmDcCommonData->TransactionInfo[i].Amount > 0 && ShmDcCommonData->finalcost_flag[i] == TRUE) {
  1254. StopGunInfoTimeoutDet(i);
  1255. ChangeChargingFeeValue(ShmDcCommonData->TransactionInfo[i].Amount);
  1256. //ShmDcCommonData->finalcost_flag[i] = FALSE;
  1257. }
  1258. ChangeCarBonValue(pDcChargingInfo->PresentChargedEnergy);
  1259. ChangeBattMapAndValue(pDcChargingInfo->EvBatterySoc);
  1260. //StartSystemTimeoutDet(Timeout_ReturnViewPage);
  1261. break;
  1262. case _PAGE_PLUGOUT:
  1263. /*
  1264. if (pSysConfig->isQRCode) {
  1265. if (pSysConfig->QRCodeMadeMode == NO) {
  1266. //uint8_t len = strlen((char *)pSysConfig->SystemId);
  1267. ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1268. } else {
  1269. //uint8_t len = strlen((char *)pSysConfig->QRCodeContent);
  1270. ChangeQrCode_Idle((char *)pSysConfig->QRCodeContent);
  1271. }
  1272. //ChangeQrCode_Idle((char *)pSysConfig->SystemId);
  1273. }*/
  1274. break;
  1275. case _PAGE_PAYING:
  1276. break;
  1277. /*
  1278. case _PAGE_MAINTAIN:
  1279. ChangeQrCode_Error();
  1280. break;*/
  1281. }
  1282. }
  1283. }
  1284. }
  1285. void ChangeWarningFunc()
  1286. {
  1287. uint8_t cmd[7] = {0};
  1288. uint8_t i = 0;
  1289. //uint8_t j = 0;
  1290. //log_info("ChangeWarningFunc ");
  1291. // 最多一次五筆
  1292. //log_info("LCM PageIndex = %d ", pSysWarning->PageIndex);
  1293. //log_info("WarningCount = %d ", pSysWarning->WarningCount);
  1294. //#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
  1295. for (i = 0; (i + pSysWarning->PageIndex * 5) < pSysWarning->WarningCount; i++) {
  1296. log_info("Warming Code[%d]:%s",i,&pSysWarning->WarningCode[i][0]);
  1297. memset(cmd, 0x00, sizeof(cmd));
  1298. if ((i) >= 5) {
  1299. break;
  1300. }
  1301. //error code
  1302. string2ByteArray(&pSysWarning->WarningCode[i + pSysWarning->PageIndex * 5][0], cmd);
  1303. DisplayValueToLcm(_Strting_Warming0 + ((i) * 0x10), cmd, sizeof(cmd));
  1304. //警告標示
  1305. memset(cmd, 0x00, sizeof(cmd));
  1306. cmd[0] = 0x00;
  1307. cmd[1] = 1;
  1308. DisplayValueToLcm(_Icon_Warming0 + ((i) * 2), cmd, 2);
  1309. }
  1310. memset(cmd, 0x00, sizeof(cmd));
  1311. for (; i < 5; i++) {
  1312. DisplayValueToLcm(_Strting_Warming0 + ((i) * 0x10), cmd, sizeof(cmd));
  1313. DisplayValueToLcm(_Icon_Warming0 + ((i) * 2), cmd, 2);
  1314. }
  1315. }
  1316. void ShowCabientVersionDefaultText()
  1317. {
  1318. char value[16];
  1319. memset(value, 0x00, sizeof(value));
  1320. sprintf((char *)value,"%s","Cabient:");
  1321. DisplayValueToLcm(_Version_Cabient_Name_Text, (uint8_t *)value, sizeof(value));
  1322. sprintf((char *)value,"%s","BootLoader:");
  1323. DisplayValueToLcm(_Version_Cabient_BootLoader_Text, (uint8_t *)value, sizeof(value));
  1324. sprintf((char *)value,"%s","Kernel Fw:");
  1325. DisplayValueToLcm(_Version_Cabient_Kernel_Text, (uint8_t *)value, sizeof(value));
  1326. sprintf((char *)value,"%s","CSU Fw:");
  1327. DisplayValueToLcm(_Version_Cabient_CSU_Text, (uint8_t *)value, sizeof(value));
  1328. sprintf((char *)value,"%s","Priamry Fw:");
  1329. DisplayValueToLcm(_Version_Cabient_Priamry_Text, (uint8_t *)value, sizeof(value));
  1330. sprintf((char *)value,"%s","Relay(0) Fw:");
  1331. DisplayValueToLcm(_Version_Cabient_Relay0_Text, (uint8_t *)value, sizeof(value));
  1332. sprintf((char *)value,"%s","Relay(1) Fw:");
  1333. DisplayValueToLcm(_Version_Cabient_Relay1_Text, (uint8_t *)value, sizeof(value));
  1334. sprintf((char *)value,"%s","Fan Fw:");
  1335. DisplayValueToLcm(_Version_Cabient_Fan_Text, (uint8_t *)value, sizeof(value));
  1336. sprintf((char *)value,"%s","IP Addr:");
  1337. DisplayValueToLcm(_Version_Cabient_IPAddr_Text, (uint8_t *)value, sizeof(value));
  1338. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number <= 12) {
  1339. sprintf((char *)value,"%s","Primary");
  1340. DisplayValueToLcm(_Version_Cabient_Primary_Text, (uint8_t *)value, sizeof(value));
  1341. sprintf((char *)value,"%s","Secondary");
  1342. DisplayValueToLcm(_Version_Cabient_Secondary_Text, (uint8_t *)value, sizeof(value));
  1343. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  1344. sprintf((char *)value,"PSU(%d):",i+1);
  1345. DisplayValueToLcm(_Version_Cabient_PSU1_Text+i*0x10, (uint8_t *)value, sizeof(value));
  1346. }
  1347. }
  1348. }
  1349. void ShowDispenserVersionDefautlText()
  1350. {
  1351. char value[16];
  1352. memset(value, 0x00, sizeof(value));
  1353. sprintf((char *)value,"%s","Dispenser:");
  1354. DisplayValueToLcm(_Version_Dispenser_Name_Text, (uint8_t *)value, sizeof(value));
  1355. sprintf((char *)value,"%s","BootLoader:");
  1356. DisplayValueToLcm(_Version_Dispenser_BootLoader_Text, (uint8_t *)value, sizeof(value));
  1357. sprintf((char *)value,"%s","Kernel Fw:");
  1358. DisplayValueToLcm(_Version_Dispenser_Kernel_Text, (uint8_t *)value, sizeof(value));
  1359. sprintf((char *)value,"%s","CSU Fw:");
  1360. DisplayValueToLcm(_Version_Dispenser_CSU_Text, (uint8_t *)value, sizeof(value));
  1361. sprintf((char *)value,"%s","Relay Fw:");
  1362. DisplayValueToLcm(_Version_Dispenser_Relay_Text, (uint8_t *)value, sizeof(value));
  1363. sprintf((char *)value,"%s","Fan Fw:");
  1364. DisplayValueToLcm(_Version_Dispenser_Fan_Text, (uint8_t *)value, sizeof(value));
  1365. sprintf((char *)value,"%s","Prim Fw:");
  1366. DisplayValueToLcm(_Version_Dispenser_Priamry_Text, (uint8_t *)value, sizeof(value));
  1367. sprintf((char *)value,"%s","LCM Hw:");
  1368. DisplayValueToLcm(_Version_Dispenser_LCM_Text, (uint8_t *)value, sizeof(value));
  1369. sprintf((char *)value,"%s","LED Fw:");
  1370. DisplayValueToLcm(_Version_Dispenser_LED_Text, (uint8_t *)value, sizeof(value));
  1371. sprintf((char *)value,"%s","Connector(0):");
  1372. DisplayValueToLcm(_Version_Dispenser_Connector0_Text, (uint8_t *)value, sizeof(value));
  1373. sprintf((char *)value,"%s","Connector(1):");
  1374. DisplayValueToLcm(_Version_Dispenser_Connector1_Text, (uint8_t *)value, sizeof(value));
  1375. sprintf((char *)value,"%s","IP Addr:");
  1376. DisplayValueToLcm(_Version_Dispenser_IPAddr_Text, (uint8_t *)value, sizeof(value));
  1377. }
  1378. void ShowCabientVersion()
  1379. {
  1380. char value[16];
  1381. memset(value, 0x00, sizeof(value));
  1382. sprintf((char *)value,"%s",ShmDcCommonData->CabinetModelName);
  1383. DisplayValueToLcm(_Version_Cabient_Model_value, (uint8_t *)value, sizeof(value));
  1384. sprintf((char *)value,"%s",ShmDcCommonData->CabinetBoolLoaderVersion);
  1385. DisplayValueToLcm(_Version_Cabient_BootLoader_value, (uint8_t *)value, sizeof(value));
  1386. sprintf((char *)value,"%s",ShmDcCommonData->CabinetKernelVersion);
  1387. DisplayValueToLcm(_Version_Cabient_Kernel_value, (uint8_t *)value, sizeof(value));
  1388. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRFSystemVersion);
  1389. DisplayValueToLcm(_Version_Cabient_CSU_value, (uint8_t *)value, sizeof(value));
  1390. sprintf((char *)value,"%s",ShmDcCommonData->CabinetPrimaryVersion);
  1391. DisplayValueToLcm(_Version_Cabient_Priamry_value, (uint8_t *)value, sizeof(value));
  1392. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay0Version);
  1393. DisplayValueToLcm(_Version_Cabient_Relay0_value, (uint8_t *)value, sizeof(value));
  1394. sprintf((char *)value,"%s",ShmDcCommonData->CabinetRelay1Version);
  1395. DisplayValueToLcm(_Version_Cabient_Relay1_value, (uint8_t *)value, sizeof(value));
  1396. sprintf((char *)value,"%s",ShmDcCommonData->CabinetFanVersion);
  1397. DisplayValueToLcm(_Version_Cabient_Fan_value, (uint8_t *)value, sizeof(value));
  1398. sprintf((char *)value,"%s",ShmDcCommonData->CabinetIPAddr);
  1399. DisplayValueToLcm(_Version_Cabient_IPAddr_value, (uint8_t *)value, sizeof(value));
  1400. if (ShmDcCommonData->PSU_Number > 0 && ShmDcCommonData->PSU_Number < 12) {
  1401. for(uint8_t i = 0 ; i < ShmDcCommonData->PSU_Number ; i++) {
  1402. if (i>=6) {
  1403. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].DCVersion);
  1404. DisplayValueToLcm(_Version_Cabient_PSU_Prim7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  1405. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[(i-6)].FPCVersion);
  1406. DisplayValueToLcm(_Version_Cabient_PSU_Sec7_value+(i-6)*0x10, (uint8_t *)value, sizeof(value));
  1407. continue;
  1408. }
  1409. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].DCVersion);
  1410. DisplayValueToLcm(_Version_Cabient_PSU_Prim1_value+i*0x10, (uint8_t *)value, sizeof(value));
  1411. sprintf((char *)value,"%s",ShmDcCommonData->PsuVer[i].FPCVersion);
  1412. DisplayValueToLcm(_Version_Cabient_PSU_Sec1_value+i*0x10, (uint8_t *)value, sizeof(value));
  1413. }
  1414. }
  1415. }
  1416. void ShowDispenserVersion()
  1417. {
  1418. char value[32];
  1419. memset(value, 0x00, sizeof(value));
  1420. sprintf((char *)value,"%s",pSysConfig->ModelName);
  1421. DisplayValueToLcm(_Version_Dispenser_Model_value, (uint8_t *)value, sizeof(value));
  1422. sprintf((char *)value,"%s",pSysInfo->CsuBootLoadFwRev);
  1423. DisplayValueToLcm(_Version_Dispenser_BootLoader_value, (uint8_t *)value, sizeof(value));
  1424. sprintf((char *)value,"%s",pSysInfo->CsuKernelFwRev);
  1425. DisplayValueToLcm(_Version_Dispenser_Kernel_value, (uint8_t *)value, sizeof(value));
  1426. sprintf((char *)value,"%s",pSysInfo->CsuRootFsFwRev);
  1427. DisplayValueToLcm(_Version_Dispenser_CSU_value, (uint8_t *)value, sizeof(value));
  1428. sprintf((char *)value,"%s",pSysInfo->RelayModuleFwRev);
  1429. DisplayValueToLcm(_Version_Dispenser_Relay_value, (uint8_t *)value, sizeof(value));
  1430. sprintf((char *)value,"%s",pSysInfo->FanModuleFwRev);
  1431. DisplayValueToLcm(_Version_Dispenser_Fan_value, (uint8_t *)value, sizeof(value));
  1432. sprintf((char *)value,"%s",pSysInfo->CsuPrimFwRev);
  1433. DisplayValueToLcm(_Version_Dispenser_Priamry_value, (uint8_t *)value, sizeof(value));
  1434. sprintf((char *)value,"%s",pSysInfo->LcmHwRev);
  1435. DisplayValueToLcm(_Version_Dispenser_LCM_value, (uint8_t *)value, sizeof(value));
  1436. sprintf((char *)value,"%s",pSysInfo->LedModuleFwRev);
  1437. DisplayValueToLcm(_Version_Dispenser_LED_value, (uint8_t *)value, sizeof(value));
  1438. sprintf((char *)value,"%s",pSysInfo->Connector1FwRev);
  1439. DisplayValueToLcm(_Version_Dispenser_Connector0_value, (uint8_t *)value, sizeof(value));
  1440. sprintf((char *)value,"%s",pSysInfo->Connector2FwRev);
  1441. DisplayValueToLcm(_Version_Dispenser_Connector1_value, (uint8_t *)value, sizeof(value));
  1442. sprintf((char *)value,"%s",pSysConfig->Eth0Interface.EthIpAddress);
  1443. DisplayValueToLcm(_Version_Dispenser_IPAddr_value, (uint8_t *)value, sizeof(value));
  1444. }
  1445. /*
  1446. void InformationShow()
  1447. {
  1448. is_show = true;
  1449. if (_showInformIndex == 0 ) {
  1450. pSysInfo->PageIndex = __SHOW_CABIENT_VERSION;
  1451. } else {
  1452. pSysInfo->PageIndex = __SHOW_DISPENSER_VERASION;
  1453. ShowDispenserVersion();
  1454. }
  1455. }
  1456. */
  1457. void DefautLayOut()
  1458. {
  1459. int i;
  1460. for (i = 0 ; i <= 0x5C ; i+=2 ) {
  1461. ChangeDisplay2Value(0x1000+i,1);
  1462. if (i==0x28 || i ==0x2A)
  1463. continue;
  1464. }
  1465. ChangeDisplay2Value(_Icon_MobilePay,0);
  1466. ChangeDisplay2Value(_Icon_CardPay,0);
  1467. ChangeDisplay2Value(0x5000,1);
  1468. ChangeDisplay2Value(_QRCode_Service, 1);
  1469. ShowSelectGun();
  1470. }
  1471. /*
  1472. static int InitialRfidPort(void)
  1473. {
  1474. int fd = open(rfidPortName, O_RDWR);
  1475. struct termios tios;
  1476. struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1477. if (fd != FAIL) {
  1478. ioctl (fd, TCGETS, &tios);
  1479. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  1480. tios.c_lflag = 0;
  1481. tios.c_iflag = 0;
  1482. tios.c_oflag = 0;
  1483. tios.c_cc[VMIN] = 0;
  1484. tios.c_cc[VTIME] = (uint8_t) 1;
  1485. tios.c_lflag = 0;
  1486. tcflush(fd, TCIFLUSH);
  1487. ioctl(fd, TCSETS, &tios);
  1488. }
  1489. if (fd < 0) {
  1490. pAlarmCode->AlarmEvents.bits.RfidModuleCommFail = 1;
  1491. }
  1492. return fd;
  1493. }
  1494. */
  1495. int main(void)
  1496. {
  1497. bool defaulttext = false;
  1498. if (CreateAllCsuShareMemory() == FAIL) {
  1499. log_error("create share memory error");
  1500. return FAIL;
  1501. }
  1502. MappingGunChargingInfo("LCM Control Task");
  1503. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1504. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1505. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1506. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();;
  1507. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1508. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1509. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1510. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  1511. struct StatusCodeData *ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();;
  1512. _port = CreateCommunicationLcmPort();
  1513. uint8_t changeWarningPriority = 0;
  1514. uint8_t curWarningCount = 255;
  1515. ChangeBackLight(true);
  1516. _totalCount = pSysConfig->TotalConnectorCount;
  1517. _everyPageRollChange = 0;
  1518. //Initialization();
  1519. //printf("_LCM_COMPLETE ");
  1520. //ChangeToOtherPage(_LCM_COMPLETE);
  1521. DefautLayOut();
  1522. //return 0;
  1523. //uint8_t index = 1;
  1524. int result = 0;
  1525. ShmDcCommonData->PSU_Number = 12;
  1526. /*
  1527. CardReadFd = InitialRfidPort();
  1528. if (CardReadFd <0) {
  1529. log_info("Card Read Port open fail!");
  1530. }*/
  1531. CheckLCMPressed();
  1532. while (_port != -1) {
  1533. if (strcmp((char *)pSysInfo->LcmHwRev, moduleName) != 0x00) {
  1534. GetCurrentPage();
  1535. sleep(1);
  1536. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1537. ShmDcCommonData->ClearServiceQR = FALSE;
  1538. } else {
  1539. UpdateLcmFunction(ShmDcCommonData,_port);
  1540. ///*
  1541. // Warning 處理
  1542. if (curWarningCount != pSysWarning->WarningCount) {
  1543. changeWarningPriority = 0;
  1544. pSysWarning->PageIndex = 0;
  1545. curWarningCount = pSysWarning->WarningCount;
  1546. ChangeWarningFunc();
  1547. } else if (pSysWarning->WarningCount > 5 && changeWarningPriority == 0) {
  1548. // 當有兩頁 Warning 則每隔三秒改變一次
  1549. if (pSysWarning->PageIndex == 0) {
  1550. pSysWarning->PageIndex = 1;
  1551. } else {
  1552. pSysWarning->PageIndex = 0;
  1553. }
  1554. ChangeWarningFunc();
  1555. }
  1556. ///*
  1557. // Show Default Text
  1558. if (!defaulttext) {
  1559. ShowCabientVersionDefaultText();
  1560. ShowDispenserVersionDefautlText();
  1561. defaulttext = true;
  1562. }
  1563. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = false;
  1564. // 頁面資訊處理
  1565. ProcessPageInfo();
  1566. // 換頁處理
  1567. //GetCurrentPage(); //DS60-120 add
  1568. /*
  1569. if (pSysConfig->ShowInformation == YES && pSysInfo->SystemPage == _PAGE_AUTHORIZE) {
  1570. InformationShow();
  1571. ChangeToOtherPage(pSysInfo->PageIndex);
  1572. usleep(100000);
  1573. continue;
  1574. } else {
  1575. if (is_show)
  1576. _showInformIndex >= 1 ? _showInformIndex = 0 : _showInformIndex++;
  1577. is_show = false;
  1578. }*/
  1579. GetCurrentPage(); //DS60-120 add
  1580. ChangeCurPage();
  1581. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1582. usleep(10000); //*/
  1583. /*
  1584. ProcessPageInfo();
  1585. GetCurrentPage();
  1586. ChangeCurPage();
  1587. usleep(10000);
  1588. //*/
  1589. }
  1590. } //while
  1591. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
  1592. log_info("Close LCM Uart Port");
  1593. CloseCommunicationLcmPort();
  1594. return FAIL;
  1595. }