Module_LcmControl.c 57 KB

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