Module_LcmControl.c 59 KB

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