Module_LcmControl.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <unistd.h>
  16. #include <stdarg.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <fcntl.h>
  21. #include <termios.h>
  22. #include <errno.h>
  23. #include <errno.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include "define.h"
  29. #include "main.h"
  30. #include "lcmComm.h"
  31. #include "Image.h"
  32. #include "qrcode.h"
  33. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  34. #define PASS 1
  35. #define FAIL -1
  36. #define YES 1
  37. #define NO 0
  38. #define ON 1
  39. #define OFF 0
  40. #define PAGE_DISPLAY_PERIOD 3
  41. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  42. struct StatusCodeData *ShmStatusCodeData;
  43. struct Charger *ShmCharger;
  44. void trim(char *s);
  45. int mystrcmp(char *p1,char *p2);
  46. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  47. void split(char **arr, char *str, const char *del);
  48. int Uart1Fd;
  49. QRCode qrcode;
  50. //=================================
  51. // Common routine
  52. //=================================
  53. int StoreLogMsg(const char *fmt, ...)
  54. {
  55. char Buf[4096+256];
  56. char buffer[4096];
  57. time_t CurrentTime;
  58. struct tm *tm;
  59. struct timeval tv;
  60. va_list args;
  61. va_start(args, fmt);
  62. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  63. va_end(args);
  64. memset(Buf,0,sizeof(Buf));
  65. CurrentTime = time(NULL);
  66. tm=localtime(&CurrentTime);
  67. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  68. if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
  69. {
  70. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_LcmSystemLog",
  71. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  72. buffer,
  73. tm->tm_year+1900,tm->tm_mon+1,
  74. ShmSysConfigAndInfo->SysConfig.ModelName,
  75. ShmSysConfigAndInfo->SysConfig.SerialNumber);
  76. }
  77. else
  78. {
  79. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s\" >> /Storage/SystemLog/[%04d.%02d]LcmSystemLog",
  80. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  81. buffer,
  82. tm->tm_year+1900,tm->tm_mon+1);
  83. }
  84. #ifdef SystemLogMessage
  85. system(Buf);
  86. #endif
  87. #ifdef ConsloePrintLog
  88. printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
  89. #endif
  90. return rc;
  91. }
  92. int DiffTimeb(struct timeb ST, struct timeb ET)
  93. {
  94. //return milli-second
  95. unsigned int StartTime,StopTime;
  96. StartTime=(unsigned int)ST.time;
  97. StopTime=(unsigned int)ET.time;
  98. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  99. }
  100. void trim(char *s)
  101. {
  102. int i=0, j, k, l=0;
  103. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  104. i++;
  105. j = strlen(s)-1;
  106. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  107. j--;
  108. if(i==0 && j==strlen(s)-1) { }
  109. else if(i==0) s[j+1] = '\0';
  110. else {
  111. for(k=i; k<=j; k++) s[l++] = s[k];
  112. s[l] = '\0';
  113. }
  114. }
  115. int mystrcmp(char *p1,char *p2)
  116. {
  117. while(*p1==*p2)
  118. {
  119. if(*p1=='\0' || *p2=='\0')
  120. break;
  121. p1++;
  122. p2++;
  123. }
  124. if(*p1=='\0' && *p2=='\0')
  125. return(PASS);
  126. else
  127. return(FAIL);
  128. }
  129. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  130. {
  131. strncpy(dest, src + start, cnt);
  132. dest[cnt] = 0;
  133. }
  134. void split(char **arr, char *str, const char *del)
  135. {
  136. char *s = strtok(str, del);
  137. while(s != NULL)
  138. {
  139. *arr++ = s;
  140. s = strtok(NULL, del);
  141. }
  142. }
  143. //==========================================
  144. // Page routine
  145. //==========================================
  146. void page_booting()
  147. {
  148. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  149. {
  150. case LCD_LANG_CHT:
  151. case LCD_LANG_CHS:
  152. case LCD_LANG_JAPANESE:
  153. case LCD_LANG_FRENCH:
  154. case LCD_LANG_ITALIAN:
  155. case LCD_LANG_SPANISH:
  156. case LCD_LANG_GERMAN:
  157. case LCD_LANG_DUTCH:
  158. case LCD_LANG_NORWEGIAN:
  159. case LCD_LANG_FINNISH:
  160. case LCD_LANG_SWEDISH:
  161. case LCD_LANG_SLOVENIAN:
  162. case LCD_LANG_THAI:
  163. case LCD_LANG_ENGLISH:
  164. default:
  165. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 8, 128, 64);
  166. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 8, 128, 64, IMG_ADDR_INIT);
  167. break;
  168. }
  169. }
  170. void page_idle()
  171. {
  172. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  173. {
  174. case LCD_LANG_CHT:
  175. case LCD_LANG_CHS:
  176. case LCD_LANG_JAPANESE:
  177. case LCD_LANG_FRENCH:
  178. case LCD_LANG_ITALIAN:
  179. case LCD_LANG_SPANISH:
  180. case LCD_LANG_GERMAN:
  181. case LCD_LANG_DUTCH:
  182. case LCD_LANG_NORWEGIAN:
  183. case LCD_LANG_FINNISH:
  184. case LCD_LANG_SWEDISH:
  185. case LCD_LANG_SLOVENIAN:
  186. case LCD_LANG_THAI:
  187. case LCD_LANG_ENGLISH:
  188. default:
  189. dispGraphicArea(Uart1Fd, AREAD_ID_0, YES, 4, 8, 64, 64, IMG_ADDR_QRCODE);
  190. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 70, 18, 70+48, 18+38, IMG_ADDR_TAP_RFID);
  191. break;
  192. }
  193. }
  194. void page_authorizing()
  195. {
  196. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  197. {
  198. case LCD_LANG_CHT:
  199. case LCD_LANG_CHS:
  200. case LCD_LANG_JAPANESE:
  201. case LCD_LANG_FRENCH:
  202. case LCD_LANG_ITALIAN:
  203. case LCD_LANG_SPANISH:
  204. case LCD_LANG_GERMAN:
  205. case LCD_LANG_DUTCH:
  206. case LCD_LANG_NORWEGIAN:
  207. case LCD_LANG_FINNISH:
  208. case LCD_LANG_SWEDISH:
  209. case LCD_LANG_SLOVENIAN:
  210. case LCD_LANG_THAI:
  211. case LCD_LANG_ENGLISH:
  212. default:
  213. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 8, 128, 64);
  214. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 8, 128, 64, IMG_ADDR_VERIFY);
  215. break;
  216. }
  217. }
  218. void page_preparing()
  219. {
  220. static uint8_t idxPage = 0;
  221. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  222. {
  223. case LCD_LANG_CHT:
  224. case LCD_LANG_CHS:
  225. case LCD_LANG_JAPANESE:
  226. case LCD_LANG_FRENCH:
  227. case LCD_LANG_ITALIAN:
  228. case LCD_LANG_SPANISH:
  229. case LCD_LANG_GERMAN:
  230. case LCD_LANG_DUTCH:
  231. case LCD_LANG_NORWEGIAN:
  232. case LCD_LANG_FINNISH:
  233. case LCD_LANG_SWEDISH:
  234. case LCD_LANG_SLOVENIAN:
  235. case LCD_LANG_THAI:
  236. case LCD_LANG_ENGLISH:
  237. default:
  238. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 15, 128, 64);
  239. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 10, 128, 54, IMG_ADDR_HANDSHAKE_1+idxPage);
  240. break;
  241. }
  242. idxPage ^= 1;
  243. }
  244. void page_charging()
  245. {
  246. uint8_t buf[128];
  247. static uint8_t idxBatt = 0;
  248. static uint8_t idxPage = 0;
  249. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  250. {
  251. case LCD_LANG_CHT:
  252. case LCD_LANG_CHS:
  253. case LCD_LANG_JAPANESE:
  254. case LCD_LANG_FRENCH:
  255. case LCD_LANG_ITALIAN:
  256. case LCD_LANG_SPANISH:
  257. case LCD_LANG_GERMAN:
  258. case LCD_LANG_DUTCH:
  259. case LCD_LANG_NORWEGIAN:
  260. case LCD_LANG_FINNISH:
  261. case LCD_LANG_SWEDISH:
  262. case LCD_LANG_SLOVENIAN:
  263. case LCD_LANG_THAI:
  264. case LCD_LANG_ENGLISH:
  265. default:
  266. dispGraphicArea(Uart1Fd, AREAD_ID_0, YES, 0, 19, 48, 36, IMG_ADDR_ICON_B0+idxBatt);
  267. //dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 0, 40, 48, 64, IMG_ADDR_ICON_COMPLETE);
  268. switch(idxPage/PAGE_DISPLAY_PERIOD)
  269. {
  270. case 0:
  271. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 48, 14, 70, 38, IMG_ADDR_ICON_ENERGY);
  272. sprintf((char*)buf, " 000.0000");
  273. dispCharacterArea(Uart1Fd, AREAD_ID_2, 72, 22, 128, 40, FONT_ASCII_6X8, buf, strlen((char*)buf));
  274. dispGraphicArea(Uart1Fd, AREAD_ID_3, YES, 48, 40, 81, 64, IMG_ADDR_ICON_TIME);
  275. sprintf((char*)buf, " 000:00");
  276. dispCharacterArea(Uart1Fd, AREAD_ID_4, 84, 48, 128, 64, FONT_ASCII_6X8, buf, strlen((char*)buf));
  277. idxPage++;
  278. break;
  279. case 1:
  280. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 48, 14, 70, 38, IMG_ADDR_ICON_COST);
  281. sprintf((char*)buf, " 0.45");
  282. dispCharacterArea(Uart1Fd, AREAD_ID_2, 72, 22, 128, 40, FONT_ASCII_6X8, buf, strlen((char*)buf));
  283. dispGraphicArea(Uart1Fd, AREAD_ID_3, YES, 48, 40, 81, 64, IMG_ADDR_ICON_PRICE);
  284. sprintf((char*)buf, " 123.88");
  285. dispCharacterArea(Uart1Fd, AREAD_ID_4, 84, 48, 128, 64, FONT_ASCII_6X8, buf, strlen((char*)buf));
  286. idxPage++;
  287. break;
  288. default:
  289. idxPage = 0;
  290. break;
  291. }
  292. break;
  293. }
  294. if(idxBatt<5)
  295. idxBatt++;
  296. else
  297. idxBatt =0;
  298. }
  299. void page_complete()
  300. {
  301. uint8_t buf[128];
  302. static uint8_t idxPage = 0;
  303. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  304. {
  305. case LCD_LANG_CHT:
  306. case LCD_LANG_CHS:
  307. case LCD_LANG_JAPANESE:
  308. case LCD_LANG_FRENCH:
  309. case LCD_LANG_ITALIAN:
  310. case LCD_LANG_SPANISH:
  311. case LCD_LANG_GERMAN:
  312. case LCD_LANG_DUTCH:
  313. case LCD_LANG_NORWEGIAN:
  314. case LCD_LANG_FINNISH:
  315. case LCD_LANG_SWEDISH:
  316. case LCD_LANG_SLOVENIAN:
  317. case LCD_LANG_THAI:
  318. case LCD_LANG_ENGLISH:
  319. default:
  320. dispGraphicArea(Uart1Fd, AREAD_ID_0, YES, 0, 20, 48, 36, IMG_ADDR_ICON_B100);
  321. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 0, 40, 48, 64, IMG_ADDR_ICON_COMPLETE);
  322. switch(idxPage/PAGE_DISPLAY_PERIOD)
  323. {
  324. case 0:
  325. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 48, 14, 70, 38, IMG_ADDR_ICON_ENERGY);
  326. sprintf((char*)buf, " 000.0000");
  327. dispCharacterArea(Uart1Fd, AREAD_ID_2, 72, 22, 128, 40, FONT_ASCII_6X8, buf, strlen((char*)buf));
  328. dispGraphicArea(Uart1Fd, AREAD_ID_3, YES, 48, 40, 81, 64, IMG_ADDR_ICON_TIME);
  329. sprintf((char*)buf, " 000:00");
  330. dispCharacterArea(Uart1Fd, AREAD_ID_4, 84, 48, 128, 64, FONT_ASCII_6X8, buf, strlen((char*)buf));
  331. idxPage++;
  332. break;
  333. case 1:
  334. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 48, 14, 70, 38, IMG_ADDR_ICON_COST);
  335. sprintf((char*)buf, " 0.45");
  336. dispCharacterArea(Uart1Fd, AREAD_ID_2, 72, 22, 128, 40, FONT_ASCII_6X8, buf, strlen((char*)buf));
  337. dispGraphicArea(Uart1Fd, AREAD_ID_3, YES, 48, 40, 81, 64, IMG_ADDR_ICON_PRICE);
  338. sprintf((char*)buf, " 123.88");
  339. dispCharacterArea(Uart1Fd, AREAD_ID_4, 84, 48, 128, 64, FONT_ASCII_6X8, buf, strlen((char*)buf));
  340. idxPage++;
  341. break;
  342. }
  343. break;
  344. }
  345. }
  346. void page_terminating()
  347. {
  348. uint8_t buf[128];
  349. static uint8_t idxPage = 0;
  350. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  351. {
  352. case LCD_LANG_CHT:
  353. case LCD_LANG_CHS:
  354. case LCD_LANG_JAPANESE:
  355. case LCD_LANG_FRENCH:
  356. case LCD_LANG_ITALIAN:
  357. case LCD_LANG_SPANISH:
  358. case LCD_LANG_GERMAN:
  359. case LCD_LANG_DUTCH:
  360. case LCD_LANG_NORWEGIAN:
  361. case LCD_LANG_FINNISH:
  362. case LCD_LANG_SWEDISH:
  363. case LCD_LANG_SLOVENIAN:
  364. case LCD_LANG_THAI:
  365. case LCD_LANG_ENGLISH:
  366. default:
  367. dispGraphicArea(Uart1Fd, AREAD_ID_0, YES, 0, 20, 48, 36, IMG_ADDR_ICON_B100);
  368. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 0, 40, 48, 64, IMG_ADDR_ICON_COMPLETE);
  369. switch(idxPage/PAGE_DISPLAY_PERIOD)
  370. {
  371. case 0:
  372. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 48, 14, 70, 38, IMG_ADDR_ICON_ENERGY);
  373. sprintf((char*)buf, " 000.0000");
  374. dispCharacterArea(Uart1Fd, AREAD_ID_2, 72, 22, 128, 40, FONT_ASCII_6X8, buf, strlen((char*)buf));
  375. dispGraphicArea(Uart1Fd, AREAD_ID_3, YES, 48, 40, 81, 64, IMG_ADDR_ICON_TIME);
  376. sprintf((char*)buf, " 000:00");
  377. dispCharacterArea(Uart1Fd, AREAD_ID_4, 84, 48, 128, 64, FONT_ASCII_6X8, buf, strlen((char*)buf));
  378. idxPage++;
  379. break;
  380. case 1:
  381. dispGraphicArea(Uart1Fd, AREAD_ID_1, YES, 48, 14, 70, 38, IMG_ADDR_ICON_COST);
  382. sprintf((char*)buf, " 0.45");
  383. dispCharacterArea(Uart1Fd, AREAD_ID_2, 72, 22, 128, 40, FONT_ASCII_6X8, buf, strlen((char*)buf));
  384. dispGraphicArea(Uart1Fd, AREAD_ID_3, YES, 48, 40, 81, 64, IMG_ADDR_ICON_PRICE);
  385. sprintf((char*)buf, " 123.88");
  386. dispCharacterArea(Uart1Fd, AREAD_ID_4, 84, 48, 128, 64, FONT_ASCII_6X8, buf, strlen((char*)buf));
  387. idxPage++;
  388. break;
  389. }
  390. break;
  391. }
  392. }
  393. void page_alarm()
  394. {
  395. uint8_t buf[128];
  396. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  397. {
  398. case LCD_LANG_CHT:
  399. case LCD_LANG_CHS:
  400. case LCD_LANG_JAPANESE:
  401. case LCD_LANG_FRENCH:
  402. case LCD_LANG_ITALIAN:
  403. case LCD_LANG_SPANISH:
  404. case LCD_LANG_GERMAN:
  405. case LCD_LANG_DUTCH:
  406. case LCD_LANG_NORWEGIAN:
  407. case LCD_LANG_FINNISH:
  408. case LCD_LANG_SWEDISH:
  409. case LCD_LANG_SLOVENIAN:
  410. case LCD_LANG_THAI:
  411. case LCD_LANG_ENGLISH:
  412. default:
  413. dispGraphicArea(Uart1Fd, AREAD_ID_0, YES, 32, 24, 48, 40, IMG_ADDR_ICON_ALERT);
  414. sprintf((char*)buf, "012336");
  415. dispCharacterArea(Uart1Fd, AREAD_ID_1, 50, 26, 128, 40, FONT_ASCII_8X12, buf, strlen((char*)buf));
  416. break;
  417. }
  418. }
  419. void page_fault()
  420. {
  421. uint8_t buf[128];
  422. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  423. {
  424. case LCD_LANG_CHT:
  425. case LCD_LANG_CHS:
  426. case LCD_LANG_JAPANESE:
  427. case LCD_LANG_FRENCH:
  428. case LCD_LANG_ITALIAN:
  429. case LCD_LANG_SPANISH:
  430. case LCD_LANG_GERMAN:
  431. case LCD_LANG_DUTCH:
  432. case LCD_LANG_NORWEGIAN:
  433. case LCD_LANG_FINNISH:
  434. case LCD_LANG_SWEDISH:
  435. case LCD_LANG_SLOVENIAN:
  436. case LCD_LANG_THAI:
  437. case LCD_LANG_ENGLISH:
  438. default:
  439. dispGraphicArea(Uart1Fd, AREAD_ID_0, YES, 32, 24, 48, 40, IMG_ADDR_ICON_ALERT);
  440. sprintf((char*)buf, "012336");
  441. dispCharacterArea(Uart1Fd, AREAD_ID_1, 50, 26, 128, 40, FONT_ASCII_8X12, buf, strlen((char*)buf));
  442. break;
  443. }
  444. }
  445. void page_maintain()
  446. {
  447. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  448. {
  449. case LCD_LANG_CHT:
  450. case LCD_LANG_CHS:
  451. case LCD_LANG_JAPANESE:
  452. case LCD_LANG_FRENCH:
  453. case LCD_LANG_ITALIAN:
  454. case LCD_LANG_SPANISH:
  455. case LCD_LANG_GERMAN:
  456. case LCD_LANG_DUTCH:
  457. case LCD_LANG_NORWEGIAN:
  458. case LCD_LANG_FINNISH:
  459. case LCD_LANG_SWEDISH:
  460. case LCD_LANG_SLOVENIAN:
  461. case LCD_LANG_THAI:
  462. case LCD_LANG_ENGLISH:
  463. default:
  464. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 8, 128, 64);
  465. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 8, 128, 64, IMG_ADDR_MAINTIAN);
  466. break;
  467. }
  468. }
  469. void page_update()
  470. {
  471. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  472. {
  473. case LCD_LANG_CHT:
  474. case LCD_LANG_CHS:
  475. case LCD_LANG_JAPANESE:
  476. case LCD_LANG_FRENCH:
  477. case LCD_LANG_ITALIAN:
  478. case LCD_LANG_SPANISH:
  479. case LCD_LANG_GERMAN:
  480. case LCD_LANG_DUTCH:
  481. case LCD_LANG_NORWEGIAN:
  482. case LCD_LANG_FINNISH:
  483. case LCD_LANG_SWEDISH:
  484. case LCD_LANG_SLOVENIAN:
  485. case LCD_LANG_THAI:
  486. case LCD_LANG_ENGLISH:
  487. default:
  488. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 8, 128, 64);
  489. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 8, 128, 64, IMG_ADDR_MAINTIAN);
  490. break;
  491. }
  492. }
  493. void page_reservation()
  494. {
  495. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  496. {
  497. case LCD_LANG_CHT:
  498. case LCD_LANG_CHS:
  499. case LCD_LANG_JAPANESE:
  500. case LCD_LANG_FRENCH:
  501. case LCD_LANG_ITALIAN:
  502. case LCD_LANG_SPANISH:
  503. case LCD_LANG_GERMAN:
  504. case LCD_LANG_DUTCH:
  505. case LCD_LANG_NORWEGIAN:
  506. case LCD_LANG_FINNISH:
  507. case LCD_LANG_SWEDISH:
  508. case LCD_LANG_SLOVENIAN:
  509. case LCD_LANG_THAI:
  510. case LCD_LANG_ENGLISH:
  511. default:
  512. break;
  513. }
  514. }
  515. void page_booking()
  516. {
  517. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  518. {
  519. case LCD_LANG_CHT:
  520. case LCD_LANG_CHS:
  521. case LCD_LANG_JAPANESE:
  522. case LCD_LANG_FRENCH:
  523. case LCD_LANG_ITALIAN:
  524. case LCD_LANG_SPANISH:
  525. case LCD_LANG_GERMAN:
  526. case LCD_LANG_DUTCH:
  527. case LCD_LANG_NORWEGIAN:
  528. case LCD_LANG_FINNISH:
  529. case LCD_LANG_SWEDISH:
  530. case LCD_LANG_SLOVENIAN:
  531. case LCD_LANG_THAI:
  532. case LCD_LANG_ENGLISH:
  533. default:
  534. break;
  535. }
  536. }
  537. void page_debug()
  538. {
  539. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  540. {
  541. case LCD_LANG_CHT:
  542. case LCD_LANG_CHS:
  543. case LCD_LANG_JAPANESE:
  544. case LCD_LANG_FRENCH:
  545. case LCD_LANG_ITALIAN:
  546. case LCD_LANG_SPANISH:
  547. case LCD_LANG_GERMAN:
  548. case LCD_LANG_DUTCH:
  549. case LCD_LANG_NORWEGIAN:
  550. case LCD_LANG_FINNISH:
  551. case LCD_LANG_SWEDISH:
  552. case LCD_LANG_SLOVENIAN:
  553. case LCD_LANG_THAI:
  554. case LCD_LANG_ENGLISH:
  555. default:
  556. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 8, 128, 64);
  557. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 8, 128, 64, IMG_ADDR_MAINTIAN);
  558. break;
  559. }
  560. }
  561. void page_unknown()
  562. {
  563. switch(ShmSysConfigAndInfo->SysConfig.DefaultLanguage)
  564. {
  565. case LCD_LANG_CHT:
  566. case LCD_LANG_CHS:
  567. case LCD_LANG_JAPANESE:
  568. case LCD_LANG_FRENCH:
  569. case LCD_LANG_ITALIAN:
  570. case LCD_LANG_SPANISH:
  571. case LCD_LANG_GERMAN:
  572. case LCD_LANG_DUTCH:
  573. case LCD_LANG_NORWEGIAN:
  574. case LCD_LANG_FINNISH:
  575. case LCD_LANG_SWEDISH:
  576. case LCD_LANG_SLOVENIAN:
  577. case LCD_LANG_THAI:
  578. case LCD_LANG_ENGLISH:
  579. default:
  580. dispGraphicConfig(Uart1Fd, AREAD_ID_0, YES, 0, 8, 128, 64);
  581. dispGraphicPartial(Uart1Fd, AREAD_ID_0, YES, 0, 0, 0, 8, 128, 64, IMG_ADDR_MAINTIAN);
  582. break;
  583. }
  584. }
  585. void page_header()
  586. {
  587. uint8_t buf[128];
  588. if(sysFlag.isEnable4G)
  589. {
  590. // Drawing 4G signal strength
  591. if((ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi == 0) || (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi == 99))
  592. {
  593. drawRfSignal(Uart1Fd, 0, YES);
  594. }
  595. else if((1 <= ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi) && (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi < 9)) // -95dBm ~ -111dBm
  596. {
  597. drawRfSignal(Uart1Fd, 1, YES);
  598. }
  599. else if((9 <= ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi) && (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi < 14)) // -85dBm ~ -95dBm
  600. {
  601. drawRfSignal(Uart1Fd, 2, YES);
  602. }
  603. else if((14 <= ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi) && (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi < 19)) // -75dBm ~ -85dBm
  604. {
  605. drawRfSignal(Uart1Fd, 3, YES);
  606. }
  607. else if((19 <= ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi) && (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi < 27)) // -60dBm ~ -75dBm
  608. {
  609. drawRfSignal(Uart1Fd, 4, YES);
  610. }
  611. else if((27 <= ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi)) // 60dBm ~
  612. {
  613. drawRfSignal(Uart1Fd, 5, YES);
  614. }
  615. else
  616. {
  617. drawRfSignal(Uart1Fd, 0, YES);
  618. }
  619. }
  620. if(sysFlag.isEnableWiFi)
  621. {
  622. // Drawing WIFI signal strength
  623. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi == 0)
  624. {
  625. drawRfSignal(Uart1Fd, 0, NO);
  626. }
  627. else if((-100 <= ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi) && (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi < -80))
  628. {
  629. drawRfSignal(Uart1Fd, 1, NO);
  630. }
  631. else if((-80 <= ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi) && (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi < -70))
  632. {
  633. drawRfSignal(Uart1Fd, 2, NO);
  634. }
  635. else if((-70 <= ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi) && (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi < -50))
  636. {
  637. drawRfSignal(Uart1Fd, 3, NO);
  638. }
  639. else if((-50 <= ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi) && (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi < -30))
  640. {
  641. drawRfSignal(Uart1Fd, 4, NO);
  642. }
  643. else if((-30 <= ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi))
  644. {
  645. drawRfSignal(Uart1Fd, 5, NO);
  646. }
  647. else
  648. {
  649. drawRfSignal(Uart1Fd, 0, NO);
  650. }
  651. }
  652. // Drawing ethernet status
  653. dispGraphic(Uart1Fd, YES, 121-(sysFlag.isEnableWiFi?26:0)+(sysFlag.isEnable4G?26:0), 0, (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet?IMG_ADDR_ICON_LAN_OFF:IMG_ADDR_ICON_LAN_ON));
  654. // Unit price display
  655. if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
  656. {
  657. sprintf((char*)buf, "%.2f %s/KWH", ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee, Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
  658. dispCharacterArea(Uart1Fd, AREAD_ID_HEADER_PRICE, 0, 0, 30, 7, FONT_ASCII_4X6, buf, strlen((char*)buf));
  659. }
  660. else
  661. {
  662. dispCharacterArea(Uart1Fd, AREAD_ID_HEADER_PRICE, 0, 0, 30, 7, FONT_ASCII_4X6, (uint8_t*)"", strlen(""));
  663. }
  664. //dispCharacterConfig(Uart1Fd, AREAD_ID_HEADER, YES, 0, 0, 30, 7);
  665. //dispCharacterScroll(Uart1Fd, AREAD_ID_HEADER, 0, 0, 40, 7, FONT_ASCII_4X6, NO, 25, (uint8_t*)"012334", strlen("012334"));
  666. //dispCharacterBlink(Uart1Fd, AREAD_ID_HEADER, 0, 0, FONT_ASCII_4X6, 1, 100, (uint8_t*)"ABCDEFG", strlen("ABCDEFG"));
  667. }
  668. //==========================================
  669. // Init all share memory
  670. //==========================================
  671. int InitShareMemory()
  672. {
  673. int result = PASS;
  674. int MeterSMId;
  675. //creat ShmSysConfigAndInfo
  676. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  677. {
  678. #ifdef SystemLogMessage
  679. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  680. #endif
  681. result = FAIL;
  682. }
  683. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  684. {
  685. #ifdef SystemLogMessage
  686. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  687. #endif
  688. result = FAIL;
  689. }
  690. else
  691. {}
  692. //creat ShmStatusCodeData
  693. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  694. {
  695. #ifdef SystemLogMessage
  696. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  697. #endif
  698. result = FAIL;
  699. }
  700. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  701. {
  702. #ifdef SystemLogMessage
  703. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  704. #endif
  705. result = FAIL;
  706. }
  707. else
  708. {}
  709. //Initial ShmCharger
  710. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  711. {
  712. #ifdef SystemLogMessage
  713. DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
  714. #endif
  715. result = FAIL;
  716. }
  717. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  718. {
  719. #ifdef SystemLogMessage
  720. DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
  721. #endif
  722. result = FAIL;
  723. }
  724. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T'))
  725. sysFlag.isEnable4G = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled;
  726. else
  727. sysFlag.isEnable4G = OFF;
  728. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W'))
  729. sysFlag.isEnableWiFi = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode;
  730. else
  731. sysFlag.isEnableWiFi = OFF;
  732. DEBUG_INFO("sysFlag.isEnable4G: %d\n", sysFlag.isEnable4G);
  733. DEBUG_INFO("sysFlag.isEnableWiFi: %d\n", sysFlag.isEnableWiFi);
  734. return result;
  735. }
  736. int InitComPort()
  737. {
  738. int fd;
  739. struct termios tios;
  740. fd = open("/dev/ttyS3", O_RDWR);
  741. if(fd<=0)
  742. {
  743. DEBUG_ERROR("open /dev/ttyS3 NG\n");
  744. return -1;
  745. }
  746. ioctl (fd, TCGETS, &tios);
  747. tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
  748. tios.c_lflag = 0;
  749. tios.c_iflag = 0;
  750. tios.c_oflag = 0;
  751. tios.c_cc[VMIN]=0;
  752. tios.c_cc[VTIME]=(unsigned char)1; // timeout 0.5 secod
  753. tios.c_lflag=0;
  754. tcflush(fd, TCIFLUSH);
  755. ioctl (fd, TCSETS, &tios);
  756. return fd;
  757. }
  758. int InitLcdModule()
  759. {
  760. int result = FAIL;
  761. uint8_t qrcodeData[qrcode_getBufferSize(SIZE_53X53)];
  762. uint8_t qrImageRaw[((53/8)+1)*53];
  763. uint16_t dataMaxLen = 512;
  764. uint8_t qrcontent[196];
  765. sprintf((char*)qrcontent, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  766. qrcode_initText(&qrcode, qrcodeData, SIZE_53X53, 0, (char*)qrcontent);
  767. // Power on LCD
  768. setPower(Uart1Fd, ON);
  769. // Clear LCD page
  770. clearScreen(Uart1Fd, NO, 0, 0, 128, 64);
  771. // Set LCE brightness
  772. setContrast(Uart1Fd, 255, 255, 1);
  773. // Display initial screen
  774. page_booting();
  775. // QR code raw data generate
  776. memset(qrImageRaw, 0x00, ARRAY_SIZE(qrImageRaw));
  777. for(uint16_t idxY = 0;idxY<qrcode.size;idxY++)
  778. {
  779. for(uint16_t idxX = 0;idxX<qrcode.size;idxX++)
  780. {
  781. if(qrcode_getModule(&qrcode, idxX, idxY))
  782. {
  783. //drawPoint(Uart1Fd, idxX, idxY);
  784. qrImageRaw[(7*idxY) + (idxX/8)] |= (0x01<<(7-(idxX%8)));
  785. }
  786. else
  787. {
  788. qrImageRaw[(7*idxY) + (idxX/8)] &= ~(0x01<<(7-(idxX%8)));
  789. }
  790. }
  791. }
  792. // Upload image file
  793. // QR Code
  794. picUploadStart(Uart1Fd, IMG_ADDR_QRCODE, 53, 53);
  795. for(uint8_t idx=0;idx<=ARRAY_SIZE(qrImageRaw)/dataMaxLen;idx++)
  796. {
  797. if((idx < (ARRAY_SIZE(qrImageRaw)/dataMaxLen)) || ((idx == (ARRAY_SIZE(qrImageRaw)/dataMaxLen)) && ((ARRAY_SIZE(qrImageRaw)%dataMaxLen)>0)))
  798. picUploadData(Uart1Fd, IMG_ADDR_QRCODE, (idx*dataMaxLen), &qrImageRaw[idx*dataMaxLen], (idx<(ARRAY_SIZE(qrImageRaw)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(qrImageRaw)%dataMaxLen)) );
  799. }
  800. // LAN icon
  801. for(uint8_t idxLAN=0;idxLAN<6;idxLAN++)
  802. {
  803. picUploadStart(Uart1Fd, IMG_ADDR_ICON_LAN_OFF+idxLAN, 7, 7);
  804. for(uint8_t idx=0;idx<=ARRAY_SIZE(LAN_Icon[idxLAN])/dataMaxLen;idx++)
  805. {
  806. if((idx < (ARRAY_SIZE(LAN_Icon[idxLAN])/dataMaxLen)) || ((idx == (ARRAY_SIZE(LAN_Icon[idxLAN])/dataMaxLen)) && ((ARRAY_SIZE(LAN_Icon[idxLAN])%dataMaxLen)>0)))
  807. picUploadData(Uart1Fd, IMG_ADDR_ICON_LAN_OFF+idxLAN, (idx*dataMaxLen), &LAN_Icon[idxLAN][idx*dataMaxLen], (idx<(ARRAY_SIZE(LAN_Icon[idxLAN])/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(LAN_Icon[idxLAN])%dataMaxLen)) );
  808. }
  809. }
  810. // RF icon
  811. for(uint8_t idxRF=0;idxRF<6;idxRF++)
  812. {
  813. picUploadStart(Uart1Fd, IMG_ADDR_RF_0+idxRF, 19, 7);
  814. for(uint8_t idx=0;idx<=ARRAY_SIZE(RF_Icon[idxRF])/dataMaxLen;idx++)
  815. {
  816. if((idx < (ARRAY_SIZE(RF_Icon[idxRF])/dataMaxLen)) || ((idx == (ARRAY_SIZE(RF_Icon[idxRF])/dataMaxLen)) && ((ARRAY_SIZE(RF_Icon[idxRF])%dataMaxLen)>0)))
  817. picUploadData(Uart1Fd, IMG_ADDR_RF_0+idxRF, (idx*dataMaxLen), &RF_Icon[idxRF][idx*dataMaxLen], (idx<(ARRAY_SIZE(RF_Icon[idxRF])/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(RF_Icon[idxRF])%dataMaxLen)) );
  818. }
  819. }
  820. // Init image
  821. picUploadStart(Uart1Fd, IMG_ADDR_INIT, 128, 64);
  822. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_init)/dataMaxLen;idx++)
  823. {
  824. if((idx < (ARRAY_SIZE(img_init)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_init)/dataMaxLen)) && ((ARRAY_SIZE(img_init)%dataMaxLen)>0)))
  825. picUploadData(Uart1Fd, IMG_ADDR_INIT, (idx*dataMaxLen), &img_init[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_init)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_init)%dataMaxLen)) );
  826. }
  827. // RIFD image
  828. picUploadStart(Uart1Fd, IMG_ADDR_TAP_RFID, 48, 38);
  829. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_rfid)/dataMaxLen;idx++)
  830. {
  831. if((idx < (ARRAY_SIZE(img_rfid)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_rfid)/dataMaxLen)) && ((ARRAY_SIZE(img_rfid)%dataMaxLen)>0)))
  832. picUploadData(Uart1Fd, IMG_ADDR_TAP_RFID, (idx*dataMaxLen), &img_rfid[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_rfid)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_rfid)%dataMaxLen)) );
  833. }
  834. // Handshake 1 image
  835. picUploadStart(Uart1Fd, IMG_ADDR_HANDSHAKE_1, 128, 64);
  836. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_handshake_1)/dataMaxLen;idx++)
  837. {
  838. if((idx < (ARRAY_SIZE(img_handshake_1)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_handshake_1)/dataMaxLen)) && ((ARRAY_SIZE(img_handshake_1)%dataMaxLen)>0)))
  839. picUploadData(Uart1Fd, IMG_ADDR_HANDSHAKE_1, (idx*dataMaxLen), &img_handshake_1[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_handshake_1)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_handshake_1)%dataMaxLen)) );
  840. }
  841. // Handshake 2 image
  842. picUploadStart(Uart1Fd, IMG_ADDR_HANDSHAKE_2, 128, 64);
  843. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_handshake_2)/dataMaxLen;idx++)
  844. {
  845. if((idx < (ARRAY_SIZE(img_handshake_2)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_handshake_2)/dataMaxLen)) && ((ARRAY_SIZE(img_handshake_2)%dataMaxLen)>0)))
  846. picUploadData(Uart1Fd, IMG_ADDR_HANDSHAKE_2, (idx*dataMaxLen), &img_handshake_2[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_handshake_2)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_handshake_2)%dataMaxLen)) );
  847. }
  848. // Maintain image
  849. picUploadStart(Uart1Fd, IMG_ADDR_MAINTIAN, 128, 64);
  850. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_maintain)/dataMaxLen;idx++)
  851. {
  852. if((idx < (ARRAY_SIZE(img_maintain)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_maintain)/dataMaxLen)) && ((ARRAY_SIZE(img_maintain)%dataMaxLen)>0)))
  853. picUploadData(Uart1Fd, IMG_ADDR_MAINTIAN, (idx*dataMaxLen), &img_maintain[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_maintain)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_maintain)%dataMaxLen)) );
  854. }
  855. // Verify image
  856. picUploadStart(Uart1Fd, IMG_ADDR_VERIFY, 128, 64);
  857. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_verify)/dataMaxLen;idx++)
  858. {
  859. if((idx < (ARRAY_SIZE(img_verify)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_verify)/dataMaxLen)) && ((ARRAY_SIZE(img_verify)%dataMaxLen)>0)))
  860. picUploadData(Uart1Fd, IMG_ADDR_VERIFY, (idx*dataMaxLen), &img_verify[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_verify)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_verify)%dataMaxLen)) );
  861. }
  862. // Verify OK image
  863. picUploadStart(Uart1Fd, IMG_ADDR_VERIFYOK, 128, 64);
  864. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_verify_ok)/dataMaxLen;idx++)
  865. {
  866. if((idx < (ARRAY_SIZE(img_verify_ok)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_verify_ok)/dataMaxLen)) && ((ARRAY_SIZE(img_verify_ok)%dataMaxLen)>0)))
  867. picUploadData(Uart1Fd, IMG_ADDR_VERIFYOK, (idx*dataMaxLen), &img_verify_ok[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_verify_ok)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_verify_ok)%dataMaxLen)) );
  868. }
  869. // Verify fail image
  870. picUploadStart(Uart1Fd, IMG_ADDR_VERIFYFAIL, 128, 64);
  871. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_verify_fail)/dataMaxLen;idx++)
  872. {
  873. if((idx < (ARRAY_SIZE(img_verify_fail)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_verify_fail)/dataMaxLen)) && ((ARRAY_SIZE(img_verify_fail)%dataMaxLen)>0)))
  874. picUploadData(Uart1Fd, IMG_ADDR_VERIFYFAIL, (idx*dataMaxLen), &img_verify_fail[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_verify_fail)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_verify_fail)%dataMaxLen)) );
  875. }
  876. // Icon alert image
  877. picUploadStart(Uart1Fd, IMG_ADDR_ICON_ALERT, 16, 16);
  878. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_alert)/dataMaxLen;idx++)
  879. {
  880. if((idx < (ARRAY_SIZE(img_icon_alert)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_alert)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_alert)%dataMaxLen)>0)))
  881. picUploadData(Uart1Fd, IMG_ADDR_ICON_ALERT, (idx*dataMaxLen), &img_icon_alert[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_alert)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_alert)%dataMaxLen)) );
  882. }
  883. // Icon energy image
  884. picUploadStart(Uart1Fd, IMG_ADDR_ICON_ENERGY, 24, 24);
  885. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_energy)/dataMaxLen;idx++)
  886. {
  887. if((idx < (ARRAY_SIZE(img_icon_energy)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_energy)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_energy)%dataMaxLen)>0)))
  888. picUploadData(Uart1Fd, IMG_ADDR_ICON_ENERGY, (idx*dataMaxLen), &img_icon_energy[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_energy)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_energy)%dataMaxLen)) );
  889. }
  890. // Icon energy image
  891. picUploadStart(Uart1Fd, IMG_ADDR_ICON_COST, 24, 24);
  892. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_cost)/dataMaxLen;idx++)
  893. {
  894. if((idx < (ARRAY_SIZE(img_icon_cost)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_cost)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_cost)%dataMaxLen)>0)))
  895. picUploadData(Uart1Fd, IMG_ADDR_ICON_COST, (idx*dataMaxLen), &img_icon_cost[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_cost)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_cost)%dataMaxLen)) );
  896. }
  897. // Icon time image
  898. picUploadStart(Uart1Fd, IMG_ADDR_ICON_TIME, 24, 24);
  899. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_time)/dataMaxLen;idx++)
  900. {
  901. if((idx < (ARRAY_SIZE(img_icon_time)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_time)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_time)%dataMaxLen)>0)))
  902. picUploadData(Uart1Fd, IMG_ADDR_ICON_TIME, (idx*dataMaxLen), &img_icon_time[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_time)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_time)%dataMaxLen)) );
  903. }
  904. // Icon price image
  905. picUploadStart(Uart1Fd, IMG_ADDR_ICON_PRICE, 33, 24);
  906. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_price)/dataMaxLen;idx++)
  907. {
  908. if((idx < (ARRAY_SIZE(img_icon_price)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_price)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_price)%dataMaxLen)>0)))
  909. picUploadData(Uart1Fd, IMG_ADDR_ICON_PRICE, (idx*dataMaxLen), &img_icon_price[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_price)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_price)%dataMaxLen)) );
  910. }
  911. // Icon battery 0% image
  912. picUploadStart(Uart1Fd, IMG_ADDR_ICON_B0, 48, 16);
  913. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_b0)/dataMaxLen;idx++)
  914. {
  915. if((idx < (ARRAY_SIZE(img_icon_b0)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_b0)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_b0)%dataMaxLen)>0)))
  916. picUploadData(Uart1Fd, IMG_ADDR_ICON_B0, (idx*dataMaxLen), &img_icon_b0[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_b0)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_b0)%dataMaxLen)) );
  917. }
  918. // Icon battery 20% image
  919. picUploadStart(Uart1Fd, IMG_ADDR_ICON_B20, 48, 16);
  920. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_b20)/dataMaxLen;idx++)
  921. {
  922. if((idx < (ARRAY_SIZE(img_icon_b20)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_b20)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_b20)%dataMaxLen)>0)))
  923. picUploadData(Uart1Fd, IMG_ADDR_ICON_B20, (idx*dataMaxLen), &img_icon_b20[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_b20)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_b20)%dataMaxLen)) );
  924. }
  925. // Icon battery 40% image
  926. picUploadStart(Uart1Fd, IMG_ADDR_ICON_B40, 48, 16);
  927. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_b40)/dataMaxLen;idx++)
  928. {
  929. if((idx < (ARRAY_SIZE(img_icon_b40)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_b40)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_b40)%dataMaxLen)>0)))
  930. picUploadData(Uart1Fd, IMG_ADDR_ICON_B40, (idx*dataMaxLen), &img_icon_b40[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_b40)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_b40)%dataMaxLen)) );
  931. }
  932. // Icon battery 60% image
  933. picUploadStart(Uart1Fd, IMG_ADDR_ICON_B60, 48, 16);
  934. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_b60)/dataMaxLen;idx++)
  935. {
  936. if((idx < (ARRAY_SIZE(img_icon_b60)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_b60)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_b60)%dataMaxLen)>0)))
  937. picUploadData(Uart1Fd, IMG_ADDR_ICON_B60, (idx*dataMaxLen), &img_icon_b60[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_b60)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_b60)%dataMaxLen)) );
  938. }
  939. // Icon battery 80% image
  940. picUploadStart(Uart1Fd, IMG_ADDR_ICON_B80, 48, 16);
  941. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_b80)/dataMaxLen;idx++)
  942. {
  943. if((idx < (ARRAY_SIZE(img_icon_b80)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_b80)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_b80)%dataMaxLen)>0)))
  944. picUploadData(Uart1Fd, IMG_ADDR_ICON_B80, (idx*dataMaxLen), &img_icon_b80[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_b80)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_b80)%dataMaxLen)) );
  945. }
  946. // Icon battery 100% image
  947. picUploadStart(Uart1Fd, IMG_ADDR_ICON_B100, 48, 16);
  948. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_b100)/dataMaxLen;idx++)
  949. {
  950. if((idx < (ARRAY_SIZE(img_icon_b100)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_b100)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_b100)%dataMaxLen)>0)))
  951. picUploadData(Uart1Fd, IMG_ADDR_ICON_B100, (idx*dataMaxLen), &img_icon_b100[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_b100)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_b100)%dataMaxLen)) );
  952. }
  953. // Icon battery 100% image
  954. picUploadStart(Uart1Fd, IMG_ADDR_ICON_COMPLETE, 48, 18);
  955. for(uint8_t idx=0;idx<=ARRAY_SIZE(img_icon_complete)/dataMaxLen;idx++)
  956. {
  957. if((idx < (ARRAY_SIZE(img_icon_complete)/dataMaxLen)) || ((idx == (ARRAY_SIZE(img_icon_complete)/dataMaxLen)) && ((ARRAY_SIZE(img_icon_complete)%dataMaxLen)>0)))
  958. picUploadData(Uart1Fd, IMG_ADDR_ICON_COMPLETE, (idx*dataMaxLen), &img_icon_complete[idx*dataMaxLen], (idx<(ARRAY_SIZE(img_icon_complete)/dataMaxLen)?dataMaxLen:(ARRAY_SIZE(img_icon_complete)%dataMaxLen)) );
  959. }
  960. return result;
  961. }
  962. //================================================
  963. // Main process
  964. //================================================
  965. int main(void)
  966. {
  967. uint8_t previousMode = 0xff;
  968. uint8_t previousLan = 0xff;
  969. if(InitShareMemory() == FAIL)
  970. {
  971. #ifdef SystemLogMessage
  972. DEBUG_ERROR("InitShareMemory NG\n");
  973. #endif
  974. if(ShmStatusCodeData!=NULL)
  975. {
  976. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  977. }
  978. sleep(5);
  979. return FAIL;
  980. }
  981. Uart1Fd=InitComPort();
  982. if(Uart1Fd<0)
  983. {
  984. #ifdef SystemLogMessage
  985. DEBUG_ERROR("InitComPort NG\n");
  986. #endif
  987. if(ShmStatusCodeData!=NULL)
  988. {
  989. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
  990. }
  991. sleep(5);
  992. return FAIL;
  993. }
  994. else
  995. {
  996. InitLcdModule();
  997. }
  998. DEBUG_INFO("Initial completed\n");
  999. for(;;)
  1000. {
  1001. // Clear LCD if page change.
  1002. if((previousMode != ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus) ||
  1003. (previousLan != ShmSysConfigAndInfo->SysConfig.DefaultLanguage))
  1004. {
  1005. // Clear screen
  1006. clearScreen(Uart1Fd, NO, 0, 0, 128, 64);
  1007. previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
  1008. previousLan = ShmSysConfigAndInfo->SysConfig.DefaultLanguage;
  1009. }
  1010. switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  1011. {
  1012. case SYS_MODE_BOOTING:
  1013. page_booting();
  1014. break;
  1015. case SYS_MODE_IDLE:
  1016. page_idle();
  1017. break;
  1018. case SYS_MODE_AUTHORIZING:
  1019. page_authorizing();
  1020. break;
  1021. case SYS_MODE_PREPARING:
  1022. page_preparing();
  1023. break;
  1024. case SYS_MODE_CHARGING:
  1025. page_charging();
  1026. break;
  1027. case SYS_MODE_TERMINATING:
  1028. page_terminating();
  1029. break;
  1030. case SYS_MODE_COMPLETE:
  1031. page_complete();
  1032. break;
  1033. case SYS_MODE_ALARM:
  1034. page_alarm();
  1035. break;
  1036. case SYS_MODE_FAULT:
  1037. page_fault();
  1038. break;
  1039. case SYS_MODE_MAINTAIN:
  1040. page_maintain();
  1041. break;
  1042. case SYS_MODE_UPDATE:
  1043. page_update();
  1044. break;
  1045. case SYS_MODE_RESERVATION:
  1046. page_reservation();
  1047. break;
  1048. case SYS_MODE_BOOKING:
  1049. page_booking();
  1050. break;
  1051. case SYS_MODE_DEBUG:
  1052. page_debug();
  1053. break;
  1054. default:
  1055. page_unknown();
  1056. break;
  1057. }
  1058. page_header();
  1059. usleep(1000000);
  1060. }
  1061. return FAIL;
  1062. }