Module_LcmControl.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. #include "Module_LcmContro.h"
  2. #include "Config.h"
  3. #include "AudiCust.h"
  4. static AudiCustInfo *gAudiCustInfo = NULL;
  5. bool needReloadQr = true;
  6. void PRINTF_FUNC(char *string, ...);
  7. int StoreLogMsg(const char *fmt, ...);
  8. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  9. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  10. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  11. char *getTimeString(void);
  12. //=================================
  13. // Common routine
  14. //=================================
  15. int StoreLogMsg(const char *fmt, ...)
  16. {
  17. char Buf[4096 + 256];
  18. char buffer[4096];
  19. va_list args;
  20. struct timeb SeqEndTime;
  21. struct tm *tm;
  22. va_start(args, fmt);
  23. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  24. va_end(args);
  25. memset(Buf, 0, sizeof(Buf));
  26. ftime(&SeqEndTime);
  27. SeqEndTime.time = time(NULL);
  28. tm = localtime(&SeqEndTime.time);
  29. if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
  30. sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  31. tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
  32. printf("%s \n", Buf);
  33. } else {
  34. sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
  35. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
  36. buffer,
  37. tm->tm_year + 1900, tm->tm_mon + 1);
  38. system(Buf);
  39. }
  40. return rc;
  41. }
  42. char *getTimeString(void)
  43. {
  44. char *result = malloc(21);
  45. time_t timep;
  46. struct tm *p;
  47. time(&timep);
  48. p = gmtime(&timep);
  49. sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
  50. return result;
  51. }
  52. void PRINTF_FUNC(char *string, ...)
  53. {
  54. va_list args;
  55. char buffer[4096];
  56. va_start(args, string);
  57. vsnprintf(buffer, sizeof(buffer), string, args);
  58. va_end(args);
  59. DEBUG_INFO("%s \n", buffer);
  60. }
  61. //==========================================
  62. // Init all share memory
  63. //==========================================
  64. int InitShareMemory()
  65. {
  66. int result = PASS;
  67. int MeterSMId;
  68. //creat ShmSysConfigAndInfo
  69. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) {
  70. #ifdef SystemLogMessage
  71. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  72. #endif
  73. result = FAIL;
  74. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  75. #ifdef SystemLogMessage
  76. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  77. #endif
  78. result = FAIL;
  79. } else
  80. {}
  81. //creat ShmStatusCodeData
  82. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) {
  83. #ifdef SystemLogMessage
  84. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  85. #endif
  86. result = FAIL;
  87. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  88. #ifdef SystemLogMessage
  89. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  90. #endif
  91. result = FAIL;
  92. } else
  93. {}
  94. //creat Audi customization info
  95. if ((MeterSMId = shmget(ShmAudiCustInfoKey, sizeof(AudiCustInfo), IPC_CREAT | 0777)) < 0) {
  96. DEBUG_ERROR("[main]CreatShareMemory:shmget select gun info NG \n");
  97. return 0;
  98. } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  99. DEBUG_ERROR("[main]CreatShareMemory:shmat shmget select gun info \n");
  100. return 0;
  101. }
  102. //creat ShmStatusCodeData
  103. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
  104. #ifdef SystemLogMessage
  105. DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
  106. #endif
  107. result = FAIL;
  108. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  109. #ifdef ShmPrimaryMcuData
  110. DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
  111. #endif
  112. result = FAIL;
  113. }
  114. return result;
  115. }
  116. //==========================================
  117. // Open and Close RS232 and R/W
  118. //==========================================
  119. int CreateCommunicationLcmPort()
  120. {
  121. int fd;
  122. struct termios tios;
  123. fd = open(pPortName, O_RDWR);
  124. if (fd <= 0) {
  125. #ifdef SystemLogMessage
  126. DEBUG_ERROR("open /dev/ttyS3 NG \n");
  127. #endif
  128. return -1;
  129. }
  130. ioctl(fd, TCGETS, &tios);
  131. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  132. tios.c_lflag = 0;
  133. tios.c_iflag = 0;
  134. tios.c_oflag = 0;
  135. tios.c_cc[VMIN] = 0;
  136. tios.c_cc[VTIME] = (unsigned char) 5;
  137. tios.c_lflag = 0;
  138. tcflush(fd, TCIFLUSH);
  139. ioctl(fd, TCSETS, &tios);
  140. return fd;
  141. }
  142. void CloseCommunicationLcmPort()
  143. {
  144. close(_port);
  145. }
  146. void WriteCmdToLcm(byte *cmd, byte cmdLen)
  147. {
  148. int len = write(_port, cmd, cmdLen);
  149. if (len >= sizeof(cmd)) {
  150. //PRINTF_FUNC("Write cmd to LCM successfully. \n");
  151. }
  152. }
  153. void ReadMsgFromLcm(byte *msg, byte readLen)
  154. {
  155. read(_port, msg, readLen);
  156. if (*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2) {
  157. if (*(msg + 3) == CMD_WRITE) {
  158. switch (*(msg + 4)) {
  159. case CMD_REGISTER: {
  160. // 頁面
  161. strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
  162. }
  163. break;
  164. }
  165. } else if (*(msg + 3) == CMD_MULTI_READ) {
  166. // switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
  167. // {
  168. // case BUTTON_GUN_INDEX:
  169. // {
  170. // // 當前選的槍號
  171. // _curGunIndex = (*(msg + 8));
  172. // }
  173. // break;
  174. // }
  175. }
  176. }
  177. }
  178. //================================================
  179. // Function
  180. //================================================
  181. void ChangeToOtherPage(short newPage)
  182. {
  183. byte cmd[7];
  184. memset(cmd, 0x00, sizeof(cmd));
  185. cmd[0] = CMD_TITLE_1;
  186. cmd[1] = CMD_TITLE_2;
  187. cmd[2] = 0x02 + sizeof(newPage);
  188. cmd[3] = CMD_READ;
  189. cmd[4] = CMD_REGISTER;
  190. cmd[5] = newPage >> 8;
  191. cmd[6] = newPage & 0x00FF;
  192. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  193. usleep(100000);
  194. }
  195. void ChangeBackLight(bool islight)
  196. {
  197. byte value = 0x01;
  198. if (islight) {
  199. value = 0x20;
  200. }
  201. byte cmd[7];
  202. memset(cmd, 0x00, sizeof(cmd));
  203. cmd[0] = CMD_TITLE_1;
  204. cmd[1] = CMD_TITLE_2;
  205. cmd[2] = 0x03;
  206. cmd[3] = CMD_READ;
  207. cmd[4] = CMD_BACKLIGHT;
  208. cmd[5] = value;
  209. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  210. usleep(100000);
  211. }
  212. void GetCurrentPage()
  213. {
  214. byte cmd[6];
  215. memset(cmd, 0x00, sizeof(cmd));
  216. byte msg[8];
  217. memset(msg, 0x00, sizeof(msg));
  218. cmd[0] = CMD_TITLE_1;
  219. cmd[1] = CMD_TITLE_2;
  220. cmd[2] = 0x03; // 底下總長度
  221. cmd[3] = CMD_WRITE;
  222. cmd[4] = CMD_REGISTER;
  223. cmd[5] = 0x02;
  224. WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
  225. usleep(100000);
  226. ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
  227. }
  228. void DisplayValueToLcm(short address, byte *data, byte len)
  229. {
  230. byte cmd[256];
  231. memset(cmd, 0x00, sizeof(cmd));
  232. cmd[0] = CMD_TITLE_1;
  233. cmd[1] = CMD_TITLE_2;
  234. cmd[2] = 0x03 + len;
  235. cmd[3] = CMD_MULTI_WRITE;
  236. cmd[4] = address >> 8;
  237. cmd[5] = address & 0x00FF;
  238. for (byte count = 0; count < len; count++) {
  239. cmd[6 + count] = *(data + count);
  240. }
  241. WriteCmdToLcm(cmd, cmd[2] + 3);
  242. }
  243. void ChangeDisplay2Value(short address, short value)
  244. {
  245. byte data[2];
  246. data[0] = value >> 8;
  247. data[1] = value & 0x00FF;
  248. DisplayValueToLcm(address, data, sizeof(data));
  249. }
  250. void GetBtnStatus(short address, byte len)
  251. {
  252. byte cmd[8];
  253. memset(cmd, 0x00, sizeof(cmd));
  254. byte msg[8];
  255. memset(msg, 0x00, sizeof(msg));
  256. cmd[0] = CMD_TITLE_1;
  257. cmd[1] = CMD_TITLE_2;
  258. cmd[2] = 0x03 + len;
  259. cmd[3] = CMD_MULTI_READ;
  260. cmd[4] = address >> 8;
  261. cmd[5] = address & 0x00FF;
  262. cmd[6] = 0x00 + len;
  263. WriteCmdToLcm(cmd, cmd[2] + 3);
  264. usleep(100000);
  265. ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
  266. }
  267. //================================================
  268. // Warning process
  269. //================================================
  270. void string2ByteArray(unsigned char *input, byte *output)
  271. {
  272. int loop;
  273. int i;
  274. loop = 0;
  275. i = 0;
  276. while (input[loop] != '\0') {
  277. output[i++] = input[loop++];
  278. }
  279. output[loop] = '\0';
  280. }
  281. void ChangeWarningFunc()
  282. {
  283. byte cmd[7];
  284. byte i = 0, j = 0;
  285. //PRINTF_FUNC("ChangeWarningFunc \n");
  286. // 最多一次五筆
  287. //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
  288. //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  289. #if 0
  290. for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
  291. memset(cmd, 0x00, sizeof(cmd));
  292. if ((i) >= 5) {
  293. break;
  294. }
  295. //error code
  296. string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
  297. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  298. //警告標示
  299. memset(cmd, 0x00, sizeof(cmd));
  300. cmd[0] = 0x00;
  301. cmd[1] = 0x01;
  302. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  303. }
  304. memset(cmd, 0x00, sizeof(cmd));
  305. for (; i < 5; i++) {
  306. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  307. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  308. }
  309. #else
  310. for (i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
  311. memset(cmd, 0x00, sizeof(cmd));
  312. if ((i - j) >= 5) {
  313. break;
  314. }
  315. if (
  316. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033900", 6) == 0) ||
  317. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033901", 6) == 0) ||
  318. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033902", 6) == 0) ||
  319. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043627", 6) == 0) ||
  320. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043628", 6) == 0) ||
  321. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043622", 6) == 0) ||
  322. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043623", 6) == 0) ||
  323. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043624", 6) == 0) ||
  324. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043625", 6) == 0) ||
  325. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043626", 6) == 0) ||
  326. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042241", 6) == 0) ||
  327. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042242", 6) == 0)
  328. ) {
  329. j++;
  330. continue;
  331. }
  332. //error code
  333. string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
  334. DisplayValueToLcm(0x0010 + ((i - j) * 6), cmd, sizeof(cmd));
  335. //警告標示
  336. memset(cmd, 0x00, sizeof(cmd));
  337. cmd[0] = 0x00;
  338. cmd[1] = 0x01;
  339. DisplayValueToLcm(0x0002 + ((i - j) * 2), cmd, 2);
  340. }
  341. memset(cmd, 0x00, sizeof(cmd));
  342. i = i - j;
  343. for (; (i) < 5; i++) {
  344. DisplayValueToLcm(0x0010 + ((i) * 6), cmd, sizeof(cmd));
  345. DisplayValueToLcm(0x0002 + ((i) * 2), cmd, 2);
  346. }
  347. #endif
  348. }
  349. //================================================
  350. // QR Code process
  351. //================================================
  352. void ChangeQrCode_Idle(char *input)
  353. {
  354. int len = strlen(input) + 3;
  355. int loop = 0;
  356. int i = 0, j = 0, k = 0, l = 0;
  357. uint8_t qrUrl[128] = {0};
  358. uint16_t urlLen = 0;
  359. uint8_t cmd[len];
  360. uint8_t tmpBuf[15] = {0};
  361. //uint8_t tmpLen = sizeof(tmpBuf) - 1;
  362. strncpy((char *)cmd, " ", len);
  363. while (input[loop] != '\0') {
  364. cmd[i++] = input[loop++];
  365. l = loop - 1;
  366. if (len >= 25) {
  367. if (i >= 16 && i <= 19) {
  368. tmpBuf[k++] = input[l];
  369. //printf("tmpBuf = %s\r\n", tmpBuf);
  370. } else if (i >= 21 && i <= 23) {
  371. tmpBuf[k++] = input[l];
  372. }
  373. }
  374. }
  375. tmpBuf[k] = '\0';
  376. //printf("tmpBuf = %s\r\n", tmpBuf);
  377. j += sprintf((char *)&cmd[i], ":%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
  378. cmd[len - 1] = '\0';
  379. urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
  380. qrUrl[urlLen] = '\0';
  381. //printf("qr url = %s\r\n", qrUrl);
  382. DisplayValueToLcm(__qr_code, qrUrl, urlLen);
  383. j = 0;
  384. j += sprintf((char *)&tmpBuf[k], "0%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
  385. tmpBuf[k + j] = '\0';
  386. //if (len < 25) {
  387. // strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  388. //}
  389. //tmpBuf[tmpLen] = '\0';
  390. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  391. /*if (len > sizeof(tmpBuf)) {
  392. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  393. tmpBuf[tmpLen] = '\0';
  394. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  395. memset(tmpBuf, 0, sizeof(tmpBuf));
  396. strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
  397. tmpBuf[tmpLen] = '\0';
  398. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  399. } else {
  400. DisplayValueToLcm(__custStationIdL1, cmd, len);
  401. strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
  402. tmpBuf[tmpLen] = '\0';
  403. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  404. }*/
  405. #if 0
  406. int len = strlen(input);
  407. byte cmd[len];
  408. int loop = 0;
  409. int i = 0;
  410. while (input[loop] != '\0') {
  411. cmd[i++] = input[loop++];
  412. }
  413. DisplayValueToLcm(__qr_code, cmd, len);
  414. #endif //0
  415. }
  416. void ChangeQrCode_Charge(char *input)
  417. {
  418. int len = strlen(input) + 3;
  419. int loop = 0;
  420. int i = 0, j = 0, k = 0, l = 0;
  421. uint8_t qrUrl[128] = {0};
  422. uint16_t urlLen = 0;
  423. uint8_t cmd[len];
  424. uint8_t tmpBuf[15] = {0};
  425. //uint8_t tmpLen = sizeof(tmpBuf) - 1;
  426. strncpy((char *)cmd, " ", len);
  427. while (input[loop] != '\0') {
  428. cmd[i++] = input[loop++];
  429. l = loop - 1;
  430. if (len >= 25) {
  431. if (i >= 16 && i <= 19) {
  432. tmpBuf[k++] = input[l];
  433. //printf("tmpBuf = %s\r\n", tmpBuf);
  434. } else if (i >= 21 && i <= 23) {
  435. tmpBuf[k++] = input[l];
  436. }
  437. }
  438. }
  439. tmpBuf[k] = '\0';
  440. //printf("tmpBuf = %s\r\n", tmpBuf);
  441. j += sprintf((char *)&cmd[i], ":%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
  442. cmd[len - 1] = '\0';
  443. urlLen = sprintf((char *)qrUrl, "%s%s", NOODOE_QR_CODE_URL, cmd);
  444. qrUrl[urlLen] = '\0';
  445. DisplayValueToLcm(__qr_code, qrUrl, urlLen);
  446. j = 0;
  447. j += sprintf((char *)&tmpBuf[k], "0%d", ShmSysConfigAndInfo->SysInfo.CurGunSelected); ////For Audi
  448. tmpBuf[k + j] = '\0';
  449. if (len < 25) {
  450. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  451. }
  452. //tmpBuf[tmpLen] = '\0';
  453. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  454. /*if (len > sizeof(tmpBuf)) {
  455. strncpy((char *)tmpBuf, (char *)cmd, sizeof(tmpBuf));
  456. tmpBuf[tmpLen] = '\0';
  457. DisplayValueToLcm(__custStationIdL1, tmpBuf, sizeof(tmpBuf));
  458. memset(tmpBuf, 0, sizeof(tmpBuf));
  459. strncpy((char *)tmpBuf, (char *)&cmd[tmpLen], sizeof(tmpBuf));
  460. tmpBuf[tmpLen] = '\0';
  461. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  462. } else {
  463. DisplayValueToLcm(__custStationIdL1, cmd, len);
  464. strncpy((char *)tmpBuf, " ", sizeof(tmpBuf));
  465. tmpBuf[tmpLen] = '\0';
  466. DisplayValueToLcm(__custStationIdL2, tmpBuf, sizeof(tmpBuf));
  467. }*/
  468. #if 0
  469. int len = strlen(input);
  470. byte cmd[len];
  471. int loop = 0;
  472. int i = 0;
  473. while (input[loop] != '\0') {
  474. cmd[i++] = input[loop++];
  475. }
  476. DisplayValueToLcm(__qr_code_pre, cmd, len);
  477. #endif //0
  478. }
  479. //================================================
  480. // Change current page
  481. //================================================
  482. void ChangeCurPage()
  483. {
  484. //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
  485. if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex) {
  486. _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
  487. ChangeToOtherPage(_currentPage);
  488. _everyPageRollChange = 0;
  489. }
  490. }
  491. //================================================
  492. // Main process
  493. //================================================
  494. byte demoCount = 0;
  495. void DemoFunction()
  496. {
  497. if (demoCount == 0) {
  498. ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
  499. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
  500. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
  501. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
  502. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
  503. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
  504. memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
  505. } else {
  506. if (demoCount == 20) {
  507. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_SELECT_GUN; //_LCM_IDLE; ////For Audi
  508. } else if (demoCount == 80) {
  509. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
  510. } else if (demoCount == 100) {
  511. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
  512. } else if (demoCount == 120) {
  513. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
  514. } else if (demoCount == 140) {
  515. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
  516. } else if (demoCount == 180) {
  517. ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
  518. }
  519. }
  520. if (demoCount < 180) {
  521. demoCount++;
  522. }
  523. }
  524. //================================================
  525. // Main process
  526. //================================================
  527. bool FindChargingInfoData(byte target, struct ChargingInfoData **_chargingData)
  528. {
  529. for (byte index = 0; index < CHAdeMO_QUANTITY; index++) {
  530. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
  531. _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  532. return true;
  533. }
  534. }
  535. for (byte index = 0; index < CCS_QUANTITY; index++) {
  536. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
  537. _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  538. return true;
  539. }
  540. }
  541. for (byte index = 0; index < GB_QUANTITY; index++) {
  542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
  543. _chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  544. return true;
  545. }
  546. }
  547. return false;
  548. }
  549. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  550. {
  551. if (target < AC_QUANTITY) {
  552. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  553. return true;
  554. }
  555. return false;
  556. }
  557. /**
  558. * [ChangeBalanceValue :print balance information]
  559. * @Author
  560. * @DateTime 2020-11-26
  561. */
  562. static void ChangeBalanceValue(uint16_t addr, uint8_t index) ////For Audi
  563. {
  564. byte cmd[10] = {0};
  565. byte value[10] = {0};
  566. uint8_t len = 0;
  567. float balance = gAudiCustInfo->PricesInfo[index].Balance;
  568. if ((balance) == (FAIL_BALANCE_PRICES)) {
  569. balance = 0.00;
  570. }
  571. len += sprintf((char *) value, "%.2f", balance);
  572. if (len < 6) {
  573. sprintf((char *)&value[len], "%s",
  574. (byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
  575. }
  576. value[sizeof(value) - 1] = '\0';
  577. string2ByteArray(value, cmd);
  578. DisplayValueToLcm(addr, cmd, sizeof(cmd));
  579. }
  580. void ChangeAcBattMapAndValue(short page)
  581. {
  582. if (page == _LCM_CHARGING) {
  583. if (isDiffStatus != _battery_display_ani) {
  584. isChangeBattMap = false;
  585. isDiffStatus = _battery_display_ani;
  586. }
  587. if (ac_chargingInfo[0]->IsCharging && !isChangeBattMap) {
  588. isChangeBattMap = true;
  589. if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
  590. ChangeDisplay2Value(__batt_map, _battery_empty);
  591. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_EMP;
  592. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
  593. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  594. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV1;
  595. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
  596. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  597. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV2;
  598. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
  599. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  600. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV3;
  601. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
  602. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  603. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV4;
  604. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
  605. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  606. ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
  607. }
  608. }
  609. } else if (page == _LCM_COMPLETE) {
  610. if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5) {
  611. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  612. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP) {
  613. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  614. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1) {
  615. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  616. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2) {
  617. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  618. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3) {
  619. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  620. } else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4) {
  621. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  622. }
  623. }
  624. ChangeDisplay2Value(__soc_value_charging, _disappear);
  625. }
  626. void ChangeBattMapAndValue(short page, int soc)
  627. {
  628. // srand(time(NULL));
  629. // int min = 10;
  630. // int max = 90;
  631. // soc = rand() % (max - min + 1) + min;
  632. if (page == _LCM_PRE_CHARGE) {
  633. ChangeDisplay2Value(__batt_map_empty, _battery_empty);
  634. } else if (page == _LCM_CHARGING) {
  635. if (soc < 20) {
  636. if (_battery_display_ani) {
  637. ChangeDisplay2Value(__batt_map, _battery_empty);
  638. } else {
  639. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  640. }
  641. } else if (soc >= 20 && soc < 40) {
  642. if (_battery_display_ani) {
  643. ChangeDisplay2Value(__batt_map, _battery_cap_20);
  644. } else {
  645. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  646. }
  647. } else if (soc >= 40 && soc < 60) {
  648. if (_battery_display_ani) {
  649. ChangeDisplay2Value(__batt_map, _battery_cap_40);
  650. } else {
  651. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  652. }
  653. } else if (soc >= 60 && soc < 80) {
  654. if (_battery_display_ani) {
  655. ChangeDisplay2Value(__batt_map, _battery_cap_60);
  656. } else {
  657. ChangeDisplay2Value(__batt_map, _battery_cap_80);
  658. }
  659. } else if (soc >= 80 && soc <= 100) {
  660. ChangeDisplay2Value(__batt_map, _battery_cap_100);
  661. }
  662. } else if (page == _LCM_COMPLETE) {
  663. if (soc < 20) {
  664. ChangeDisplay2Value(__batt_map, _battery_soc_20);
  665. } else if (soc >= 20 && soc < 40) {
  666. ChangeDisplay2Value(__batt_map, _battery_soc_40);
  667. } else if (soc >= 40 && soc < 60) {
  668. ChangeDisplay2Value(__batt_map, _battery_soc_60);
  669. } else if (soc >= 60 && soc < 80) {
  670. ChangeDisplay2Value(__batt_map, _battery_soc_80);
  671. } else if (soc >= 80 && soc <= 100) {
  672. ChangeDisplay2Value(__batt_map, _battery_soc_100);
  673. }
  674. }
  675. byte cmd[5];
  676. byte value[5];
  677. memset(cmd, 0x00, sizeof(cmd));
  678. memset(value, 0x00, sizeof(value));
  679. sprintf((char *)value, "%d%%", soc);
  680. string2ByteArray(value, cmd);
  681. DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
  682. }
  683. void ChangeRemainTime(int sec)
  684. {
  685. int h, m, s;
  686. byte cmd[10];
  687. byte value[10];
  688. memset(cmd, 0x00, sizeof(cmd));
  689. // srand(time(NULL));
  690. // int min = 0;
  691. // int max = 65536;
  692. // sec = rand() % (max - min + 1) + min;
  693. h = (sec / 3600);
  694. m = (sec - (3600 * h)) / 60;
  695. s = (sec - (3600 * h) - (m * 60));
  696. sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
  697. string2ByteArray(value, cmd);
  698. DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
  699. }
  700. void ChangeChargingEnergyValue(float energy)
  701. {
  702. byte cmd[10];
  703. byte value[10];
  704. memset(cmd, 0x00, sizeof(cmd));
  705. if (energy >= 0.05) {
  706. energy -= 0.05;
  707. }
  708. sprintf((char *) value, "%.1f kWh", energy);
  709. string2ByteArray(value, cmd);
  710. DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
  711. }
  712. void ChangeChargingPowerValue(float pow)
  713. {
  714. byte cmd[10];
  715. byte value[10];
  716. memset(cmd, 0x00, sizeof(cmd));
  717. // float min = 0.0;
  718. // float max = 50;
  719. // pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
  720. sprintf((char *) value, "%.1f kW", pow);
  721. string2ByteArray(value, cmd);
  722. DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
  723. }
  724. void ChangeChargingFeeValue(float fee)
  725. {
  726. byte cmd[10];
  727. byte value[10];
  728. memset(cmd, 0x00, sizeof(cmd));
  729. sprintf((char *) value, "%.2f", fee);
  730. string2ByteArray(value, cmd);
  731. DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
  732. }
  733. void DisplayMoneyRate(float money)
  734. {
  735. byte cmd[8];
  736. byte value[8];
  737. memset(cmd, 0x00, sizeof(cmd));
  738. sprintf((char *) value, "%.2f", money);
  739. string2ByteArray(value, cmd);
  740. DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
  741. }
  742. void DisplayMoneyCur(byte *cur)
  743. {
  744. byte cmd[10] = {0};
  745. byte buf[10] = {0};
  746. uint8_t len = 0;
  747. *(cur + 3) = '\0';
  748. memset(cmd, 0x00, sizeof(cmd));
  749. len = sprintf((char *) buf, "%s/kWh", cur);
  750. buf[len] = '\0';
  751. string2ByteArray(buf, cmd);
  752. DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
  753. }
  754. void RefreshPageAnimation(byte value)
  755. {
  756. switch (_currentPage) {
  757. case _LCM_IDLE: {
  758. }
  759. break;
  760. case _LCM_WAIT_FOR_PLUG: {
  761. if (_everyPageRollChange == 0) {
  762. ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
  763. } else if (_everyPageRollChange == 15) {
  764. ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
  765. }
  766. _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  767. }
  768. break;
  769. case _LCM_PRE_CHARGE:
  770. case _LCM_CHARGING:
  771. case _LCM_COMPLETE: {
  772. if (_currentPage == _LCM_PRE_CHARGE) {
  773. if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
  774. ChangeDisplay2Value(__conn_line, _conn_map1);
  775. } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
  776. ChangeDisplay2Value(__conn_line, _conn_map2);
  777. }
  778. } else if (_currentPage == _LCM_CHARGING) {
  779. if (_everyPageRollChange == 0 || _everyPageRollChange == 22) {
  780. ChangeDisplay2Value(__conn_line_chag, _charging_map1);
  781. } else if (_everyPageRollChange == 11 || _everyPageRollChange == 33) {
  782. ChangeDisplay2Value(__conn_line_chag, _charging_map2);
  783. }
  784. } else if (_currentPage == _LCM_COMPLETE) {
  785. if (_everyPageRollChange == 0) {
  786. ChangeDisplay2Value(__conn_line_comp, _complete_map);
  787. }
  788. }
  789. _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
  790. }
  791. break;
  792. }
  793. }
  794. void RefreshConnStatus()
  795. {
  796. // Wifi priority is higher than Ethernet
  797. #if defined DD360 || defined DD360Audi
  798. uint8_t i = 0;
  799. unsigned char flag[4] = {0};
  800. for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
  801. //printf("status code = %s\r\n", &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  802. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "012304", 6) == 0) {
  803. flag[0] = 1;
  804. continue;
  805. }
  806. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043625", 6) == 0) {
  807. //disconnected from AP through WiFi
  808. flag[1] = 1;
  809. continue;
  810. }
  811. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043627", 6) == 0) { //wifi disabled
  812. flag[1] = 2;
  813. continue;
  814. }
  815. if ((memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033900", 6) == 0) ||
  816. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033901", 6) == 0) ||
  817. (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "033902", 6) == 0)) {
  818. flag[2] = 1;
  819. continue;
  820. }
  821. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043626", 6) == 0) {
  822. //disconnected from APN through 3G/4G
  823. flag[3] = 1;
  824. continue;
  825. }
  826. if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "043628", 6) == 0) { //4g disabled
  827. flag[3] = 2;
  828. continue;
  829. }
  830. }
  831. if (flag[0] == 1) {
  832. ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
  833. } else {
  834. ChangeDisplay2Value(__ethernet_status, _eth_connect);
  835. }
  836. //ChangeDisplay2Value(__wifi_status, _disappear);
  837. //ChangeDisplay2Value(__conn_status, _disappear);
  838. //ChangeDisplay2Value(__3G4G_status, _disappear);
  839. if (flag[1] == 1) {
  840. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  841. ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
  842. } else if (flag[1] == 2) {
  843. ChangeDisplay2Value(__wifi_status, _disappear);
  844. } else {
  845. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  846. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  847. }
  848. if (flag[2] == 1) {
  849. ChangeDisplay2Value(__conn_status, _disconnect);
  850. } else {
  851. ChangeDisplay2Value(__conn_status, _connect);
  852. }
  853. if (flag[1] == 2) {
  854. ChangeDisplay2Value(__3G4G_status, _disappear);
  855. if (flag[3] == 1) {
  856. ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect);
  857. } else if (flag[3] == 2) {
  858. ChangeDisplay2Value(__3G4G_move_status, _disappear);
  859. } else {
  860. ChangeDisplay2Value(__3G4G_move_status, __3G4G_connect);
  861. }
  862. } else {
  863. if (flag[3] == 1) {
  864. ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
  865. } else if (flag[3] == 2) {
  866. ChangeDisplay2Value(__3G4G_status, _disappear);
  867. } else {
  868. ChangeDisplay2Value(__3G4G_status, __3G4G_connect);
  869. }
  870. }
  871. #else
  872. if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ||
  873. ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP) {
  874. _wifi_conn_status = true;
  875. ChangeDisplay2Value(__wifi_status, _wifi_connect);
  876. ChangeDisplay2Value(__ethernet_status, _disappear);
  877. } else {
  878. _wifi_conn_status = false;
  879. ChangeDisplay2Value(__wifi_status, _disappear);
  880. }
  881. if (!_wifi_conn_status) {
  882. if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ||
  883. ShmSysConfigAndInfo->SysInfo.InternetConn == YES) {
  884. ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
  885. } else {
  886. ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
  887. }
  888. }
  889. // 連線到後台
  890. if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES) {
  891. ChangeDisplay2Value(__conn_status, _connect);
  892. } else {
  893. ChangeDisplay2Value(__conn_status, _disconnect);
  894. }
  895. #endif //defined DD360 || defined DD360Audi
  896. }
  897. byte FirstPageChanged()
  898. {
  899. byte result = NO;
  900. if (_currentPage != _oldPage) {
  901. result = YES;
  902. _oldPage = _currentPage;
  903. }
  904. return result;
  905. }
  906. bool IsPageReloadChk()
  907. {
  908. bool result = false;
  909. if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
  910. if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
  911. _curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
  912. result = true;
  913. }
  914. } else {
  915. if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc) {
  916. _curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
  917. result = true;
  918. }
  919. }
  920. return result;
  921. }
  922. void ProcessPageInfo()
  923. {
  924. _page_reload = IsPageReloadChk();
  925. switch (_currentPage) {
  926. case _LCM_SELECT_GUN: ////For Audi
  927. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 0) {
  928. ChangeDisplay2Value(__left_gun_map, _left_gun_enable_map);
  929. ChangeDisplay2Value(__right_gun_map, _right_gun_disable_map);
  930. } else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 1) {
  931. ChangeDisplay2Value(__left_gun_map, _left_gun_disable_map);
  932. ChangeDisplay2Value(__right_gun_map, _right_gun_enable_map);
  933. }
  934. ChangeDisplay2Value(__add_chk_btn, _select_gun_btn);
  935. break;
  936. case _LCM_IDLE: {
  937. if (ShmSysConfigAndInfo->SysConfig.isRFID) {
  938. ChangeDisplay2Value(__main_rfid, _main_rfid);
  939. } else {
  940. ChangeDisplay2Value(__main_rfid, _main_none_rfid);
  941. }
  942. if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
  943. ChangeDisplay2Value(__main_qr, _main_qr);
  944. } else {
  945. ChangeDisplay2Value(__qr_code, _disappear);
  946. ChangeDisplay2Value(__main_qr, _main_none_qr);
  947. needReloadQr = true;
  948. }
  949. if (ShmSysConfigAndInfo->SysConfig.isAPP) {
  950. ChangeDisplay2Value(__main_app, _main_app);
  951. } else {
  952. ChangeDisplay2Value(__main_app, _main_none_app);
  953. }
  954. //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
  955. if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
  956. needReloadQr = false;
  957. ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  958. }
  959. //}
  960. }
  961. break;
  962. case _LCM_AUTHORIZING:
  963. case _LCM_AUTHORIZ_COMP:
  964. case _LCM_AUTHORIZ_FAIL:
  965. case _LCM_WAIT_FOR_PLUG: {
  966. FirstPageChanged();
  967. if (_currentPage == _LCM_AUTHORIZ_COMP) { ////For Audi
  968. ChangeBalanceValue(__balance, ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  969. }
  970. }
  971. break;
  972. case _LCM_PRE_CHARGE:
  973. case _LCM_CHARGING:
  974. case _LCM_COMPLETE: {
  975. #if 0
  976. if (_totalCount + acgunCount >= 2) {
  977. if (ShmSysConfigAndInfo->SysConfig.isRFID) {
  978. ChangeDisplay2Value(__side_top, _side_rfid);
  979. } else {
  980. ChangeDisplay2Value(__side_top, _side_none_rfid);
  981. }
  982. if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
  983. ChangeDisplay2Value(__side_mid, _side_qr);
  984. } else {
  985. ChangeDisplay2Value(__qr_code_pre, _disappear);
  986. ChangeDisplay2Value(__side_mid, _side_none_qr);
  987. needReloadQr = true;
  988. }
  989. if (ShmSysConfigAndInfo->SysConfig.isAPP) {
  990. ChangeDisplay2Value(__side_down, _side_app);
  991. } else {
  992. ChangeDisplay2Value(__side_down, _side_none_app);
  993. }
  994. } else {
  995. ChangeDisplay2Value(__side_top, _disappear);
  996. ChangeDisplay2Value(__side_mid, _disappear);
  997. ChangeDisplay2Value(__side_down, _disappear);
  998. }
  999. #endif //0
  1000. bool isShowAc = false;
  1001. if (acgunCount > 0) {
  1002. if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
  1003. isShowAc = true;
  1004. ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light);
  1005. if (_currentPage == _LCM_CHARGING) {
  1006. ChangeAcBattMapAndValue(_LCM_CHARGING);
  1007. if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
  1008. ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC) {
  1009. ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
  1010. } else {
  1011. ChangeRemainTime(0);
  1012. }
  1013. if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
  1014. ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW) {
  1015. ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
  1016. } else {
  1017. ChangeChargingPowerValue(0);
  1018. }
  1019. if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
  1020. ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1021. ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
  1022. } else {
  1023. ChangeChargingEnergyValue(0);
  1024. }
  1025. if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0) {
  1026. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  1027. } else {
  1028. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  1029. }
  1030. } else if (_currentPage == _LCM_COMPLETE) {
  1031. ChangeAcBattMapAndValue(_LCM_COMPLETE);
  1032. if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
  1033. ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC) {
  1034. ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
  1035. } else {
  1036. ChangeRemainTime(0);
  1037. }
  1038. if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
  1039. ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW) {
  1040. ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
  1041. } else {
  1042. ChangeChargingPowerValue(0);
  1043. }
  1044. if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
  1045. ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1046. ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
  1047. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
  1048. ac_chargingInfo[0]->ChargingFee >= 0) {
  1049. ChangeChargingFeeValue(ac_chargingInfo[0]->ChargingFee);
  1050. }
  1051. } else {
  1052. ChangeChargingEnergyValue(0);
  1053. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
  1054. ChangeChargingFeeValue(0);
  1055. }
  1056. }
  1057. if (!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
  1058. ChangeDisplay2Value(__charging_fee_map, _disappear);
  1059. ChangeDisplay2Value(__charging_fee_tx, _disappear);
  1060. } else {
  1061. ChangeDisplay2Value(__charging_fee_map, _money_map);
  1062. }
  1063. }
  1064. } else {
  1065. ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark);
  1066. }
  1067. } else {
  1068. ChangeDisplay2Value(__gun_type_index + (2 * 2), _disappear);
  1069. }
  1070. for (byte i = 0; i < _totalCount; i++) {
  1071. switch (_chargingInfoData[i]->Type) {
  1072. case _Type_Chademo: {
  1073. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
  1074. if (_currentPage == _LCM_COMPLETE) {
  1075. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_light_cmp);
  1076. } else {
  1077. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
  1078. }
  1079. } else {
  1080. if (_currentPage == _LCM_COMPLETE) {
  1081. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _chademo_dark_cmp);
  1082. } else {
  1083. ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
  1084. }
  1085. }
  1086. }
  1087. break;
  1088. case _Type_GB: {
  1089. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
  1090. if (_currentPage == _LCM_COMPLETE) {
  1091. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_light_cmp);
  1092. } else {
  1093. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
  1094. }
  1095. } else {
  1096. if (_currentPage == _LCM_COMPLETE) {
  1097. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _gbt_dark_cmp);
  1098. } else {
  1099. ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
  1100. }
  1101. }
  1102. }
  1103. break;
  1104. case _Type_CCS_2: {
  1105. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc) {
  1106. if (_currentPage == _LCM_COMPLETE) {
  1107. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_light_cmp);
  1108. } else {
  1109. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
  1110. }
  1111. } else {
  1112. if (_currentPage == _LCM_COMPLETE) {
  1113. ChangeDisplay2Value(__cmp_gun_type_index + (i * 2), _ccs_dark_cmp);
  1114. } else {
  1115. ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
  1116. }
  1117. }
  1118. }
  1119. break;
  1120. }
  1121. if (_currentPage == _LCM_PRE_CHARGE && !isShowAc) {
  1122. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
  1123. ChangeBattMapAndValue(_currentPage, _chargingInfoData[i]->EvBatterySoc);
  1124. }
  1125. } else if (_currentPage == _LCM_CHARGING && !isShowAc) {
  1126. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
  1127. ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
  1128. if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
  1129. _chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC) {
  1130. ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
  1131. } else {
  1132. ChangeRemainTime(0);
  1133. }
  1134. if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
  1135. _chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW) {
  1136. ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
  1137. } else {
  1138. ChangeChargingPowerValue(0);
  1139. }
  1140. if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
  1141. _chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1142. ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
  1143. } else {
  1144. ChangeChargingEnergyValue(0);
  1145. }
  1146. if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0) {
  1147. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
  1148. } else {
  1149. ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
  1150. }
  1151. }
  1152. } else if (_currentPage == _LCM_COMPLETE && !isShowAc) {
  1153. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i) {
  1154. ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
  1155. if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
  1156. _chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC) {
  1157. ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
  1158. } else {
  1159. ChangeRemainTime(0);
  1160. }
  1161. if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
  1162. _chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW) {
  1163. ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
  1164. } else {
  1165. ChangeChargingPowerValue(0);
  1166. }
  1167. #if 1
  1168. if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
  1169. _chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) {
  1170. ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
  1171. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
  1172. _chargingInfoData[i]->ChargingFee >= 0) {
  1173. ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
  1174. ChangeBalanceValue(__remain_balance, i);
  1175. }
  1176. } else {
  1177. ChangeChargingEnergyValue(0);
  1178. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
  1179. ChangeChargingFeeValue(0);
  1180. ChangeBalanceValue(__remain_balance, i);
  1181. }
  1182. }
  1183. #else
  1184. ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
  1185. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
  1186. _chargingInfoData[i]->ChargingFee >= 0) {
  1187. ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
  1188. ChangeBalanceValue(__remain_balance, i);
  1189. }
  1190. #endif // 0
  1191. if (!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
  1192. ChangeDisplay2Value(__charging_fee_map, _disappear);
  1193. ChangeDisplay2Value(__charging_fee_tx, _disappear);
  1194. } else {
  1195. ChangeDisplay2Value(__charging_fee_map, _money_map);
  1196. }
  1197. }
  1198. }
  1199. }
  1200. // gun btn and QR code
  1201. if (_totalCount + acgunCount >= 2 && _currentPage) {
  1202. byte index = 0;
  1203. for (index = 0; index < _totalCount; index++) {
  1204. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index) {
  1205. break;
  1206. }
  1207. }
  1208. if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
  1209. _chargingInfoData[index]->SystemStatus == S_RESERVATION ||
  1210. _chargingInfoData[index]->SystemStatus == S_BOOTING) {
  1211. if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
  1212. if (ShmSysConfigAndInfo->SysConfig.isQRCode) {
  1213. needReloadQr = false;
  1214. ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220. break;
  1221. case _LCM_FIX:
  1222. if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
  1223. ChangeDisplay2Value(_emergency_map, _emergency_disable_map);
  1224. } else {
  1225. ChangeDisplay2Value(_emergency_map, _disappear);
  1226. }
  1227. break;
  1228. }
  1229. }
  1230. void ChangeDisplayMoneyInfo()
  1231. {
  1232. uint8_t curGun = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
  1233. if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling) {
  1234. struct timeb csuTime;
  1235. struct tm *tmCSU;
  1236. ftime(&csuTime);
  1237. tmCSU = localtime(&csuTime.time);
  1238. ChangeDisplay2Value(__money_rate_map, _charging_money);
  1239. if (gAudiCustInfo->PricesInfo[curGun].UserPrices != 0.00) { //Jerry add
  1240. DisplayMoneyRate(gAudiCustInfo->PricesInfo[curGun].UserPrices);
  1241. } else {
  1242. if (tmCSU->tm_hour <= 23) {
  1243. ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
  1244. DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
  1245. }
  1246. if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53) {
  1247. DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
  1248. }
  1249. }
  1250. } else {
  1251. ChangeDisplay2Value(__money_rate_map, _disappear);
  1252. ChangeDisplay2Value(__money_by_rate, _disappear);
  1253. ChangeDisplay2Value(__money_rate, _disappear);
  1254. }
  1255. }
  1256. void Initialization()
  1257. {
  1258. bool isPass = false;
  1259. byte count = 5;
  1260. while (!isPass && count > 0) {
  1261. isPass = true;
  1262. for (byte _index = 0; _index < _totalCount; _index++) {
  1263. if (!FindChargingInfoData(_index, &_chargingInfoData[0])) {
  1264. DEBUG_ERROR("LcmComm (main) : FindChargingInfoData false \n");
  1265. isPass = false;
  1266. count--;
  1267. break;
  1268. }
  1269. }
  1270. sleep(1);
  1271. }
  1272. isPass = false;
  1273. if (acgunCount > 0) {
  1274. while (!isPass) {
  1275. isPass = true;
  1276. for (byte _index = 0; _index < acgunCount; _index++) {
  1277. if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0])) {
  1278. DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
  1279. isPass = false;
  1280. break;
  1281. }
  1282. }
  1283. sleep(1);
  1284. }
  1285. }
  1286. if (count == 0) {
  1287. PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
  1288. }
  1289. }
  1290. int main(void)
  1291. {
  1292. if (InitShareMemory() == FAIL) {
  1293. #ifdef SystemLogMessage
  1294. DEBUG_ERROR("InitShareMemory NG\n");
  1295. #endif
  1296. if (ShmStatusCodeData != NULL) {
  1297. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  1298. }
  1299. sleep(5);
  1300. return 0;
  1301. }
  1302. _port = CreateCommunicationLcmPort();
  1303. byte changeWarningPriority = 0;
  1304. byte curWarningCount = 255;
  1305. ChangeBackLight(true);
  1306. _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
  1307. acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
  1308. Initialization();
  1309. //ChangeToOtherPage(_LCM_COMPLETE);
  1310. //return 0;
  1311. for (byte i = 0; i < 3; i++) {
  1312. ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
  1313. }
  1314. while (_port != -1) {
  1315. if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName) != 0x00) {
  1316. GetCurrentPage();
  1317. sleep(1);
  1318. } else {
  1319. //DemoFunction();
  1320. // Warning 處理
  1321. if (curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount) {
  1322. changeWarningPriority = 0;
  1323. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1324. curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
  1325. ChangeWarningFunc();
  1326. } else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0) {
  1327. // 當有兩頁 Warning 則每隔三秒改變一次
  1328. if (ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0) {
  1329. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
  1330. } else {
  1331. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1332. }
  1333. ChangeWarningFunc();
  1334. }
  1335. // 頁面資訊處理
  1336. ProcessPageInfo();
  1337. // 網路 - wifi - 連線訊號處理
  1338. RefreshConnStatus();
  1339. // 換頁處理
  1340. ChangeCurPage();
  1341. RefreshPageAnimation(_everyPageRollChange);
  1342. //if (changeWarningPriority == 0) { ////For Audi
  1343. ChangeDisplayMoneyInfo();
  1344. //}
  1345. changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
  1346. changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
  1347. usleep(100000);
  1348. }
  1349. }
  1350. CloseCommunicationLcmPort();
  1351. return FAIL;
  1352. }