Module_LcmControl.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  1. /*
  2. * Module_LcmControl.c
  3. *
  4. * Created on : 2020-10-20
  5. * Update on : 2021-02-20
  6. * Author : Folus Wen, Eason Yang
  7. * Version : D0.01
  8. *
  9. */
  10. #include <sys/time.h>
  11. #include "define.h"
  12. #include "main.h"
  13. #include "lcmComm_dgus.h"
  14. //=======================================
  15. // Declare share memory
  16. //=======================================
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct OCPP16Data *ShmOCPP16Data;
  20. struct OCPP20Data *ShmOCPP20Data;
  21. struct Charger *ShmCharger;
  22. //=======================================
  23. // Declare Basic function
  24. //=======================================
  25. void trim(char *s);
  26. int mystrcmp(char *p1,char *p2);
  27. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  28. uint8_t split(char **arr, char *str, const char *del);
  29. void string2ByteArray(uint8_t *input, uint8_t *output);
  30. //=======================================
  31. // Declare Control panel function
  32. //=======================================
  33. uint8_t getCurrentPage();
  34. void setCurrentPage(uint8_t page);
  35. void setCurrencyFromWebsite(char *unit);
  36. void setWarningStatus(uint8_t gun_index);
  37. void setAuthorizationPage(uint8_t gun_index);
  38. void setPriceFromWebsite(float monry_rate);
  39. void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode);
  40. void setPresentChargedEnergy(uint8_t gun_index);
  41. void setPresentChargingPower(uint8_t gun_index);
  42. void setBatteryPercentageValue(uint8_t gun_index);
  43. void setPresentChargedDuration(uint8_t gun_index);
  44. void setQRcodeContent(char *input, uint8_t length);
  45. void setDisplayValue(uint16_t address, uint8_t value);
  46. void setGunPluginAnimation(uint8_t gun_index);
  47. void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode);
  48. void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode);
  49. void setUserPrice(uint8_t type);
  50. void setDefaultPrice(uint8_t type);
  51. void setFinalCost(uint8_t gun_index, uint8_t type);
  52. void setCurrencyAndUnitFromBackend(uint8_t type_price,uint8_t type_currency_unit, uint8_t gun_index);
  53. void setRTC();
  54. void setRfidIcon();
  55. void setWifi4GIcon();
  56. void setQRCodeIcon();
  57. void setBackendIcon();
  58. void setEthernetIcon();
  59. void setAlarmCodeAndIcon();
  60. void setBillingFromWebsite();
  61. //=======================================
  62. // Declare Timer
  63. //=======================================
  64. #define TMR_IDX_BATTERY 0
  65. #define TMR_IDX_CONNECTION 1
  66. #define TMR_IDX_PLUGIN 2
  67. #define TMR_IDX_ALARM 3
  68. #define TMR_IDX_PRICE 4
  69. #define TMR_IDX_EMULATOR 5
  70. #define TMR_IDX_6 6
  71. #define TMR_IDX_7 7
  72. #define TMR_IDX_8 8
  73. #define TMR_IDX_9 9
  74. struct timeb startTime[AC_QUANTITY][10];
  75. #define TIME_ANIMATION_PLUGIN 1000
  76. #define TIME_ANIMATION_BATTERY 1000
  77. #define TIME_ANIMATION_CONNECTION 1000
  78. #define TIME_ANIMATION_ALARM 5000
  79. #define TIME_REFRESH_TIME 2000
  80. //=======================================
  81. // Declare Variable
  82. //=======================================
  83. uint8_t BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  84. uint8_t CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  85. uint8_t GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  86. uint8_t WarningCount = 255;
  87. int Uart1Fd;
  88. //=======================================
  89. // Emulator
  90. //=======================================
  91. int PERCENTAGE;
  92. uint8_t isChange;
  93. uint8_t isEmulator = NO;
  94. uint8_t isCharging = YES;
  95. //=======================================
  96. // Record version and date
  97. //=======================================
  98. char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.16", "2021-03-26", "REV.01.00"};
  99. //=======================================
  100. // Common routine
  101. //=======================================
  102. int StoreLogMsg(const char *fmt, ...)
  103. {
  104. char Buf[4096+256];
  105. char buffer[4096];
  106. time_t CurrentTime;
  107. struct tm *tm;
  108. struct timeval tv;
  109. va_list args;
  110. va_start(args, fmt);
  111. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  112. va_end(args);
  113. memset(Buf,0,sizeof(Buf));
  114. CurrentTime = time(NULL);
  115. tm=localtime(&CurrentTime);
  116. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  117. sprintf(Buf,"echo -n \'[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\' >> /Storage/SystemLog/[%04d.%02d]Module_LcmControlLog",
  118. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  119. buffer,
  120. tm->tm_year+1900,tm->tm_mon+1);
  121. #ifdef SystemLogMessage
  122. system(Buf);
  123. #endif
  124. #ifdef ConsloePrintLog
  125. 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);
  126. #endif
  127. return rc;
  128. }
  129. long long DiffTimebWithNow(struct timeb ST)
  130. {
  131. //return milli-second
  132. struct timeb ET;
  133. long long StartTime,StopTime;
  134. ftime(&ET);
  135. StartTime=(long long)ST.time;
  136. StopTime=(long long)ET.time;
  137. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  138. }
  139. int DiffTimeb(struct timeb ST, struct timeb ET)
  140. {
  141. //return milli-second
  142. unsigned int StartTime,StopTime;
  143. StartTime=(unsigned int)ST.time;
  144. StopTime=(unsigned int)ET.time;
  145. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  146. }
  147. void trim(char *s)
  148. {
  149. int i=0, j, k, l=0;
  150. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  151. i++;
  152. j = strlen(s)-1;
  153. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  154. j--;
  155. if(i==0 && j==strlen(s)-1) { }
  156. else if(i==0) s[j+1] = '\0';
  157. else {
  158. for(k=i; k<=j; k++) s[l++] = s[k];
  159. s[l] = '\0';
  160. }
  161. }
  162. void trim_string(char *s, unsigned char len)
  163. {
  164. for(unsigned char i = 0 ; i < len; i++)
  165. {
  166. if (!(s[i] =='.')&& !((s[i]>='0') && (s[i]<='9')))
  167. {
  168. s[i] = s[i + 1];
  169. strncpy(s + i, s + i + 1, len);
  170. i -= 1;
  171. len -= 1;
  172. }
  173. }
  174. s[len + 1] = '\0';
  175. }
  176. int mystrcmp(char *p1,char *p2)
  177. {
  178. while(*p1==*p2)
  179. {
  180. if(*p1=='\0' || *p2=='\0')
  181. break;
  182. p1++;
  183. p2++;
  184. }
  185. if(*p1=='\0' && *p2=='\0')
  186. return(PASS);
  187. else
  188. return(FAIL);
  189. }
  190. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  191. {
  192. strncpy(dest, src + start, cnt);
  193. dest[cnt] = 0;
  194. }
  195. uint8_t split(char **arr, char *str, const char *del)
  196. {
  197. uint8_t result = 0;
  198. char *s = strtok(str, del);
  199. while(s != NULL)
  200. {
  201. *arr++ = s;
  202. result += 1;
  203. s = strtok(NULL, del);
  204. }
  205. return result;
  206. }
  207. void getDateTimeString(char* result)
  208. {
  209. time_t CurrentTime;
  210. struct tm *tm;
  211. CurrentTime = time(NULL);
  212. tm=localtime(&CurrentTime);
  213. sprintf(result, "%04d/%02d/%02d %02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
  214. }
  215. //=======================================
  216. // Function to page routine
  217. //=======================================
  218. void page_booting()
  219. {
  220. if(getCurrentPage() != SYSTEM_SCREEN_BOOTING)
  221. {
  222. setCurrentPage(SYSTEM_SCREEN_BOOTING);
  223. DEBUG_INFO("Setting page to booting.\n");
  224. }
  225. else
  226. {
  227. //DEBUG_INFO("Page booting.\n");
  228. }
  229. }
  230. void page_idle(uint8_t gun_index, uint8_t system_mode)
  231. {
  232. if(getCurrentPage() != SYSTEM_SCREEN_IDLE)
  233. {
  234. setCurrentPage(SYSTEM_SCREEN_IDLE);
  235. setBatteryAnimation(gun_index, system_mode);
  236. //DEBUG_INFO("Setting page to idle.\n");
  237. }
  238. else
  239. {
  240. setRfidIcon();
  241. setQRCodeIcon();
  242. //if(isCharging == YES)
  243. //PERCENTAGE = 0;
  244. //else
  245. //PERCENTAGE = 100;
  246. //DEBUG_INFO("Page idle.\n");
  247. }
  248. }
  249. void page_authorizing(uint8_t gun_index)
  250. {
  251. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  252. {
  253. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  254. {
  255. if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
  256. ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
  257. {
  258. // Searching User price for account balance
  259. setUserPrice(ACCOUNT_BALANCE);
  260. }
  261. else
  262. {
  263. // Disappear account balance and icon
  264. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  265. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  266. }
  267. }
  268. else
  269. {
  270. // Display by OCPP 2.0.1
  271. }
  272. }
  273. else
  274. {
  275. // Disappear account balance and icon
  276. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  277. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  278. }
  279. setAuthorizationPage(gun_index);
  280. }
  281. void page_preparing(uint8_t gun_index, uint8_t system_mode)
  282. {
  283. // Check handshaking mode BS / HLC
  284. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
  285. {
  286. if((getCurrentPage() != SYSTEM_SCREEN_PREPARING))
  287. {
  288. setCurrentPage(SYSTEM_SCREEN_PREPARING);
  289. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
  290. ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
  291. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  292. DEBUG_INFO("Setting page to preparing.\n");
  293. }
  294. else
  295. {
  296. setGunPluginAnimation(gun_index);
  297. //DEBUG_INFO("Page preparing.\n");
  298. }
  299. }
  300. else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  301. {
  302. if((getCurrentPage() != SYSTEM_SCREEN_PREPARE_FOR_EVSE))
  303. {
  304. setCurrentPage(SYSTEM_SCREEN_PREPARE_FOR_EVSE);
  305. setDisplayValue(ICON_BATTERY_PRECHARGING, BATTERY_CAPACITY_EMPTY);
  306. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
  307. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  308. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  309. DEBUG_INFO("Setting page to prepare for EVSE.\n");
  310. }
  311. else
  312. {
  313. setConnectionAnimation(gun_index, system_mode);
  314. //DEBUG_INFO("Page preparing.\n");
  315. }
  316. }
  317. }
  318. void page_charging(uint8_t gun_index, uint8_t system_mode)
  319. {
  320. if((getCurrentPage() != SYSTEM_SCREEN_CHARGING) && (ShmCharger->gun_info[gun_index].resultAuthorization == DEFAULT_RFID))
  321. {
  322. setCurrentPage(SYSTEM_SCREEN_CHARGING);
  323. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
  324. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  325. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  326. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  327. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  328. DEBUG_INFO("Setting page to charging.\n");
  329. //isChange = 0;
  330. //ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
  331. }
  332. else
  333. {
  334. setConnectionAnimation(gun_index, system_mode);
  335. setBatteryAnimation(gun_index, system_mode);
  336. setPresentChargedDuration(gun_index);
  337. setPresentChargedEnergy(gun_index);
  338. setPresentChargingPower(gun_index);
  339. setAuthorizationPage(gun_index);
  340. //DEBUG_INFO("Page charging.\n");
  341. }
  342. }
  343. void page_complete(uint8_t gun_index, uint8_t system_mode)
  344. {
  345. if(getCurrentPage() != SYSTEM_SCREEN_COMPLETE)
  346. {
  347. setCurrentPage(SYSTEM_SCREEN_COMPLETE);
  348. DEBUG_INFO("Setting page to complete.\n");
  349. }
  350. else
  351. {
  352. setPresentChargedDuration(gun_index);
  353. setPresentChargedEnergy(gun_index);
  354. setBatteryAnimation(gun_index, system_mode);
  355. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  356. {
  357. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  358. {
  359. setFinalCost(gun_index, TOTAL_COST);
  360. setFinalCost(gun_index, ACCOUNT_BALANCE);
  361. setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
  362. }
  363. else
  364. {
  365. // Display by OCPP 2.0.1
  366. }
  367. }
  368. else
  369. {
  370. // Disappear account balance and icon
  371. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  372. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  373. // Disappear cost and icon
  374. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  375. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  376. // Disappear balance currency unit
  377. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  378. }
  379. //DEBUG_INFO("Page complete.\n");
  380. }
  381. }
  382. void page_terminating(uint8_t gun_index, uint8_t system_mode)
  383. {
  384. if((getCurrentPage() != SYSTEM_SCREEN_TERMINATING) && (ShmCharger->gun_info[gun_index].resultAuthorization == DEFAULT_RFID))
  385. {
  386. setCurrentPage(SYSTEM_SCREEN_TERMINATING);
  387. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  388. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  389. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  390. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  391. DEBUG_INFO("Setting page to terminating.\n");
  392. }
  393. else
  394. {
  395. setConnectionAnimation(gun_index, system_mode);
  396. setBatteryAnimation(gun_index, system_mode);
  397. setPresentChargedDuration(gun_index);
  398. setPresentChargedEnergy(gun_index);
  399. setPresentChargingPower(gun_index);
  400. setAuthorizationPage(gun_index);
  401. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  402. {
  403. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  404. {
  405. setFinalCost(gun_index, TOTAL_COST);
  406. setFinalCost(gun_index, ACCOUNT_BALANCE);
  407. setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
  408. }
  409. else
  410. {
  411. // Display by OCPP 2.0.1
  412. }
  413. }
  414. else
  415. {
  416. // Disappear account balance and icon
  417. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  418. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  419. // Disappear cost and icon
  420. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  421. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  422. // Disappear balance currency unit
  423. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  424. }
  425. //DEBUG_INFO("Page terminating.\n");
  426. }
  427. }
  428. void page_alarm()
  429. {
  430. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip != ON)
  431. {
  432. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  433. {
  434. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  435. DEBUG_INFO("Setting page to repair man.\n");
  436. }
  437. else
  438. {}
  439. }
  440. else
  441. {
  442. if(getCurrentPage() != SYSTEM_SCREEN_EMERGENCY)
  443. {
  444. setCurrentPage(SYSTEM_SCREEN_EMERGENCY);
  445. DEBUG_INFO("Setting page to emergency.\n");
  446. }
  447. else
  448. {}
  449. }
  450. }
  451. void page_fault()
  452. {
  453. DEBUG_INFO("Page fault.\n");
  454. }
  455. void page_maintain()
  456. {
  457. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  458. {
  459. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  460. DEBUG_INFO("Setting page to maintain.\n");
  461. }
  462. else
  463. {
  464. //DEBUG_INFO("Page maintain.\n");
  465. }
  466. }
  467. void page_update()
  468. {
  469. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  470. {
  471. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  472. DEBUG_INFO("Setting page to update.\n");
  473. }
  474. else
  475. {
  476. //DEBUG_INFO("Page update.\n");
  477. }
  478. }
  479. void page_reservation()
  480. {
  481. DEBUG_INFO("Page reservation.\n");
  482. }
  483. void page_booking()
  484. {
  485. DEBUG_INFO("Page booking.\n");
  486. }
  487. void page_debug()
  488. {
  489. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  490. {
  491. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  492. DEBUG_INFO("Setting page to debug.\n");
  493. }
  494. else
  495. {
  496. //DEBUG_INFO("Page debug.\n");
  497. }
  498. }
  499. void page_unknown()
  500. {
  501. DEBUG_INFO("Page unknown.\n");
  502. }
  503. void page_header(uint8_t gun_index, uint8_t system_mode)
  504. {
  505. setEthernetIcon();
  506. setBackendIcon();
  507. setWifi4GIcon();
  508. setRTC();
  509. setWarningStatus(gun_index);
  510. // Set LCM to save energy mode
  511. if((ShmCharger->isLcdOn == ON))
  512. setDisplayValue(REG_ADDRESS_WRITE_BRIGHTNESS,BRIGHTNESS_100);
  513. else
  514. setDisplayValue(REG_ADDRESS_WRITE_BRIGHTNESS,BRIGHTNESS_10);
  515. // Set billing
  516. if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
  517. {
  518. setBillingFromWebsite();
  519. }
  520. else
  521. {
  522. if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PRICE]) > (TIME_REFRESH_TIME))
  523. {
  524. ftime(&startTime[gun_index][TMR_IDX_PRICE]);
  525. setBillingFromBackend(gun_index, system_mode);
  526. }
  527. }
  528. //DEBUG_INFO("Page heading.\n");
  529. }
  530. //=======================================
  531. // Setting icon display value
  532. //=======================================
  533. void setDisplayValue(uint16_t address, uint8_t value)
  534. {
  535. uint8_t data[2];
  536. data[0] = value >> 8;
  537. data[1] = value & 0X00FF;
  538. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, address, data, ARRAY_SIZE(data));
  539. }
  540. //=======================================
  541. // Getting current page
  542. //=======================================
  543. uint8_t getCurrentPage()
  544. {
  545. uint8_t currentPage[2];
  546. uint8_t result = 255;
  547. if(lcdRegisterRead(Uart1Fd, REG_TYPE_CONTROL, REG_ADDRESS_READ_PAGE_ID, currentPage, ARRAY_SIZE(currentPage)))
  548. {
  549. result = currentPage[1];
  550. // DEBUG_INFO("currentPage[0] : %X\n", currentPage[0]);
  551. // DEBUG_INFO("currentPage[1] : %X\n", currentPage[1]);
  552. // DEBUG_INFO("getCurrentPage : %d \n", result);
  553. }
  554. else
  555. {
  556. DEBUG_INFO("Get current page fail! \n");
  557. }
  558. return result;
  559. }
  560. //=======================================
  561. // Setting current page
  562. //=======================================
  563. void setCurrentPage(uint8_t page)
  564. {
  565. uint8_t settingPage[2] = {0x00, page};
  566. if(lcdRegisterWrite(Uart1Fd, REG_TYPE_CONTROL, REG_ADDRESS_SET_PAGE_ID, settingPage, ARRAY_SIZE(settingPage)))
  567. DEBUG_INFO("setCurrentPage : %d \n", page);
  568. else
  569. DEBUG_INFO("Setting current page fail! \n");
  570. }
  571. //=======================================
  572. // Convert string to byte array
  573. //=======================================
  574. void string2ByteArray(unsigned char *input, uint8_t *output)
  575. {
  576. int loop;
  577. int i;
  578. loop = 0;
  579. i = 0;
  580. while(input[loop] != '\0')
  581. {
  582. output[i++] = input[loop++];
  583. }
  584. output[loop] = '\0';
  585. }
  586. //=======================================
  587. // Setting ETHERNET icon status
  588. //=======================================
  589. void setEthernetIcon()
  590. {
  591. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet == ON)
  592. setDisplayValue(ICON_ETHERENT_CONNECTION, ETHERENT_OFFLINE);
  593. else
  594. setDisplayValue(ICON_ETHERENT_CONNECTION, EHTERNET_ONLINE);
  595. }
  596. //=======================================
  597. // Setting BACKEND icon status
  598. //=======================================
  599. void setBackendIcon()
  600. {
  601. if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus != ON)
  602. setDisplayValue(ICON_BACKEND_CONNECTION,BACKEND_OFFLINE);
  603. else
  604. setDisplayValue(ICON_BACKEND_CONNECTION,BACKEND_ONLINE);
  605. }
  606. //=======================================
  607. // Setting WIFI / 4G icon status
  608. //=======================================
  609. void setWifi4GIcon()
  610. {
  611. //==============================================
  612. // Setting WIFI + 4G icon status online / off-line
  613. //==============================================
  614. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
  615. {
  616. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == DISABLE_WIFI)
  617. {
  618. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G)
  619. {
  620. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  621. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  622. }
  623. else
  624. {
  625. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  626. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  627. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
  628. else
  629. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
  630. }
  631. }
  632. else
  633. {
  634. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == WIFI_STATION)
  635. {
  636. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
  637. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  638. else
  639. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
  640. }
  641. else
  642. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  643. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G)
  644. {
  645. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  646. }
  647. else
  648. {
  649. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  650. setDisplayValue(ICON_4G_CONNECTION, TELECOM_OFFLINE);
  651. else
  652. setDisplayValue(ICON_4G_CONNECTION, TELECOM_ONLINE);
  653. }
  654. }
  655. }
  656. else
  657. {
  658. //========================================
  659. // Setting 4G icon status online / off-line
  660. //========================================
  661. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
  662. {
  663. switch(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled)
  664. {
  665. case DISABLE_4G:
  666. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  667. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  668. break;
  669. case ENABLE_4G:
  670. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  671. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
  672. else
  673. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
  674. break;
  675. default:
  676. break;
  677. }
  678. }
  679. //========================================
  680. // Setting WIFI icon status online / off-line
  681. //========================================
  682. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
  683. {
  684. switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
  685. {
  686. case DISABLE_WIFI:
  687. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  688. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  689. break;
  690. case WIFI_STATION:
  691. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
  692. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  693. else
  694. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
  695. break;
  696. case WIFI_ACCESS_POINT:
  697. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  698. break;
  699. default:
  700. break;
  701. }
  702. }
  703. }
  704. }
  705. //=======================================
  706. // Setting billing (Web page)
  707. //=======================================
  708. void setBillingFromWebsite()
  709. {
  710. if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
  711. {
  712. setDisplayValue(ICON_PRICE, APPEAR);
  713. struct timeb csuTime;
  714. struct tm *tmCSU;
  715. ftime(&csuTime);
  716. tmCSU = localtime(&csuTime.time);
  717. if(tmCSU->tm_hour <= 23)
  718. {
  719. ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
  720. setPriceFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
  721. }
  722. // Currency unit 53 countries
  723. if(ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
  724. {
  725. setCurrencyFromWebsite((char *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
  726. }
  727. }
  728. else
  729. {
  730. setDisplayValue(ICON_PRICE, DISAPPEAR);
  731. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  732. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  733. }
  734. }
  735. //=======================================
  736. // Setting currency (Web page)
  737. //=======================================
  738. void setCurrencyFromWebsite(char *unit)
  739. {
  740. uint8_t data[16];
  741. uint8_t currency[16];
  742. memset(data, 0x00, ARRAY_SIZE(data));
  743. memset(currency, 0x00, ARRAY_SIZE(currency));
  744. *(unit + 3) = '\0';
  745. sprintf((char *) currency, "%s", unit);
  746. string2ByteArray(currency, data);
  747. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, data, ARRAY_SIZE(data));
  748. }
  749. //=======================================
  750. // Setting price (Web page)
  751. //=======================================
  752. void setPriceFromWebsite(float monry_rate)
  753. {
  754. uint8_t data[16];
  755. uint8_t price[16];
  756. memset(data, 0x00, ARRAY_SIZE(data));
  757. memset(price, 0x00, ARRAY_SIZE(price));
  758. sprintf((char *)price, "%.2f", monry_rate);
  759. string2ByteArray(price, data);
  760. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, data, ARRAY_SIZE(data));
  761. }
  762. //=======================================
  763. // Setting billing (Backend)
  764. //=======================================
  765. void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
  766. {
  767. if((system("pidof -s OcppBackend > /dev/null") != 0))
  768. {
  769. // Price, currency and icon disappear
  770. setDisplayValue(ICON_PRICE, DISAPPEAR);
  771. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  772. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  773. }
  774. else
  775. {
  776. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  777. {
  778. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  779. {
  780. if((strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData,"") != 0))
  781. {
  782. if(system_mode == SYS_MODE_IDLE)
  783. {
  784. // Searching defaultPrice for price
  785. setDefaultPrice(CURRENT_RATE);
  786. // Searching DefaultPrice for Currency and unit appear
  787. setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
  788. }
  789. else
  790. {
  791. // If startUserId is not match with idToken and it can not be null, otherwise the system should use default price
  792. if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
  793. ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
  794. {
  795. // Searching UserPrice for price
  796. setUserPrice(CURRENT_RATE);
  797. // Searching UserPrice for Currency and unit appear
  798. setCurrencyAndUnitFromBackend(SET_USER_PRICE, CURRENT_RATE,gun_index);
  799. }
  800. else
  801. {
  802. // Searching defaultPrice for price
  803. setDefaultPrice(CURRENT_RATE);
  804. // Searching DefaultPrice for Currency and unit appear
  805. setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
  806. }
  807. }
  808. }
  809. else
  810. {
  811. // Price, currency and icon disappear
  812. setDisplayValue(ICON_PRICE, DISAPPEAR);
  813. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  814. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  815. }
  816. }
  817. else
  818. {
  819. // Display default price by OCPP 2.0.1
  820. }
  821. }
  822. else
  823. {
  824. // Price, currency and icon disappear
  825. setDisplayValue(ICON_PRICE, DISAPPEAR);
  826. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  827. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  828. }
  829. }
  830. }
  831. //=======================================
  832. // Setting UserPrice (Backend)
  833. //=======================================
  834. void setUserPrice(uint8_t type)
  835. {
  836. uint8_t length;
  837. uint8_t Split_String_Count;
  838. uint8_t output_data[32];
  839. char input_data[32];
  840. char tmp[256];
  841. char *splitString[10];
  842. const char *Symbol = ";";
  843. memset(tmp, 0, ARRAY_SIZE(tmp));
  844. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  845. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  846. switch(type)
  847. {
  848. case CONNECTION_FEE:
  849. break;
  850. case CURRENT_RATE:
  851. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
  852. {
  853. // Appear price icon
  854. setDisplayValue(ICON_PRICE, APPEAR);
  855. // Appear price text
  856. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  857. Split_String_Count = split((char**)splitString, tmp, Symbol);
  858. memcpy(input_data, splitString[1], strlen(splitString[1]));
  859. length = strlen(input_data);
  860. trim_string(input_data,length);
  861. memcpy(output_data ,input_data, strlen(input_data));
  862. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
  863. }
  864. else
  865. {
  866. // Disappear price text and price icon
  867. setDisplayValue(ICON_PRICE, DISAPPEAR);
  868. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  869. }
  870. break;
  871. case OCCUPANCY_FEE:
  872. break;
  873. case ACCOUNT_BALANCE:
  874. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Account Balance:") > 0)
  875. {
  876. // Appear account balance icon
  877. setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
  878. // Appear account balance text
  879. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  880. Split_String_Count = split((char**)splitString, tmp, Symbol);
  881. memcpy(input_data, splitString[3], strlen(splitString[3]));
  882. length = strlen(input_data);
  883. trim_string(input_data,length);
  884. memcpy(output_data ,input_data, strlen(input_data));
  885. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
  886. }
  887. else
  888. {
  889. // Disappear balance text and balance icon
  890. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  891. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  892. }
  893. break;
  894. default:
  895. break;
  896. }
  897. }
  898. //=======================================
  899. // Setting DefaultPrice (Backend)
  900. //=======================================
  901. void setDefaultPrice(uint8_t type)
  902. {
  903. uint8_t length;
  904. uint8_t Split_String_Count;
  905. uint8_t output_data[32];
  906. char input_data[32];
  907. char tmp[256];
  908. char *splitString[10];
  909. const char *Symbol = ";";
  910. memset(tmp, 0, ARRAY_SIZE(tmp));
  911. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  912. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  913. switch(type)
  914. {
  915. case CONNECTION_FEE:
  916. break;
  917. case CURRENT_RATE:
  918. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
  919. {
  920. // Appear price icon
  921. setDisplayValue(ICON_PRICE, APPEAR);
  922. // Appear price text
  923. strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  924. Split_String_Count = split((char**)splitString, tmp, Symbol);
  925. memcpy(input_data, splitString[1], strlen(splitString[1]));
  926. length = strlen(input_data);
  927. trim_string(input_data,length);
  928. memcpy(output_data ,input_data, strlen(input_data));
  929. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
  930. }
  931. else
  932. {
  933. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  934. setDisplayValue(ICON_PRICE, DISAPPEAR);
  935. }
  936. break;
  937. case OCCUPANCY_FEE:
  938. break;
  939. default:
  940. break;
  941. }
  942. }
  943. //=======================================
  944. // Setting FinalCost (Backend)
  945. //=======================================
  946. void setFinalCost(uint8_t gun_index, uint8_t type)
  947. {
  948. uint8_t length;
  949. uint8_t Split_String_Count;
  950. uint8_t output_data[32];
  951. char input_data[32];
  952. char tmp[256];
  953. char *splitString[10];
  954. const char *Symbol = ";";
  955. memset(tmp, 0, ARRAY_SIZE(tmp));
  956. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  957. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  958. switch(type)
  959. {
  960. case CONNECTION_FEE:
  961. break;
  962. case SESSION_FEE:
  963. break;
  964. case OCCUPANCY_FEE:
  965. break;
  966. case TOTAL_COST:
  967. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Total Cost:") > 0))
  968. {
  969. // Appear cost icon
  970. setDisplayValue(ICON_COST_COMPLETE, APPEAR);
  971. // Appear cost test
  972. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  973. Split_String_Count = split((char**)splitString, tmp, Symbol);
  974. memcpy(input_data, splitString[3], strlen(splitString[3]));
  975. length = strlen(input_data);
  976. trim_string(input_data,length);
  977. memcpy(output_data ,input_data, strlen(input_data));
  978. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, output_data, ARRAY_SIZE(output_data));
  979. }
  980. else
  981. {
  982. // Disappear cost icon and text
  983. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  984. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  985. }
  986. break;
  987. case ACCOUNT_BALANCE:
  988. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
  989. {
  990. // Appear balance icon
  991. setDisplayValue(ICON_WALLER_COMPLETE, APPEAR);
  992. setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
  993. // Appear balance test
  994. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  995. Split_String_Count = split((char**)splitString, tmp, Symbol);
  996. memcpy(input_data, splitString[4], strlen(splitString[4]));
  997. length = strlen(input_data);
  998. trim_string(input_data,length);
  999. memcpy(output_data ,input_data, strlen(input_data));
  1000. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ACCOUNT_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1001. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
  1002. }
  1003. else
  1004. {
  1005. // Disappear account balance and icon on complete
  1006. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  1007. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  1008. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  1009. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  1010. }
  1011. break;
  1012. default:
  1013. break;
  1014. }
  1015. }
  1016. //=======================================
  1017. // Setting currency (Backend)
  1018. //=======================================
  1019. void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_unit,uint8_t gun_index)
  1020. {
  1021. uint8_t length;
  1022. uint8_t Split_String_Count;
  1023. uint8_t output_data[32];
  1024. char input_data[32];
  1025. char tmp[256];
  1026. char *splitString[10];
  1027. const char *Symbol = ";";
  1028. memset(tmp, 0, ARRAY_SIZE(tmp));
  1029. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  1030. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  1031. if(type_price == DEFAULE_PRICE)
  1032. {
  1033. switch(type_currency_unit)
  1034. {
  1035. case CONNECTION_FEE:
  1036. break;
  1037. case CURRENT_RATE:
  1038. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
  1039. {
  1040. strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  1041. Split_String_Count = split((char**)splitString, tmp, Symbol);
  1042. memcpy(input_data, splitString[1], strlen(splitString[1]));
  1043. length = strlen(input_data);
  1044. memcpy(output_data , input_data+(length-7), 7);
  1045. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
  1046. }
  1047. else
  1048. {
  1049. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  1050. }
  1051. break;
  1052. case OCCUPANCY_FEE:
  1053. break;
  1054. default:
  1055. break;
  1056. }
  1057. }
  1058. else if(type_price == SET_USER_PRICE)
  1059. {
  1060. switch(type_currency_unit)
  1061. {
  1062. case CONNECTION_FEE:
  1063. break;
  1064. case CURRENT_RATE:
  1065. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
  1066. {
  1067. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  1068. Split_String_Count = split((char**)splitString, tmp, Symbol);
  1069. memcpy(input_data, splitString[1], strlen(splitString[1]));
  1070. length = strlen(input_data);
  1071. memcpy(output_data , input_data+(length-7), 7);
  1072. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
  1073. }
  1074. else
  1075. {
  1076. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  1077. }
  1078. break;
  1079. case OCCUPANCY_FEE:
  1080. break;
  1081. case ACCOUNT_BALANCE:
  1082. break;
  1083. default:
  1084. break;
  1085. }
  1086. }
  1087. else if(type_price == FINAL_COST)
  1088. {
  1089. switch(type_currency_unit)
  1090. {
  1091. case CONNECTION_FEE:
  1092. break;
  1093. case SESSION_FEE:
  1094. break;
  1095. case OCCUPANCY_FEE:
  1096. break;
  1097. case TOTAL_COST:
  1098. break;
  1099. case ACCOUNT_BALANCE:
  1100. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
  1101. {
  1102. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  1103. Split_String_Count = split((char**)splitString, tmp, Symbol);
  1104. memcpy(input_data, splitString[4], strlen(splitString[4]));
  1105. length = strlen(input_data);
  1106. memcpy(output_data , input_data+(length-3), 3);
  1107. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1108. }
  1109. else
  1110. {
  1111. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  1112. }
  1113. break;
  1114. default:
  1115. break;
  1116. }
  1117. }
  1118. else
  1119. {}
  1120. }
  1121. //=======================================
  1122. // Setting RTC value
  1123. //=======================================
  1124. void setRTC()
  1125. {
  1126. uint8_t data[32];
  1127. uint8_t rtc[32];
  1128. memset(data, 0x00, ARRAY_SIZE(data));
  1129. memset(rtc, 0x00, ARRAY_SIZE(rtc));
  1130. getDateTimeString((char*)rtc);
  1131. string2ByteArray(rtc, data);
  1132. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_RTC, data, ARRAY_SIZE(data));
  1133. }
  1134. //=======================================
  1135. // Setting RFID icon status
  1136. //=======================================
  1137. void setRfidIcon()
  1138. {
  1139. //=======================================
  1140. // AX-Series Generation 1
  1141. //=======================================
  1142. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1143. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
  1144. (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '1'))
  1145. {
  1146. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1147. setDisplayValue(ICON_RFID, RFID_ENABLE);
  1148. else
  1149. setDisplayValue(ICON_RFID, RFID_DISABLE);
  1150. }
  1151. //=======================================
  1152. // AX-Series Generation 2/3/4
  1153. //=======================================
  1154. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1155. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
  1156. ((ShmSysConfigAndInfo->SysConfig.ModelName[11] == '2') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '3') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '4')))
  1157. {
  1158. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1159. setDisplayValue(ICON_RFID, VISA_ENABLE);
  1160. else
  1161. setDisplayValue(ICON_RFID, VISA_DISABLE);
  1162. }
  1163. //=======================================
  1164. // AW-Series Generation
  1165. //=======================================
  1166. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1167. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'w'))
  1168. {
  1169. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1170. setDisplayValue(ICON_RFID, RFID_ENABLE);
  1171. else
  1172. setDisplayValue(ICON_RFID, RFID_DISABLE);
  1173. }
  1174. }
  1175. //=======================================
  1176. // Setting QRCODE icon status
  1177. //=======================================
  1178. void setQRCodeIcon()
  1179. {
  1180. uint8_t length = 0;
  1181. // QR code enable / disable
  1182. if(ShmSysConfigAndInfo->SysConfig.isQRCode == ON)
  1183. {
  1184. setDisplayValue(ICON_QRCODE,QRCODE_ENABLE);
  1185. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
  1186. {
  1187. length = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  1188. setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.SystemId, length);
  1189. }
  1190. else
  1191. {
  1192. length = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  1193. setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, length);
  1194. }
  1195. }
  1196. else
  1197. {
  1198. setDisplayValue(TEXT_QRCODE_CONTENT, DISAPPEAR);
  1199. setDisplayValue(ICON_QRCODE,QRCODE_DISABLE);
  1200. }
  1201. }
  1202. //=======================================
  1203. // Setting QR code content
  1204. //=======================================
  1205. void setQRcodeContent(char *input, uint8_t length)
  1206. {
  1207. uint8_t output[length];
  1208. int loop = 0;
  1209. input[length] = '\0';
  1210. output[length] = '\0';
  1211. while(input[loop] != '\0')
  1212. {
  1213. output[loop] = input[loop];
  1214. loop++;
  1215. }
  1216. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
  1217. }
  1218. //=======================================
  1219. // Setting warning page switch
  1220. //=======================================
  1221. void setWarningStatus(uint8_t gun_index)
  1222. {
  1223. if(WarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
  1224. {
  1225. WarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
  1226. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1227. setAlarmCodeAndIcon();
  1228. }
  1229. else if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 4 && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_ALARM]) > (TIME_ANIMATION_ALARM)))
  1230. {
  1231. ftime(&startTime[gun_index][TMR_IDX_ALARM]);
  1232. if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
  1233. {
  1234. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
  1235. }
  1236. else
  1237. {
  1238. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1239. }
  1240. setAlarmCodeAndIcon();
  1241. }
  1242. }
  1243. //=======================================
  1244. // Setting alarm code and icon status
  1245. //=======================================
  1246. void setAlarmCodeAndIcon()
  1247. {
  1248. uint8_t cmd[7];
  1249. uint8_t index = 0;
  1250. for(index = 0; (index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; index++)
  1251. {
  1252. memset(cmd, 0x00, sizeof(cmd));
  1253. if(index >= 4)
  1254. {
  1255. break;
  1256. }
  1257. // Alarm code
  1258. string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4][0], cmd);
  1259. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
  1260. // Icon status
  1261. memset(cmd, 0x00, sizeof(cmd));
  1262. cmd[0] = 0x00;
  1263. cmd[1] = 0x01;
  1264. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
  1265. }
  1266. memset(cmd, 0x00, sizeof(cmd));
  1267. for(; index < 4; index++)
  1268. {
  1269. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
  1270. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
  1271. }
  1272. }
  1273. //=======================================
  1274. // Setting Battery icon animation
  1275. //=======================================
  1276. void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode)
  1277. {
  1278. switch(system_mode)
  1279. {
  1280. case SYS_MODE_IDLE:
  1281. // Setting battery icon to initial status
  1282. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1283. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_EMPTY);
  1284. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1285. break;
  1286. case SYS_MODE_CHARGING:
  1287. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
  1288. {
  1289. // Set battery percentage text to disappear
  1290. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1291. // Set battery animation
  1292. if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
  1293. {
  1294. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1295. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_0;
  1296. }
  1297. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
  1298. {
  1299. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1300. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_1;
  1301. }
  1302. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
  1303. {
  1304. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1305. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_2;
  1306. }
  1307. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_2) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*3)))
  1308. {
  1309. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1310. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_3;
  1311. }
  1312. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_3) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*4)))
  1313. {
  1314. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1315. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_4;
  1316. }
  1317. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_4) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*5)))
  1318. {
  1319. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1320. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1321. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1322. }
  1323. }
  1324. else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1325. {
  1326. if(isEmulator == YES)
  1327. {
  1328. if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_EMULATOR]) > 3000))
  1329. {
  1330. if(isCharging == YES)
  1331. PERCENTAGE++;
  1332. else
  1333. PERCENTAGE--;
  1334. ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
  1335. }
  1336. if(isCharging == YES)
  1337. {
  1338. if(PERCENTAGE > 100)
  1339. PERCENTAGE = 0;
  1340. }
  1341. else
  1342. {
  1343. if(PERCENTAGE <= 0)
  1344. PERCENTAGE = 100;
  1345. }
  1346. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc = PERCENTAGE;
  1347. if((isChange == 0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
  1348. {
  1349. isChange = 1;
  1350. }
  1351. else if((isChange == 1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
  1352. {
  1353. isChange = 0;
  1354. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1355. }
  1356. }
  1357. else
  1358. {}
  1359. // Set battery animation
  1360. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1361. {
  1362. if(isChange == 0)
  1363. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1364. else
  1365. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1366. }
  1367. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1368. {
  1369. if(isChange == 0)
  1370. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1371. else
  1372. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1373. }
  1374. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1375. {
  1376. if(isChange == 0)
  1377. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1378. else
  1379. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1380. }
  1381. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1382. {
  1383. if(isChange == 0)
  1384. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1385. else
  1386. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1387. }
  1388. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 100))
  1389. {
  1390. if(isChange == 0)
  1391. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1392. else
  1393. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1394. }
  1395. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc == 100)
  1396. {
  1397. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1398. }
  1399. // Set battery SOC value
  1400. setBatteryPercentageValue(gun_index);
  1401. // Set electric arrow icon direction
  1402. if(isCharging == YES)
  1403. setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_LEFT);
  1404. else
  1405. setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_RIGHT);
  1406. }
  1407. break;
  1408. case SYS_MODE_TERMINATING:
  1409. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
  1410. {
  1411. // Set battery icon to empty
  1412. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1413. // Set battery percentage to disappear
  1414. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1415. }
  1416. else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1417. {
  1418. // Set battery animation
  1419. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1420. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1421. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1422. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1423. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1424. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1425. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1426. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1427. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
  1428. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1429. // Set battery SOC value
  1430. setBatteryPercentageValue(gun_index);
  1431. // Set electric arrow icon direction disappear
  1432. setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
  1433. }
  1434. break;
  1435. case SYS_MODE_COMPLETE:
  1436. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
  1437. {
  1438. // Set battery icon to 100%
  1439. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
  1440. // Set battery percentage to disappear
  1441. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1442. }
  1443. else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1444. {
  1445. // Set battery animation
  1446. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1447. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_20);
  1448. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1449. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_40);
  1450. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1451. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_60);
  1452. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1453. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_80);
  1454. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
  1455. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
  1456. // Set battery SOC value
  1457. setBatteryPercentageValue(gun_index);
  1458. // Set electric arrow icon direction disappear
  1459. setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
  1460. }
  1461. break;
  1462. default:
  1463. break;
  1464. }
  1465. }
  1466. //=======================================
  1467. // Setting connection icon animation
  1468. //=======================================
  1469. void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
  1470. {
  1471. switch(system_mode)
  1472. {
  1473. case SYS_MODE_PREPARING:
  1474. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1475. {
  1476. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
  1477. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1478. }
  1479. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1480. {
  1481. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_2);
  1482. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1483. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1484. }
  1485. break;
  1486. case SYS_MODE_CHARGING:
  1487. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1488. {
  1489. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
  1490. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1491. }
  1492. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1493. {
  1494. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_2);
  1495. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1496. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1497. }
  1498. break;
  1499. case SYS_MODE_TERMINATING:
  1500. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1501. {
  1502. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1503. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1504. }
  1505. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1506. {
  1507. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
  1508. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1509. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1510. }
  1511. break;
  1512. default:
  1513. break;
  1514. }
  1515. }
  1516. //=======================================
  1517. // Setting gun plug-in animation
  1518. //=======================================
  1519. void setGunPluginAnimation(uint8_t gun_index)
  1520. {
  1521. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_B)
  1522. {
  1523. if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN)))
  1524. {
  1525. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
  1526. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_1;
  1527. }
  1528. else if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN*2)))
  1529. {
  1530. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
  1531. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  1532. ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
  1533. }
  1534. }
  1535. else
  1536. {
  1537. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
  1538. }
  1539. }
  1540. //=======================================
  1541. // Setting battery SOC value
  1542. //=======================================
  1543. void setBatteryPercentageValue(uint8_t gun_index)
  1544. {
  1545. uint8_t data[16];
  1546. uint8_t soc[16];
  1547. memset(data, 0x00, ARRAY_SIZE(data));
  1548. memset(soc, 0x00, ARRAY_SIZE(soc));
  1549. sprintf((char *)soc, "%d%%", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc);
  1550. string2ByteArray(soc, data);
  1551. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PERCENTAGE, data, ARRAY_SIZE(data));
  1552. }
  1553. //=======================================
  1554. // Setting present charging power
  1555. //=======================================
  1556. void setPresentChargingPower(uint8_t gun_index)
  1557. {
  1558. uint8_t data[16];
  1559. uint8_t power[16];
  1560. memset(data, 0x00, ARRAY_SIZE(data));
  1561. memset(power, 0x00, ARRAY_SIZE(power));
  1562. sprintf((char *)power, "%.2f kW", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingPower);
  1563. string2ByteArray(power, data);
  1564. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_POWER_CHARGING, data, ARRAY_SIZE(data));
  1565. }
  1566. //=======================================
  1567. // Setting present charged energy
  1568. //=======================================
  1569. void setPresentChargedEnergy(uint8_t gun_index)
  1570. {
  1571. uint8_t data[16];
  1572. uint8_t energy[16];
  1573. memset(data, 0x00, ARRAY_SIZE(data));
  1574. memset(energy, 0x00, ARRAY_SIZE(energy));
  1575. sprintf((char *)energy, "%.4f kWh", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy);
  1576. string2ByteArray(energy, data);
  1577. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ENERGY_CHARGING, data, ARRAY_SIZE(data));
  1578. }
  1579. //=======================================
  1580. // Setting present charged duration
  1581. //=======================================
  1582. void setPresentChargedDuration(uint8_t gun_index)
  1583. {
  1584. uint8_t data[16];
  1585. uint8_t time[16];
  1586. uint16_t hour;
  1587. uint16_t minute;
  1588. uint16_t second;
  1589. uint16_t PresentChargedDuration = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration;
  1590. memset(data, 0x00, ARRAY_SIZE(data));
  1591. memset(time, 0x00, ARRAY_SIZE(time));
  1592. hour = (PresentChargedDuration / 3600);
  1593. minute = (PresentChargedDuration - (3600 * hour)) / 60;
  1594. second = (PresentChargedDuration - (3600 * hour) - (minute * 60));
  1595. sprintf((char *)time, "%02d:%02d:%02d", hour, minute, second);
  1596. string2ByteArray(time, data);
  1597. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_TIMER_CHARGING, data, ARRAY_SIZE(data));
  1598. }
  1599. //=======================================
  1600. // Setting authorization page
  1601. //=======================================
  1602. void setAuthorizationPage(uint8_t gun_index)
  1603. {
  1604. switch(ShmCharger->gun_info[gun_index].resultAuthorization)
  1605. {
  1606. case VALIDATED_RFID:
  1607. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_PASS)
  1608. {
  1609. setCurrentPage(SYSTEM_SCREEN_AUTH_PASS);
  1610. DEBUG_INFO("Setting page to authorizing : Validated RFID.\n");
  1611. }
  1612. else
  1613. {
  1614. DEBUG_INFO("Page authorizing validated.\n");
  1615. }
  1616. break;
  1617. case UNVALIDATED_RFID:
  1618. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_FAIL)
  1619. {
  1620. setCurrentPage(SYSTEM_SCREEN_AUTH_FAIL);
  1621. DEBUG_INFO("Setting page to authorizing : Unvalidated RFID.\n");
  1622. }
  1623. else
  1624. {
  1625. DEBUG_INFO("Page authorizing unvalidated.\n");
  1626. }
  1627. break;
  1628. case UNKNOW_RFID:
  1629. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_UNKNOW)
  1630. {
  1631. setCurrentPage(SYSTEM_SCREEN_AUTH_UNKNOW);
  1632. DEBUG_INFO("Setting page to authorizing : Unknow RFID\n");
  1633. }
  1634. else
  1635. {
  1636. DEBUG_INFO("Page authorizing unknow.\n");
  1637. }
  1638. break;
  1639. case DEFAULT_RFID:
  1640. break;
  1641. default:
  1642. break;
  1643. }
  1644. }
  1645. //=======================================
  1646. // Initial all share memory
  1647. //=======================================
  1648. int InitShareMemory()
  1649. {
  1650. int result = PASS;
  1651. int MeterSMId;
  1652. // Initial ShmSysConfigAndInfo
  1653. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1654. {
  1655. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1656. result = FAIL;
  1657. }
  1658. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1659. {
  1660. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1661. result = FAIL;
  1662. }
  1663. else
  1664. {}
  1665. // Initial ShmStatusCodeData
  1666. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1667. {
  1668. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1669. result = FAIL;
  1670. }
  1671. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1672. {
  1673. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1674. result = FAIL;
  1675. }
  1676. else
  1677. {}
  1678. // Initial ShmCharger
  1679. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  1680. {
  1681. DEBUG_ERROR("shmget ShmChargerKey NG\n");
  1682. result = FAIL;
  1683. }
  1684. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1685. {
  1686. DEBUG_ERROR("shmat ShmChargerKey NG\n");
  1687. result = FAIL;
  1688. }
  1689. // Initial ShmOCPP16Data
  1690. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1691. {
  1692. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  1693. result = FAIL;
  1694. }
  1695. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1696. {
  1697. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  1698. result = FAIL;
  1699. }
  1700. // Initial ShmOCPP20Data
  1701. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  1702. {
  1703. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  1704. result = FAIL;
  1705. }
  1706. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1707. {
  1708. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  1709. result = FAIL;
  1710. }
  1711. return result;
  1712. }
  1713. //=======================================
  1714. // Initial communication port
  1715. //=======================================
  1716. int InitComPort()
  1717. {
  1718. int fd;
  1719. struct termios tios;
  1720. fd = open("/dev/ttyS3", O_RDWR);
  1721. if(fd<=0)
  1722. {
  1723. DEBUG_ERROR("open /dev/ttyS3 NG\n");
  1724. return -1;
  1725. }
  1726. ioctl (fd, TCGETS, &tios);
  1727. tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
  1728. tios.c_lflag = 0;
  1729. tios.c_iflag = 0;
  1730. tios.c_oflag = 0;
  1731. tios.c_cc[VMIN]=0;
  1732. tios.c_cc[VTIME]=(unsigned char)5; // timeout 500ms
  1733. tios.c_lflag=0;
  1734. tcflush(fd, TCIFLUSH);
  1735. ioctl (fd, TCSETS, &tios);
  1736. return fd;
  1737. }
  1738. //=======================================
  1739. // Main process
  1740. //=======================================
  1741. int main(void)
  1742. {
  1743. uint8_t previousMode = 0xff;
  1744. if(InitShareMemory() == FAIL)
  1745. {
  1746. #ifdef SystemLogMessage
  1747. DEBUG_ERROR("InitShareMemory NG\n");
  1748. #endif
  1749. if(ShmStatusCodeData!=NULL)
  1750. {
  1751. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  1752. }
  1753. sleep(5);
  1754. return FAIL;
  1755. }
  1756. Uart1Fd=InitComPort();
  1757. if(Uart1Fd<0)
  1758. {
  1759. #ifdef SystemLogMessage
  1760. DEBUG_ERROR("InitComPort NG\n");
  1761. #endif
  1762. if(ShmStatusCodeData!=NULL)
  1763. {
  1764. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  1765. }
  1766. sleep(5);
  1767. return FAIL;
  1768. }
  1769. else
  1770. {}
  1771. DEBUG_INFO("Initial completed\n");
  1772. DEBUG_INFO("Latest Firmware Version : [%s] \n", FIRMWARE_UPDATE_IMAGE[0]);
  1773. DEBUG_INFO("Latest Upgrade Date : [%s]. \n", FIRMWARE_UPDATE_IMAGE[1]);
  1774. DEBUG_INFO("Latest Image Version : [%s]. \n", FIRMWARE_UPDATE_IMAGE[2]);
  1775. for(;;)
  1776. {
  1777. if(previousMode != ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  1778. {
  1779. previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
  1780. }
  1781. switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  1782. {
  1783. case SYS_MODE_BOOTING:
  1784. page_booting();
  1785. break;
  1786. case SYS_MODE_IDLE:
  1787. page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  1788. break;
  1789. case SYS_MODE_AUTHORIZING:
  1790. page_authorizing(ShmCharger->gun_selectd);
  1791. break;
  1792. case SYS_MODE_PREPARING:
  1793. page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  1794. break;
  1795. case SYS_MODE_CHARGING:
  1796. page_charging(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  1797. break;
  1798. case SYS_MODE_TERMINATING:
  1799. page_terminating(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  1800. break;
  1801. case SYS_MODE_COMPLETE:
  1802. page_complete(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  1803. break;
  1804. case SYS_MODE_ALARM:
  1805. page_alarm();
  1806. break;
  1807. case SYS_MODE_FAULT:
  1808. page_fault();
  1809. break;
  1810. case SYS_MODE_MAINTAIN:
  1811. page_maintain();
  1812. break;
  1813. case SYS_MODE_UPDATE:
  1814. page_update();
  1815. break;
  1816. case SYS_MODE_RESERVATION:
  1817. page_reservation();
  1818. break;
  1819. case SYS_MODE_BOOKING:
  1820. page_booking();
  1821. break;
  1822. case SYS_MODE_DEBUG:
  1823. page_debug();
  1824. break;
  1825. default:
  1826. page_unknown();
  1827. break;
  1828. }
  1829. page_header(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  1830. usleep(100000);
  1831. }
  1832. return FAIL;
  1833. }