Module_LcmControl.c 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585
  1. /*
  2. * Module_LcmControl.c
  3. *
  4. * Created on : 2020-10-20
  5. * Update on : 2021-06-23
  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. #include "cbmp.h"
  15. //=======================================
  16. // Declare share memory
  17. //=======================================
  18. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  19. struct StatusCodeData *ShmStatusCodeData;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. struct OCPP20Data *ShmOCPP20Data;
  22. struct Charger *ShmCharger;
  23. //=======================================
  24. // Declare Basic function
  25. //=======================================
  26. void trim(char *s);
  27. int mystrcmp(char *p1,char *p2);
  28. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  29. uint8_t split(char **arr, char *str, const char *del);
  30. void string2ByteArray(uint8_t *input, uint8_t *output);
  31. //=======================================
  32. // Declare Control panel function
  33. //=======================================
  34. uint8_t getCurrentPage();
  35. void setCurrentPage(uint8_t page);
  36. void setCurrencyFromWebsite(uint8_t unit);
  37. void setWarningStatus(uint8_t gun_index);
  38. void setAuthorizationPage(uint8_t gun_index);
  39. void setPriceFromWebsite(float monry_rate);
  40. void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode);
  41. void setPresentChargedEnergy(uint8_t gun_index);
  42. void setPresentChargingPower(uint8_t gun_index);
  43. void setBatteryPercentageValue(uint8_t gun_index);
  44. void setPresentChargedDuration(uint8_t gun_index);
  45. void setPresentPowerConsumption(uint8_t gun_index);
  46. void setQRcodeContent(char *input, uint8_t length, uint8_t mode);
  47. void setDisplayValue(uint16_t address, uint8_t value);
  48. void setGunPluginAnimation(uint8_t gun_index);
  49. void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode);
  50. void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode);
  51. void setPresentFinalCost(float cost);
  52. float getPresentFinalCost(uint8_t gun_index);
  53. void setDefaultValue(uint8_t gun_index, uint8_t system_mode);
  54. void setStartButtonAnimation(uint8_t gun_index);
  55. void setUserPrice(uint8_t type);
  56. void setDefaultPrice(uint8_t type);
  57. void setFinalCost(uint8_t gun_index, uint8_t type);
  58. void setCurrencyAndUnitFromBackend(uint8_t type_price,uint8_t type_currency_unit, uint8_t gun_index);
  59. void setRTC();
  60. void setRfidIcon();
  61. void setWifi4GIcon();
  62. void setQRCodeIcon();
  63. void setBackendIcon();
  64. void setEthernetIcon();
  65. void setAlarmCodeAndIcon();
  66. void setBillingFromWebsite();
  67. void setQRCodeReceipt(uint8_t gun_index);
  68. void setReceiptIcon(uint8_t gun_index);
  69. //=======================================
  70. // Declare Timer
  71. //=======================================
  72. enum TMR_IDX
  73. {
  74. TMR_IDX_BATTERY=0,
  75. TMR_IDX_CONNECTION,
  76. TMR_IDX_PLUGIN,
  77. TMR_IDX_ALARM,
  78. TMR_IDX_PRICE,
  79. TMR_IDX_EMULATOR,
  80. TMR_IDX_STARTBUTTON,
  81. TMR_IDX_7,
  82. TMR_IDX_8,
  83. TMR_IDX_SHOW_AUTH_RESULT
  84. };
  85. struct timeb startTime[AC_QUANTITY][10];
  86. #define TIME_ANIMATION_PLUGIN 1000
  87. #define TIME_ANIMATION_BATTERY 1000
  88. #define TIME_ANIMATION_CONNECTION 1000
  89. #define TIME_ANIMATION_START_BUTTON 1000
  90. #define TIME_ANIMATION_ALARM 5000
  91. #define TIME_REFRESH_TIME 5000
  92. #define TIME_AUTH_RESULT_TIME 5000
  93. //=======================================
  94. // Declare Variable
  95. //=======================================
  96. uint8_t BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  97. uint8_t CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  98. uint8_t GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  99. uint8_t START_BUTTON_LEVEL_STATUS = START_BUTTON_LEVEL_0;
  100. uint8_t WarningCount = 255;
  101. int Uart1Fd;
  102. //=======================================
  103. // Emulator
  104. //=======================================
  105. int PERCENTAGE;
  106. uint8_t isChange;
  107. uint8_t isEmulator = NO;
  108. uint8_t isCharging = YES;
  109. //=======================================
  110. // Record version and date
  111. //=======================================
  112. char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.19", "2021-09-28", "REV.01.00"};
  113. //=======================================
  114. // Common routine
  115. //=======================================
  116. int StoreLogMsg(const char *fmt, ...)
  117. {
  118. char Buf[4096+256];
  119. char buffer[4096];
  120. time_t CurrentTime;
  121. struct tm *tm;
  122. struct timeval tv;
  123. va_list args;
  124. va_start(args, fmt);
  125. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  126. va_end(args);
  127. memset(Buf,0,sizeof(Buf));
  128. CurrentTime = time(NULL);
  129. tm=localtime(&CurrentTime);
  130. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  131. sprintf(Buf,"echo -n \'[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\' >> /Storage/SystemLog/[%04d.%02d]Module_LcmControlLog",
  132. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  133. buffer,
  134. tm->tm_year+1900,tm->tm_mon+1);
  135. #ifdef SystemLogMessage
  136. system(Buf);
  137. #endif
  138. #ifdef ConsloePrintLog
  139. 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);
  140. #endif
  141. return rc;
  142. }
  143. long long DiffTimebWithNow(struct timeb ST)
  144. {
  145. //return milli-second
  146. struct timeb ET;
  147. long long StartTime,StopTime;
  148. ftime(&ET);
  149. StartTime=(long long)ST.time;
  150. StopTime=(long long)ET.time;
  151. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  152. }
  153. int DiffTimeb(struct timeb ST, struct timeb ET)
  154. {
  155. //return milli-second
  156. unsigned int StartTime,StopTime;
  157. StartTime=(unsigned int)ST.time;
  158. StopTime=(unsigned int)ET.time;
  159. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  160. }
  161. void trim(char *s)
  162. {
  163. int i=0, j, k, l=0;
  164. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  165. i++;
  166. j = strlen(s)-1;
  167. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  168. j--;
  169. if(i==0 && j==strlen(s)-1) { }
  170. else if(i==0) s[j+1] = '\0';
  171. else {
  172. for(k=i; k<=j; k++) s[l++] = s[k];
  173. s[l] = '\0';
  174. }
  175. }
  176. void trim_string(char *s, unsigned char len)
  177. {
  178. for(unsigned char i = 0 ; i < len; i++)
  179. {
  180. if (!(s[i] =='.')&& !((s[i]>='0') && (s[i]<='9')))
  181. {
  182. s[i] = s[i + 1];
  183. strncpy(s + i, s + i + 1, len);
  184. i -= 1;
  185. len -= 1;
  186. }
  187. }
  188. s[len + 1] = '\0';
  189. }
  190. int mystrcmp(char *p1,char *p2)
  191. {
  192. while(*p1==*p2)
  193. {
  194. if(*p1=='\0' || *p2=='\0')
  195. break;
  196. p1++;
  197. p2++;
  198. }
  199. if(*p1=='\0' && *p2=='\0')
  200. return(PASS);
  201. else
  202. return(FAIL);
  203. }
  204. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  205. {
  206. strncpy(dest, src + start, cnt);
  207. dest[cnt] = 0;
  208. }
  209. uint8_t split(char **arr, char *str, const char *del)
  210. {
  211. uint8_t result = 0;
  212. char *s = strtok(str, del);
  213. while(s != NULL)
  214. {
  215. *arr++ = s;
  216. result += 1;
  217. s = strtok(NULL, del);
  218. }
  219. return result;
  220. }
  221. void getDateTimeString(char* result)
  222. {
  223. time_t CurrentTime;
  224. struct tm *tm;
  225. CurrentTime = time(NULL);
  226. tm=localtime(&CurrentTime);
  227. sprintf(result, "%04d/%02d/%02d %02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
  228. }
  229. //=======================================
  230. // Function to page routine
  231. //=======================================
  232. void page_booting()
  233. {
  234. if(getCurrentPage() != SYSTEM_SCREEN_BOOTING)
  235. {
  236. setCurrentPage(SYSTEM_SCREEN_BOOTING);
  237. DEBUG_INFO("Setting page to booting.\n");
  238. }
  239. else
  240. {}
  241. }
  242. void page_idle(uint8_t gun_index, uint8_t system_mode)
  243. {
  244. if(ShmCharger->gun_info[gun_index].isSleepOn == YES)
  245. {
  246. if((getCurrentPage() != SYSTEM_SCREEN_SLEEP))
  247. {
  248. setCurrentPage(SYSTEM_SCREEN_SLEEP);
  249. START_BUTTON_LEVEL_STATUS = START_BUTTON_LEVEL_0;
  250. ftime(&startTime[gun_index][TMR_IDX_STARTBUTTON]);
  251. }
  252. else
  253. setStartButtonAnimation(gun_index);
  254. }
  255. else
  256. {
  257. if(ShmCharger->gun_info[gun_index].isCheckPowerConsumption == YES)
  258. {
  259. setCurrentPage(SYSTEM_SCREEN_POWER_CONSUMPTION);
  260. setDisplayValue(ICON_POWER_CONSUMPTION, APPEAR);
  261. setPresentPowerConsumption(gun_index);
  262. }
  263. else
  264. {
  265. if((getCurrentPage() != SYSTEM_SCREEN_IDLE) && (ShmCharger->gun_info[gun_index].resultAuthorization != VALIDATED_RFID))
  266. {
  267. setCurrentPage(SYSTEM_SCREEN_IDLE);
  268. setDefaultValue(gun_index, system_mode);
  269. DEBUG_INFO("Setting page to idle.\n");
  270. }
  271. else
  272. {
  273. setRfidIcon();
  274. setQRCodeIcon();
  275. if(isEmulator == YES)
  276. {
  277. //if(isCharging == YES)
  278. //PERCENTAGE = 0;
  279. //else
  280. //PERCENTAGE = 100;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. void page_authorizing(uint8_t gun_index)
  287. {
  288. // CHANGE DISPLAY TO AUTHORIZATION
  289. setAuthorizationPage(gun_index);
  290. // SHOW USER ACCOUNT BALANCE WHEN THE SYSTEM IS ONLINE
  291. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  292. {
  293. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  294. {
  295. if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
  296. ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
  297. {
  298. // SEARCHING USER PRICE FOR ACCOUNT BALANCE
  299. setUserPrice(ACCOUNT_BALANCE);
  300. }
  301. else
  302. {
  303. // DISAPPEAR ACCOUNT BALANCE AND ICON
  304. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  305. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  306. }
  307. }
  308. else
  309. {
  310. // DISPLAY BY OCPP 2.0.1
  311. }
  312. }
  313. else
  314. {
  315. // DISAPPEAR ACCOUNT BALANCE AND ICON
  316. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  317. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  318. }
  319. }
  320. void page_preparing(uint8_t gun_index, uint8_t system_mode)
  321. {
  322. // CHECK PREPARING MODE (BS & SOCKET) / HLC
  323. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  324. {
  325. if((getCurrentPage() != SYSTEM_SCREEN_PREPARE_FOR_EVSE))
  326. {
  327. setCurrentPage(SYSTEM_SCREEN_PREPARE_FOR_EVSE);
  328. setDefaultValue(gun_index, system_mode);
  329. DEBUG_INFO("Setting page to prepare for EVSE.\n");
  330. }
  331. else
  332. {
  333. setConnectionAnimation(gun_index, system_mode);
  334. }
  335. }
  336. else
  337. {
  338. if((getCurrentPage() != SYSTEM_SCREEN_PREPARING))
  339. {
  340. setCurrentPage(SYSTEM_SCREEN_PREPARING);
  341. setDefaultValue(gun_index, system_mode);
  342. DEBUG_INFO("Setting page to preparing.\n");
  343. }
  344. else
  345. {
  346. setGunPluginAnimation(gun_index);
  347. }
  348. }
  349. }
  350. void page_charging(uint8_t gun_index, uint8_t system_mode)
  351. {
  352. if((getCurrentPage() != SYSTEM_SCREEN_CHARGING) && (!ShmCharger->isAuthrizing && !ShmCharger->isGetAuthResult))
  353. {
  354. setCurrentPage(SYSTEM_SCREEN_CHARGING);
  355. setDefaultValue(gun_index, system_mode);
  356. DEBUG_INFO("Setting page to charging.\n");
  357. //isChange = 0;
  358. //ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
  359. }
  360. else
  361. {
  362. setConnectionAnimation(gun_index, system_mode);
  363. setBatteryAnimation(gun_index, system_mode);
  364. setPresentChargedDuration(gun_index);
  365. setPresentChargedEnergy(gun_index);
  366. setPresentChargingPower(gun_index);
  367. }
  368. }
  369. void page_complete(uint8_t gun_index, uint8_t system_mode)
  370. {
  371. if(getCurrentPage() != SYSTEM_SCREEN_COMPLETE)
  372. {
  373. setCurrentPage(SYSTEM_SCREEN_COMPLETE);
  374. DEBUG_INFO("Setting page to complete.\n");
  375. }
  376. else
  377. {
  378. setPresentChargedEnergy(gun_index);
  379. setPresentChargedDuration(gun_index);
  380. setBatteryAnimation(gun_index, system_mode);
  381. setReceiptIcon(gun_index);
  382. // SHOW FINAL COST AND ACCOUNT BALANCE AFTER THE END OF TRANSACTION
  383. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  384. {
  385. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  386. {
  387. setFinalCost(gun_index, TOTAL_COST);
  388. setFinalCost(gun_index, ACCOUNT_BALANCE);
  389. setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
  390. }
  391. else
  392. {
  393. // DISPLAY BY OCPP 2.0.1
  394. }
  395. }
  396. else
  397. {
  398. if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
  399. {
  400. // APPEAR COST AND ICON
  401. setDisplayValue(ICON_COST_COMPLETE, APPEAR);
  402. setPresentFinalCost(getPresentFinalCost(gun_index));
  403. }
  404. else
  405. {
  406. // DISAPPEAR ACCOUNT BALANCE AND ICON
  407. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  408. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  409. // DISAPPEAR COST AND ICON
  410. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  411. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  412. // DISAPPEAR BALANCE CURRENCY UNIT
  413. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  414. }
  415. }
  416. }
  417. }
  418. void page_terminating(uint8_t gun_index, uint8_t system_mode)
  419. {
  420. if((getCurrentPage() != SYSTEM_SCREEN_TERMINATING) && (!ShmCharger->isAuthrizing && !ShmCharger->isGetAuthResult))
  421. {
  422. setCurrentPage(SYSTEM_SCREEN_TERMINATING);
  423. setDefaultValue(gun_index, system_mode);
  424. DEBUG_INFO("Setting page to terminating.\n");
  425. }
  426. else
  427. {
  428. setConnectionAnimation(gun_index, system_mode);
  429. setBatteryAnimation(gun_index, system_mode);
  430. setPresentChargedDuration(gun_index);
  431. setPresentChargedEnergy(gun_index);
  432. setPresentChargingPower(gun_index);
  433. setReceiptIcon(gun_index);
  434. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  435. {
  436. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  437. {
  438. setFinalCost(gun_index, TOTAL_COST);
  439. setFinalCost(gun_index, ACCOUNT_BALANCE);
  440. setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
  441. }
  442. else
  443. {
  444. // DISPLAY BY OCPP 2.0.1
  445. }
  446. }
  447. else
  448. {
  449. // DISAPPEAR ACCOUNT BALANCE AND ICON
  450. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  451. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  452. // DISAPPEAR COST ADN ICON
  453. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  454. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  455. // DISAPPEAR BALANCE CURRENCY UNIT
  456. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  457. }
  458. }
  459. }
  460. void page_alarm()
  461. {
  462. if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip != ON)
  463. {
  464. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  465. {
  466. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  467. DEBUG_INFO("Setting page to repair man.\n");
  468. }
  469. else
  470. {}
  471. }
  472. else
  473. {
  474. if(getCurrentPage() != SYSTEM_SCREEN_EMERGENCY)
  475. {
  476. setCurrentPage(SYSTEM_SCREEN_EMERGENCY);
  477. DEBUG_INFO("Setting page to emergency.\n");
  478. }
  479. else
  480. {}
  481. }
  482. }
  483. void page_fault()
  484. {
  485. //DEBUG_INFO("Page fault.\n");
  486. }
  487. void page_maintain()
  488. {
  489. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  490. {
  491. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  492. DEBUG_INFO("Setting page to maintain.\n");
  493. }
  494. else
  495. {}
  496. }
  497. void page_update()
  498. {
  499. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  500. {
  501. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  502. DEBUG_INFO("Setting page to update.\n");
  503. }
  504. else
  505. {}
  506. }
  507. void page_reservation()
  508. {
  509. //DEBUG_INFO("Page reservation.\n");
  510. }
  511. void page_booking()
  512. {
  513. //DEBUG_INFO("Page booking.\n");
  514. }
  515. void page_debug()
  516. {
  517. if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
  518. {
  519. setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
  520. DEBUG_INFO("Setting page to debug.\n");
  521. }
  522. else
  523. {}
  524. }
  525. void page_unknown()
  526. {
  527. //DEBUG_INFO("Page unknown.\n");
  528. }
  529. void page_header(uint8_t gun_index, uint8_t system_mode)
  530. {
  531. setEthernetIcon();
  532. setBackendIcon();
  533. setWifi4GIcon();
  534. setWarningStatus(gun_index);
  535. // CHANGE LCD BRIGHNESS ( POWER SAVING MODE )
  536. if((ShmCharger->isLcdOn == ON))
  537. setDisplayValue(REG_ADDRESS_WRITE_BRIGHTNESS,BRIGHTNESS_100);
  538. else
  539. setDisplayValue(REG_ADDRESS_WRITE_BRIGHTNESS,BRIGHTNESS_10);
  540. // SET BILLING
  541. if((ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON) && (ShmSysConfigAndInfo->SysInfo.OcppConnStatus != ON))
  542. {
  543. setBillingFromWebsite();
  544. }
  545. else
  546. {
  547. // EVERY 5 SECONDS TO UPDATE PRICE
  548. if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PRICE]) > (TIME_REFRESH_TIME))
  549. {
  550. ftime(&startTime[gun_index][TMR_IDX_PRICE]);
  551. setBillingFromBackend(gun_index, system_mode);
  552. }
  553. }
  554. }
  555. void page_footer()
  556. {
  557. setRTC();
  558. }
  559. //=======================================
  560. // Setting icon display value
  561. //=======================================
  562. void setDisplayValue(uint16_t address, uint8_t value)
  563. {
  564. uint8_t data[2];
  565. data[0] = value >> 8;
  566. data[1] = value & 0X00FF;
  567. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, address, data, ARRAY_SIZE(data));
  568. }
  569. //=======================================
  570. // Getting current page
  571. //=======================================
  572. uint8_t getCurrentPage()
  573. {
  574. uint8_t currentPage[2];
  575. uint8_t result = 255;
  576. if(lcdRegisterRead(Uart1Fd, REG_TYPE_CONTROL, REG_ADDRESS_READ_PAGE_ID, currentPage, ARRAY_SIZE(currentPage)))
  577. {
  578. result = currentPage[1];
  579. // DEBUG_INFO("currentPage[0] : %X\n", currentPage[0]);
  580. // DEBUG_INFO("currentPage[1] : %X\n", currentPage[1]);
  581. // DEBUG_INFO("Getting current page : [%d] \n", result);
  582. }
  583. else
  584. {
  585. DEBUG_INFO("Getting current page fail! \n");
  586. }
  587. return result;
  588. }
  589. //=======================================
  590. // Setting current page
  591. //=======================================
  592. void setCurrentPage(uint8_t page)
  593. {
  594. uint8_t settingPage[2] = {0x00, page};
  595. if(lcdRegisterWrite(Uart1Fd, REG_TYPE_CONTROL, REG_ADDRESS_SET_PAGE_ID, settingPage, ARRAY_SIZE(settingPage)))
  596. DEBUG_INFO("Setting current page to : [%d] \n", page);
  597. else
  598. DEBUG_INFO("Setting current page fail! \n");
  599. }
  600. //=======================================
  601. // Convert string to byte array
  602. //=======================================
  603. void string2ByteArray(unsigned char *input, uint8_t *output)
  604. {
  605. int loop;
  606. int i;
  607. loop = 0;
  608. i = 0;
  609. while(input[loop] != '\0')
  610. {
  611. output[i++] = input[loop++];
  612. }
  613. output[loop] = '\0';
  614. }
  615. //=======================================
  616. // Setting ETHERNET icon status
  617. //=======================================
  618. void setEthernetIcon()
  619. {
  620. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet == ON)
  621. setDisplayValue(ICON_ETHERENT_CONNECTION, ETHERENT_OFFLINE);
  622. else
  623. setDisplayValue(ICON_ETHERENT_CONNECTION, EHTERNET_ONLINE);
  624. }
  625. //=======================================
  626. // Setting BACKEND icon status
  627. //=======================================
  628. void setBackendIcon()
  629. {
  630. if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus != ON)
  631. setDisplayValue(ICON_BACKEND_CONNECTION,BACKEND_OFFLINE);
  632. else
  633. setDisplayValue(ICON_BACKEND_CONNECTION,BACKEND_ONLINE);
  634. }
  635. //=======================================
  636. // Setting WIFI / 4G icon status
  637. //=======================================
  638. void setWifi4GIcon()
  639. {
  640. // SET WIFI + 4G ICON STATUS ( ONLINE OR OFFLINE )
  641. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
  642. {
  643. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == DISABLE_WIFI)
  644. {
  645. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G)
  646. {
  647. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  648. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  649. }
  650. else
  651. {
  652. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  653. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  654. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
  655. else
  656. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
  657. }
  658. }
  659. else
  660. {
  661. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == WIFI_STATION)
  662. {
  663. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
  664. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  665. else
  666. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
  667. }
  668. else
  669. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  670. if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G)
  671. {
  672. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  673. }
  674. else
  675. {
  676. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  677. setDisplayValue(ICON_4G_CONNECTION, TELECOM_OFFLINE);
  678. else
  679. setDisplayValue(ICON_4G_CONNECTION, TELECOM_ONLINE);
  680. }
  681. }
  682. }
  683. else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'E')
  684. {
  685. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  686. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  687. }
  688. else
  689. {
  690. // SET 4G ICON STATUS ( ONLINE OR OFFLINE )
  691. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
  692. {
  693. switch(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled)
  694. {
  695. case DISABLE_4G:
  696. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  697. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  698. break;
  699. case ENABLE_4G:
  700. // Clean icon
  701. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  702. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  703. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
  704. else
  705. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
  706. break;
  707. default:
  708. break;
  709. }
  710. }
  711. // SET WIFI ICON STATUS ( ONLINE OR OFFLINE)
  712. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
  713. {
  714. switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
  715. {
  716. case DISABLE_WIFI:
  717. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  718. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  719. break;
  720. case WIFI_STATION:
  721. // Clean icon
  722. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  723. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
  724. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  725. else
  726. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
  727. break;
  728. case WIFI_ACCESS_POINT:
  729. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  730. break;
  731. default:
  732. break;
  733. }
  734. }
  735. }
  736. }
  737. //=======================================
  738. // Setting billing ( WEB PAGE )
  739. //=======================================
  740. void setBillingFromWebsite()
  741. {
  742. if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
  743. {
  744. setDisplayValue(ICON_PRICE, APPEAR);
  745. struct timeb csuTime;
  746. struct tm *tmCSU;
  747. ftime(&csuTime);
  748. tmCSU = localtime(&csuTime.time);
  749. if(tmCSU->tm_hour <= 23)
  750. {
  751. ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
  752. setPriceFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
  753. }
  754. // CURRENCY UNIT ( 53 COUNTRIES )
  755. if(ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
  756. {
  757. setCurrencyFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  758. }
  759. }
  760. else
  761. {
  762. setDisplayValue(ICON_PRICE, DISAPPEAR);
  763. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  764. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  765. }
  766. }
  767. //=======================================
  768. // Setting currency ( WEB PAGE )
  769. //=======================================
  770. void setCurrencyFromWebsite(uint8_t unit)
  771. {
  772. uint8_t data[16];
  773. uint8_t currency[16];
  774. unsigned char kWh [16];
  775. uint8_t final_currency[16];
  776. memset(data, 0x00, ARRAY_SIZE(data));
  777. memset(currency, 0x00, ARRAY_SIZE(currency));
  778. memset(final_currency, 0x00, ARRAY_SIZE(final_currency));
  779. strcpy((char*)kWh, "/kWh");
  780. memcpy((char*)currency, Currency[unit], 3);
  781. sprintf((char *)final_currency, "%s%s", currency,kWh);
  782. string2ByteArray(final_currency, data);
  783. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, data, ARRAY_SIZE(data));
  784. }
  785. //=======================================
  786. // Setting price ( WEB PAGE )
  787. //=======================================
  788. void setPriceFromWebsite(float monry_rate)
  789. {
  790. uint8_t data[16];
  791. uint8_t price[16];
  792. memset(data, 0x00, ARRAY_SIZE(data));
  793. memset(price, 0x00, ARRAY_SIZE(price));
  794. sprintf((char *)price, "%.2f", monry_rate);
  795. string2ByteArray(price, data);
  796. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, data, ARRAY_SIZE(data));
  797. }
  798. //=======================================
  799. // Setting final cost ( WEB PAGE )
  800. //=======================================
  801. void setPresentFinalCost(float cost)
  802. {
  803. uint8_t data[16];
  804. uint8_t finalCost[16];
  805. memset(data, 0x00, ARRAY_SIZE(data));
  806. memset(finalCost, 0x00, ARRAY_SIZE(finalCost));
  807. sprintf((char *)finalCost, "%.2f", cost);
  808. string2ByteArray(finalCost, data);
  809. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, data, ARRAY_SIZE(data));
  810. }
  811. //=======================================
  812. // Getting final cost ( WEB PAGE )
  813. //=======================================
  814. float getPresentFinalCost(uint8_t gun_index)
  815. {
  816. float result = 0.0f;
  817. for(int idx=0;idx<ARRAY_SIZE(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod);idx++)
  818. {
  819. result += ((ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idx]) * ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idx]);
  820. }
  821. return result;
  822. }
  823. //=======================================
  824. // Setting billing ( BACKEND )
  825. //=======================================
  826. void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
  827. {
  828. if((system("pidof -s OcppBackend > /dev/null") != 0))
  829. {
  830. // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
  831. setDisplayValue(ICON_PRICE, DISAPPEAR);
  832. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  833. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  834. }
  835. else
  836. {
  837. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  838. {
  839. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  840. {
  841. if((strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData,"") != 0))
  842. {
  843. if(system_mode == SYS_MODE_IDLE)
  844. {
  845. /*
  846. * 1. SEARCHING DEFAULT PRICE FOR PRICE TEXT
  847. * 2. SEARCHING DEFAULT PRICE FOR CURRENCY AND UNIT TO APPEAR
  848. */
  849. setDefaultPrice(CURRENT_RATE);
  850. setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
  851. }
  852. else
  853. {
  854. /*
  855. * 1. IF STARTUSERID IS NOT MATCH WITH IDTOKEN ALSO VALUE CAN'T BE NULL, OTHERWISE THE SYSTEM MUST USE DEFAULT PRICE
  856. */
  857. if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
  858. ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
  859. {
  860. /*
  861. * 1. SEARCHING USER PRICE FOR PRICE TEXT
  862. * 2. SEARCHING USER PRICE FOR CURRENCY AND UNIT TO APPEAR
  863. */
  864. setUserPrice(CURRENT_RATE);
  865. setCurrencyAndUnitFromBackend(SET_USER_PRICE, CURRENT_RATE,gun_index);
  866. }
  867. else
  868. {
  869. /*
  870. * 1. SEARCHING DEFAULT PRICE FOR PRICE TEXT
  871. * 2. SEARCHING DEFAULT PRICE FOR CURRENCY AND UNIT TO APPEAR
  872. */
  873. setDefaultPrice(CURRENT_RATE);
  874. setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
  875. }
  876. }
  877. }
  878. else
  879. {
  880. // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
  881. setDisplayValue(ICON_PRICE, DISAPPEAR);
  882. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  883. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  884. }
  885. }
  886. else
  887. {
  888. // DISPLAY BY OCPP 2.0.1
  889. }
  890. }
  891. else
  892. {
  893. // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
  894. setDisplayValue(ICON_PRICE, DISAPPEAR);
  895. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  896. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  897. }
  898. }
  899. }
  900. //=======================================
  901. // Setting UserPrice ( BACKEND )
  902. //=======================================
  903. void setUserPrice(uint8_t type)
  904. {
  905. uint8_t length;
  906. uint8_t output_data[32];
  907. char input_data[32];
  908. char tmp[256];
  909. char *splitString[10];
  910. const char *Symbol = ";";
  911. memset(tmp, 0, ARRAY_SIZE(tmp));
  912. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  913. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  914. switch(type)
  915. {
  916. case CONNECTION_FEE:
  917. break;
  918. case CURRENT_RATE:
  919. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
  920. {
  921. // APPEAR PRICE ICON
  922. setDisplayValue(ICON_PRICE, APPEAR);
  923. // APPEAR PRICE TEXT
  924. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  925. split((char**)splitString, tmp, Symbol);
  926. memcpy(input_data, splitString[1], strlen(splitString[1]));
  927. length = strlen(input_data);
  928. trim_string(input_data,length);
  929. memcpy(output_data ,input_data, strlen(input_data));
  930. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
  931. }
  932. else
  933. {
  934. // DISAPPEAR PRICE ICON AND PRICE TEXT
  935. setDisplayValue(ICON_PRICE, DISAPPEAR);
  936. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  937. }
  938. break;
  939. case OCCUPANCY_FEE:
  940. break;
  941. case ACCOUNT_BALANCE:
  942. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Account Balance:") > 0)
  943. {
  944. // APPEAR ACCOUNT BALANCE ICON
  945. setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
  946. // APPEAR ACCOUNT BALANCE TEXT
  947. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  948. split((char**)splitString, tmp, Symbol);
  949. memcpy(input_data, splitString[3], strlen(splitString[3]));
  950. length = strlen(input_data);
  951. trim_string(input_data,length);
  952. memcpy(output_data ,input_data, strlen(input_data));
  953. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
  954. }
  955. else
  956. {
  957. // DISAPPEAR BALANCE ICON AND BALANCE TEXT
  958. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  959. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  960. }
  961. break;
  962. default:
  963. break;
  964. }
  965. }
  966. //=======================================
  967. // Setting DefaultPrice ( BACKEND )
  968. //=======================================
  969. void setDefaultPrice(uint8_t type)
  970. {
  971. uint8_t length;
  972. uint8_t output_data[32];
  973. char input_data[32];
  974. char tmp[256];
  975. char *splitString[10];
  976. const char *Symbol = ";";
  977. memset(tmp, 0, ARRAY_SIZE(tmp));
  978. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  979. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  980. switch(type)
  981. {
  982. case CONNECTION_FEE:
  983. break;
  984. case CURRENT_RATE:
  985. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
  986. {
  987. // APPEAR PRICE ICON
  988. setDisplayValue(ICON_PRICE, APPEAR);
  989. // APPEAR PRICE TEXT
  990. strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  991. split((char**)splitString, tmp, Symbol);
  992. memcpy(input_data, splitString[1], strlen(splitString[1]));
  993. length = strlen(input_data);
  994. trim_string(input_data,length);
  995. memcpy(output_data ,input_data, strlen(input_data));
  996. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
  997. }
  998. else
  999. {
  1000. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  1001. setDisplayValue(ICON_PRICE, DISAPPEAR);
  1002. }
  1003. break;
  1004. case OCCUPANCY_FEE:
  1005. break;
  1006. default:
  1007. break;
  1008. }
  1009. }
  1010. //=======================================
  1011. // Setting FinalCost ( BACKEND )
  1012. //=======================================
  1013. void setFinalCost(uint8_t gun_index, uint8_t type)
  1014. {
  1015. uint8_t length;
  1016. uint8_t output_data[32];
  1017. char input_data[32];
  1018. char tmp[256];
  1019. char *splitString[10];
  1020. const char *Symbol = ";";
  1021. memset(tmp, 0, ARRAY_SIZE(tmp));
  1022. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  1023. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  1024. switch(type)
  1025. {
  1026. case CONNECTION_FEE:
  1027. break;
  1028. case SESSION_FEE:
  1029. break;
  1030. case OCCUPANCY_FEE:
  1031. break;
  1032. case TOTAL_COST:
  1033. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Total Cost:") > 0))
  1034. {
  1035. // APPEAR COST ICON
  1036. setDisplayValue(ICON_COST_COMPLETE, APPEAR);
  1037. // APPEAR COST TEXT
  1038. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  1039. split((char**)splitString, tmp, Symbol);
  1040. memcpy(input_data, splitString[3], strlen(splitString[3]));
  1041. length = strlen(input_data);
  1042. trim_string(input_data,length);
  1043. memcpy(output_data ,input_data, strlen(input_data));
  1044. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1045. }
  1046. else
  1047. {
  1048. // DISAPPEAR COST ICON AND COST TEXT
  1049. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  1050. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  1051. }
  1052. break;
  1053. case ACCOUNT_BALANCE:
  1054. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
  1055. {
  1056. // APPEAR BALANCE ICON
  1057. setDisplayValue(ICON_WALLER_COMPLETE, APPEAR);
  1058. setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
  1059. // APPEAR BALANCE TEXT
  1060. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  1061. split((char**)splitString, tmp, Symbol);
  1062. memcpy(input_data, splitString[4], strlen(splitString[4]));
  1063. length = strlen(input_data);
  1064. trim_string(input_data,length);
  1065. memcpy(output_data ,input_data, strlen(input_data));
  1066. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ACCOUNT_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1067. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
  1068. }
  1069. else
  1070. {
  1071. /*
  1072. * 1. DISAPPEAR ACCOUNT BALANCE WHEN THE SYSTEM IS COMPLETE MODE
  1073. * 2. DISAPPEAR ACCOUNT ICON WHEN THE SYSTEM IS COMPLETE MODE
  1074. */
  1075. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  1076. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  1077. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  1078. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  1079. }
  1080. break;
  1081. default:
  1082. break;
  1083. }
  1084. }
  1085. //=======================================
  1086. // Setting currency ( BACKEND )
  1087. //=======================================
  1088. void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_unit,uint8_t gun_index)
  1089. {
  1090. uint8_t length;
  1091. uint8_t output_data[32];
  1092. char input_data[32];
  1093. char tmp[256];
  1094. char *splitString[10];
  1095. const char *Symbol = ";";
  1096. memset(tmp, 0, ARRAY_SIZE(tmp));
  1097. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  1098. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  1099. if(type_price == DEFAULE_PRICE)
  1100. {
  1101. switch(type_currency_unit)
  1102. {
  1103. case CONNECTION_FEE:
  1104. break;
  1105. case CURRENT_RATE:
  1106. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
  1107. {
  1108. strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  1109. split((char**)splitString, tmp, Symbol);
  1110. memcpy(input_data, splitString[1], strlen(splitString[1]));
  1111. length = strlen(input_data);
  1112. memcpy(output_data , input_data+(length-7), 7);
  1113. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
  1114. }
  1115. else
  1116. {
  1117. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  1118. }
  1119. break;
  1120. case OCCUPANCY_FEE:
  1121. break;
  1122. default:
  1123. break;
  1124. }
  1125. }
  1126. else if(type_price == SET_USER_PRICE)
  1127. {
  1128. switch(type_currency_unit)
  1129. {
  1130. case CONNECTION_FEE:
  1131. break;
  1132. case CURRENT_RATE:
  1133. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
  1134. {
  1135. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  1136. split((char**)splitString, tmp, Symbol);
  1137. memcpy(input_data, splitString[1], strlen(splitString[1]));
  1138. length = strlen(input_data);
  1139. memcpy(output_data , input_data+(length-7), 7);
  1140. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
  1141. }
  1142. else
  1143. {
  1144. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  1145. }
  1146. break;
  1147. case OCCUPANCY_FEE:
  1148. break;
  1149. case ACCOUNT_BALANCE:
  1150. break;
  1151. default:
  1152. break;
  1153. }
  1154. }
  1155. else if(type_price == FINAL_COST)
  1156. {
  1157. switch(type_currency_unit)
  1158. {
  1159. case CONNECTION_FEE:
  1160. break;
  1161. case SESSION_FEE:
  1162. break;
  1163. case OCCUPANCY_FEE:
  1164. break;
  1165. case TOTAL_COST:
  1166. break;
  1167. case ACCOUNT_BALANCE:
  1168. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
  1169. {
  1170. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  1171. split((char**)splitString, tmp, Symbol);
  1172. memcpy(input_data, splitString[4], strlen(splitString[4]));
  1173. length = strlen(input_data);
  1174. memcpy(output_data , input_data+(length-3), 3);
  1175. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1176. }
  1177. else
  1178. {
  1179. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  1180. }
  1181. break;
  1182. default:
  1183. break;
  1184. }
  1185. }
  1186. else
  1187. {}
  1188. }
  1189. //=======================================
  1190. // Setting RTC value
  1191. //=======================================
  1192. void setRTC()
  1193. {
  1194. uint8_t data[32];
  1195. uint8_t rtc[32];
  1196. memset(data, 0x00, ARRAY_SIZE(data));
  1197. memset(rtc, 0x00, ARRAY_SIZE(rtc));
  1198. getDateTimeString((char*)rtc);
  1199. string2ByteArray(rtc, data);
  1200. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_RTC, data, ARRAY_SIZE(data));
  1201. }
  1202. //=======================================
  1203. // Setting RFID icon status
  1204. //=======================================
  1205. void setRfidIcon()
  1206. {
  1207. //=======================================
  1208. // AX-Series Generation 1
  1209. //=======================================
  1210. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1211. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
  1212. (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '1'))
  1213. {
  1214. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1215. setDisplayValue(ICON_RFID, RFID_ENABLE);
  1216. else
  1217. setDisplayValue(ICON_RFID, RFID_DISABLE);
  1218. }
  1219. //=======================================
  1220. // AX-Series Generation 2/3/4
  1221. //=======================================
  1222. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1223. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
  1224. ((ShmSysConfigAndInfo->SysConfig.ModelName[11] == '2') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '3') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '4')))
  1225. {
  1226. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1227. setDisplayValue(ICON_RFID, VISA_ENABLE);
  1228. else
  1229. setDisplayValue(ICON_RFID, VISA_DISABLE);
  1230. }
  1231. //=======================================
  1232. // AW-Series Generation
  1233. //=======================================
  1234. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1235. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  1236. {
  1237. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1238. setDisplayValue(ICON_RFID, RFID_ENABLE);
  1239. else
  1240. setDisplayValue(ICON_RFID, RFID_DISABLE);
  1241. }
  1242. }
  1243. //=======================================
  1244. // Setting QRCODE icon status
  1245. //=======================================
  1246. void setQRCodeIcon()
  1247. {
  1248. uint8_t length = 0;
  1249. // QR CODE ( ENABLE / DISABLE )
  1250. if(ShmSysConfigAndInfo->SysConfig.isQRCode == ON)
  1251. {
  1252. setDisplayValue(ICON_QRCODE,QRCODE_ENABLE);
  1253. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
  1254. {
  1255. length = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  1256. setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.SystemId, length, QRCODE_FOR_IDLE);
  1257. }
  1258. else
  1259. {
  1260. length = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  1261. setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, length, QRCODE_FOR_IDLE);
  1262. }
  1263. }
  1264. else
  1265. {
  1266. setDisplayValue(TEXT_QRCODE_CONTENT, DISAPPEAR);
  1267. setDisplayValue(ICON_QRCODE,QRCODE_DISABLE);
  1268. }
  1269. }
  1270. //=======================================
  1271. // Setting QRCODE icon for receipt
  1272. //=======================================
  1273. void setQRCodeReceipt(uint8_t gun_index)
  1274. {
  1275. uint8_t length = 0;
  1276. uint8_t data[128];
  1277. int TransactionId;
  1278. unsigned char QRCodeContent[128];
  1279. unsigned char QRCodeReceipt[128];
  1280. memset(QRCodeReceipt, 0x00, ARRAY_SIZE(QRCodeReceipt));
  1281. memset(QRCodeReceipt, 0x00, ARRAY_SIZE(QRCodeReceipt));
  1282. memset(data, 0x00, ARRAY_SIZE(data));
  1283. strcpy((char*)QRCodeContent, "https://ocpp.phihong.com.tw/CDFA/");
  1284. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  1285. {
  1286. TransactionId = ShmOCPP16Data->StopTransaction[gun_index].TransactionId;
  1287. }
  1288. else
  1289. {}
  1290. sprintf((char *)QRCodeReceipt, "%s%d", QRCodeContent,TransactionId);
  1291. string2ByteArray(QRCodeReceipt, data);
  1292. if(strstr((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, "phihong") && (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  1293. {
  1294. length = strlen((char *)data);
  1295. setQRcodeContent((char *)data, length, QRCODE_FOR_COMPLETE);
  1296. }
  1297. else
  1298. {
  1299. setDisplayValue(TEXT_QRCODE_RECEIPT, DISAPPEAR);
  1300. }
  1301. }
  1302. //=======================================
  1303. // Setting QR code content
  1304. //=======================================
  1305. void setQRcodeContent(char *input, uint8_t length, uint8_t mode)
  1306. {
  1307. uint8_t output[length];
  1308. int loop = 0;
  1309. input[length] = '\0';
  1310. output[length] = '\0';
  1311. while(input[loop] != '\0')
  1312. {
  1313. output[loop] = input[loop];
  1314. loop++;
  1315. }
  1316. switch(mode)
  1317. {
  1318. case QRCODE_FOR_IDLE:
  1319. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
  1320. break;
  1321. case QRCODE_FOR_COMPLETE:
  1322. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_RECEIPT, output, ARRAY_SIZE(output)+1);
  1323. break;
  1324. default:
  1325. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
  1326. break;
  1327. }
  1328. }
  1329. //=======================================
  1330. // Setting warning page switch
  1331. //=======================================
  1332. void setWarningStatus(uint8_t gun_index)
  1333. {
  1334. /*
  1335. * 1. WARNING COUNT IS DIFFERENT BETWEEN BEGINNING CHANGE DISPLAY
  1336. * 2. WARNING COUNT BIGGER THAN 4 AND EVERY 5 SECONDS CHANGE NEXT PAGE
  1337. */
  1338. if(WarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
  1339. {
  1340. WarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
  1341. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1342. setAlarmCodeAndIcon();
  1343. }
  1344. else if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 4 && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_ALARM]) > (TIME_ANIMATION_ALARM)))
  1345. {
  1346. ftime(&startTime[gun_index][TMR_IDX_ALARM]);
  1347. if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
  1348. {
  1349. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
  1350. }
  1351. else
  1352. {
  1353. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1354. }
  1355. setAlarmCodeAndIcon();
  1356. }
  1357. }
  1358. //=======================================
  1359. // Setting alarm code and icon status
  1360. //=======================================
  1361. void setAlarmCodeAndIcon()
  1362. {
  1363. uint8_t cmd[7];
  1364. uint8_t index = 0;
  1365. for(index = 0; (index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; index++)
  1366. {
  1367. memset(cmd, 0x00, sizeof(cmd));
  1368. if(index >= 4)
  1369. {
  1370. break;
  1371. }
  1372. // ALARM CODE TEXT (XXXXXX)
  1373. string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4][0], cmd);
  1374. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
  1375. // ALARM CODE ICON STATUS (!)
  1376. memset(cmd, 0x00, sizeof(cmd));
  1377. cmd[0] = 0x00;
  1378. cmd[1] = 0x01;
  1379. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
  1380. }
  1381. memset(cmd, 0x00, sizeof(cmd));
  1382. for(; index < 4; index++)
  1383. {
  1384. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
  1385. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
  1386. }
  1387. }
  1388. //=======================================
  1389. // Setting Battery icon animation
  1390. //=======================================
  1391. void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode)
  1392. {
  1393. switch(system_mode)
  1394. {
  1395. case SYS_MODE_IDLE:
  1396. // INITIALIZATION BATTERY ICON AND PERCENTAGE TEXT
  1397. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1398. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_EMPTY);
  1399. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1400. break;
  1401. case SYS_MODE_CHARGING:
  1402. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1403. {
  1404. if(isEmulator == YES)
  1405. {
  1406. if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_EMULATOR]) > 3000))
  1407. {
  1408. if(isCharging == YES)
  1409. PERCENTAGE++;
  1410. else
  1411. PERCENTAGE--;
  1412. ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
  1413. }
  1414. if(isCharging == YES)
  1415. {
  1416. if(PERCENTAGE > 100)
  1417. PERCENTAGE = 0;
  1418. }
  1419. else
  1420. {
  1421. if(PERCENTAGE <= 0)
  1422. PERCENTAGE = 100;
  1423. }
  1424. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc = PERCENTAGE;
  1425. if((isChange == 0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
  1426. {
  1427. isChange = 1;
  1428. }
  1429. else if((isChange == 1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
  1430. {
  1431. isChange = 0;
  1432. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1433. }
  1434. }
  1435. else
  1436. {}
  1437. // SET BATTERY ANIMATION
  1438. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1439. {
  1440. if(isChange == 0)
  1441. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1442. else
  1443. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1444. }
  1445. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1446. {
  1447. if(isChange == 0)
  1448. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1449. else
  1450. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1451. }
  1452. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1453. {
  1454. if(isChange == 0)
  1455. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1456. else
  1457. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1458. }
  1459. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1460. {
  1461. if(isChange == 0)
  1462. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1463. else
  1464. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1465. }
  1466. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 100))
  1467. {
  1468. if(isChange == 0)
  1469. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1470. else
  1471. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1472. }
  1473. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc == 100)
  1474. {
  1475. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1476. }
  1477. // SET BATTERY SOC VALUE
  1478. setBatteryPercentageValue(gun_index);
  1479. // SET ICON TO CHARGE OR DISCHARGE
  1480. if(isCharging == YES)
  1481. setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_LEFT);
  1482. else
  1483. setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_RIGHT);
  1484. }
  1485. else
  1486. {
  1487. // SET BATTERY PERCENTAGE TEXT TO DISAPPEAR
  1488. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1489. if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
  1490. {
  1491. // SET BATTERY ANIMATION
  1492. if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
  1493. {
  1494. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1495. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_0;
  1496. }
  1497. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
  1498. {
  1499. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1500. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_1;
  1501. }
  1502. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
  1503. {
  1504. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1505. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_2;
  1506. }
  1507. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_2) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*3)))
  1508. {
  1509. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1510. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_3;
  1511. }
  1512. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_3) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*4)))
  1513. {
  1514. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1515. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_4;
  1516. }
  1517. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_4) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*5)))
  1518. {
  1519. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1520. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1521. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1522. }
  1523. }
  1524. else
  1525. {
  1526. // SET BATTERY ICON TO EMPTY ICON
  1527. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1528. // SET BATTERY PERCENTAGE TO DISAPPEAR
  1529. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1530. // RESET TO DEFAULT VALUE
  1531. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1532. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1533. }
  1534. }
  1535. break;
  1536. case SYS_MODE_TERMINATING:
  1537. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1538. {
  1539. // SET BATTERY ANIMATION
  1540. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1541. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1542. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1543. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1544. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1545. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1546. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1547. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1548. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
  1549. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1550. // SET BATTERY SOC VALUE
  1551. setBatteryPercentageValue(gun_index);
  1552. // SET ELECTRIC ARROW DIRECTION ICON DISAPPEAR
  1553. setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
  1554. }
  1555. else
  1556. {
  1557. // SET BATTERY ICON TO EMPTY ICON
  1558. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1559. // SET BATTERY PERCENTAGE TO DISAPPEAR
  1560. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1561. }
  1562. break;
  1563. case SYS_MODE_COMPLETE:
  1564. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1565. {
  1566. // SET BATTERY ANIMATION
  1567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1568. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_20);
  1569. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1570. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_40);
  1571. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1572. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_60);
  1573. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1574. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_80);
  1575. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
  1576. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
  1577. // SET BATTERY SOC VALUE
  1578. setBatteryPercentageValue(gun_index);
  1579. // SET ELECTRIC ARROW DIRECTION ICON DISAPPEAR
  1580. setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
  1581. }
  1582. else
  1583. {
  1584. // SET BATTERY ICON TO FULL BATTERY ICON
  1585. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
  1586. // SET BATTERY PERCENTAGE TO DISAPPEAR
  1587. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1588. }
  1589. break;
  1590. default:
  1591. break;
  1592. }
  1593. }
  1594. //=======================================
  1595. // Setting connection icon animation
  1596. //=======================================
  1597. void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
  1598. {
  1599. switch(system_mode)
  1600. {
  1601. case SYS_MODE_PREPARING:
  1602. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1603. {
  1604. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
  1605. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1606. }
  1607. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1608. {
  1609. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_2);
  1610. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1611. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1612. }
  1613. break;
  1614. case SYS_MODE_CHARGING:
  1615. if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
  1616. {
  1617. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1618. {
  1619. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
  1620. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1621. }
  1622. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1623. {
  1624. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_2);
  1625. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1626. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1627. }
  1628. }
  1629. else
  1630. {
  1631. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1632. {
  1633. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1634. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1635. }
  1636. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1637. {
  1638. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
  1639. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1640. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1641. }
  1642. }
  1643. break;
  1644. case SYS_MODE_TERMINATING:
  1645. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1646. {
  1647. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1648. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1649. }
  1650. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1651. {
  1652. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
  1653. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1654. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1655. }
  1656. break;
  1657. default:
  1658. break;
  1659. }
  1660. }
  1661. //=======================================
  1662. // Setting gun plug-in animation
  1663. //=======================================
  1664. void setGunPluginAnimation(uint8_t gun_index)
  1665. {
  1666. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) ||
  1667. (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) ||
  1668. (ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON))
  1669. {
  1670. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
  1671. }
  1672. else
  1673. {
  1674. if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN)))
  1675. {
  1676. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
  1677. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_1;
  1678. }
  1679. else if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN*2)))
  1680. {
  1681. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
  1682. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  1683. ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
  1684. }
  1685. }
  1686. }
  1687. //=======================================
  1688. // Setting start button animation
  1689. //=======================================
  1690. void setStartButtonAnimation(uint8_t gun_index)
  1691. {
  1692. if((START_BUTTON_LEVEL_STATUS == START_BUTTON_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_STARTBUTTON]) > (TIME_ANIMATION_START_BUTTON)))
  1693. {
  1694. setDisplayValue(ICON_START_BUTTON, APPEAR);
  1695. START_BUTTON_LEVEL_STATUS = START_BUTTON_LEVEL_1;
  1696. }
  1697. else if((START_BUTTON_LEVEL_STATUS == START_BUTTON_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_STARTBUTTON]) > (TIME_ANIMATION_START_BUTTON*2)))
  1698. {
  1699. setDisplayValue(ICON_START_BUTTON, DISAPPEAR);
  1700. START_BUTTON_LEVEL_STATUS = START_BUTTON_LEVEL_0;
  1701. ftime(&startTime[gun_index][TMR_IDX_STARTBUTTON]);
  1702. }
  1703. }
  1704. //=======================================
  1705. // Setting battery SOC value
  1706. //=======================================
  1707. void setBatteryPercentageValue(uint8_t gun_index)
  1708. {
  1709. uint8_t data[16];
  1710. uint8_t soc[16];
  1711. memset(data, 0x00, ARRAY_SIZE(data));
  1712. memset(soc, 0x00, ARRAY_SIZE(soc));
  1713. sprintf((char *)soc, "%d%%", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc);
  1714. string2ByteArray(soc, data);
  1715. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PERCENTAGE, data, ARRAY_SIZE(data));
  1716. }
  1717. //=======================================
  1718. // Setting present charging power
  1719. //=======================================
  1720. void setPresentChargingPower(uint8_t gun_index)
  1721. {
  1722. uint8_t data[16];
  1723. uint8_t power[16];
  1724. memset(data, 0x00, ARRAY_SIZE(data));
  1725. memset(power, 0x00, ARRAY_SIZE(power));
  1726. sprintf((char *)power, "%.2f kW", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingPower);
  1727. string2ByteArray(power, data);
  1728. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_POWER_CHARGING, data, ARRAY_SIZE(data));
  1729. }
  1730. //=======================================
  1731. // Setting present charged energy
  1732. //=======================================
  1733. void setPresentChargedEnergy(uint8_t gun_index)
  1734. {
  1735. uint8_t data[16];
  1736. uint8_t energy[16];
  1737. memset(data, 0x00, ARRAY_SIZE(data));
  1738. memset(energy, 0x00, ARRAY_SIZE(energy));
  1739. sprintf((char *)energy, "%.4f kWh", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy);
  1740. string2ByteArray(energy, data);
  1741. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ENERGY_CHARGING, data, ARRAY_SIZE(data));
  1742. }
  1743. //=======================================
  1744. // Setting present power consumption
  1745. //=======================================
  1746. void setPresentPowerConsumption(uint8_t gun_index)
  1747. {
  1748. uint8_t data[32];
  1749. uint8_t powerConsumption[32];
  1750. memset(data, 0x00, ARRAY_SIZE(data));
  1751. memset(powerConsumption, 0x00, ARRAY_SIZE(powerConsumption));
  1752. sprintf((char *)powerConsumption, "%.4f kWh", ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
  1753. string2ByteArray(powerConsumption, data);
  1754. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_POWER_CONSUMPTION, data, ARRAY_SIZE(data));
  1755. }
  1756. //=======================================
  1757. // Setting present charged duration
  1758. //=======================================
  1759. void setPresentChargedDuration(uint8_t gun_index)
  1760. {
  1761. uint8_t data[16];
  1762. uint8_t time[16];
  1763. uint16_t hour;
  1764. uint16_t minute;
  1765. uint16_t second;
  1766. uint32_t PresentChargedDuration = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration;
  1767. memset(data, 0x00, ARRAY_SIZE(data));
  1768. memset(time, 0x00, ARRAY_SIZE(time));
  1769. hour = (PresentChargedDuration / 3600);
  1770. minute = (PresentChargedDuration - (3600 * hour)) / 60;
  1771. second = (PresentChargedDuration - (3600 * hour) - (minute * 60));
  1772. sprintf((char *)time, "%02d:%02d:%02d", hour, minute, second);
  1773. string2ByteArray(time, data);
  1774. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_TIMER_CHARGING, data, ARRAY_SIZE(data));
  1775. }
  1776. //=======================================
  1777. // Setting authorization page
  1778. //=======================================
  1779. void setAuthorizationPage(uint8_t gun_index)
  1780. {
  1781. switch(ShmCharger->gun_info[gun_index].resultAuthorization)
  1782. {
  1783. case VALIDATED_RFID:
  1784. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_PASS)
  1785. {
  1786. setCurrentPage(SYSTEM_SCREEN_AUTH_PASS);
  1787. DEBUG_INFO("Setting page to authorizing : Validated RFID.\n");
  1788. }
  1789. else
  1790. {}
  1791. break;
  1792. case UNVALIDATED_RFID:
  1793. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_FAIL)
  1794. {
  1795. setCurrentPage(SYSTEM_SCREEN_AUTH_FAIL);
  1796. DEBUG_INFO("Setting page to authorizing : Unvalidated RFID.\n");
  1797. }
  1798. else
  1799. {}
  1800. break;
  1801. case UNKNOW_RFID:
  1802. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_UNKNOW)
  1803. {
  1804. setCurrentPage(SYSTEM_SCREEN_AUTH_UNKNOW);
  1805. DEBUG_INFO("Setting page to authorizing : Unknown RFID\n");
  1806. }
  1807. else
  1808. {}
  1809. break;
  1810. case DEFAULT_RFID:
  1811. break;
  1812. default:
  1813. break;
  1814. }
  1815. }
  1816. //=======================================
  1817. // Setting default values
  1818. //=======================================
  1819. void setDefaultValue(uint8_t gun_index, uint8_t system_mode)
  1820. {
  1821. switch(system_mode)
  1822. {
  1823. case SYS_MODE_BOOTING:
  1824. break;
  1825. case SYS_MODE_IDLE:
  1826. setBatteryAnimation(gun_index, system_mode);
  1827. break;
  1828. case SYS_MODE_AUTHORIZING:
  1829. break;
  1830. case SYS_MODE_PREPARING:
  1831. // DEFAULT TIMER, ICON AND STATUS OF ANIMATION. ( BS / HLC ) MODE
  1832. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1833. {
  1834. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
  1835. setDisplayValue(ICON_BATTERY_PRECHARGING, BATTERY_CAPACITY_EMPTY);
  1836. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1837. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1838. }
  1839. else
  1840. {
  1841. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
  1842. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  1843. ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
  1844. }
  1845. break;
  1846. case SYS_MODE_CHARGING:
  1847. // DEFAULT TIMER, ICON AND STATUS OF ANIMATION
  1848. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
  1849. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1850. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1851. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1852. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1853. break;
  1854. case SYS_MODE_TERMINATING:
  1855. // DEFAULT TIMER, ICON AND STATUS OF ANIMATION
  1856. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1857. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1858. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1859. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1860. break;
  1861. case SYS_MODE_COMPLETE:
  1862. break;
  1863. case SYS_MODE_ALARM:
  1864. break;
  1865. case SYS_MODE_FAULT:
  1866. break;
  1867. case SYS_MODE_MAINTAIN:
  1868. break;
  1869. case SYS_MODE_UPDATE:
  1870. break;
  1871. case SYS_MODE_RESERVATION:
  1872. break;
  1873. case SYS_MODE_BOOKING:
  1874. break;
  1875. case SYS_MODE_DEBUG:
  1876. break;
  1877. default:
  1878. break;
  1879. }
  1880. }
  1881. //=======================================
  1882. // Setting receipt icon
  1883. //=======================================
  1884. void setReceiptIcon(uint8_t gun_index)
  1885. {
  1886. // DISPLAY FOR QR CODE RECEIPT
  1887. if(strstr((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, "phihong") && (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  1888. {
  1889. setDisplayValue(ICON_THE_CHARGE_COMPLETE, DISAPPEAR);
  1890. setDisplayValue(ICON_CONNECTION_COMPLETE, APPEAR);
  1891. setQRCodeReceipt(gun_index);
  1892. }
  1893. else
  1894. {
  1895. setDisplayValue(ICON_THE_CHARGE_COMPLETE, APPEAR);
  1896. setDisplayValue(ICON_CONNECTION_COMPLETE, APPEAR);
  1897. setQRCodeReceipt(gun_index);
  1898. }
  1899. }
  1900. //=======================================
  1901. // Initial all share memory
  1902. //=======================================
  1903. int InitShareMemory()
  1904. {
  1905. int result = PASS;
  1906. int MeterSMId;
  1907. // Initial ShmSysConfigAndInfo
  1908. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1909. {
  1910. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1911. result = FAIL;
  1912. }
  1913. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1914. {
  1915. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1916. result = FAIL;
  1917. }
  1918. else
  1919. {}
  1920. // Initial ShmStatusCodeData
  1921. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1922. {
  1923. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1924. result = FAIL;
  1925. }
  1926. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1927. {
  1928. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1929. result = FAIL;
  1930. }
  1931. else
  1932. {}
  1933. // Initial ShmCharger
  1934. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  1935. {
  1936. DEBUG_ERROR("shmget ShmChargerKey NG\n");
  1937. result = FAIL;
  1938. }
  1939. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1940. {
  1941. DEBUG_ERROR("shmat ShmChargerKey NG\n");
  1942. result = FAIL;
  1943. }
  1944. // Initial ShmOCPP16Data
  1945. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1946. {
  1947. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  1948. result = FAIL;
  1949. }
  1950. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1951. {
  1952. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  1953. result = FAIL;
  1954. }
  1955. // Initial ShmOCPP20Data
  1956. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  1957. {
  1958. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  1959. result = FAIL;
  1960. }
  1961. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1962. {
  1963. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  1964. result = FAIL;
  1965. }
  1966. return result;
  1967. }
  1968. //=======================================
  1969. // Initial communication port
  1970. //=======================================
  1971. int InitComPort()
  1972. {
  1973. int fd;
  1974. struct termios tios;
  1975. fd = open("/dev/ttyS3", O_RDWR);
  1976. if(fd<=0)
  1977. {
  1978. DEBUG_ERROR("open /dev/ttyS3 NG\n");
  1979. return -1;
  1980. }
  1981. ioctl (fd, TCGETS, &tios);
  1982. tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
  1983. tios.c_lflag = 0;
  1984. tios.c_iflag = 0;
  1985. tios.c_oflag = 0;
  1986. tios.c_cc[VMIN]=0;
  1987. tios.c_cc[VTIME]=(unsigned char)5; // timeout 500ms
  1988. tios.c_lflag=0;
  1989. tcflush(fd, TCIFLUSH);
  1990. ioctl (fd, TCSETS, &tios);
  1991. return fd;
  1992. }
  1993. //=======================================
  1994. // Download image
  1995. //=======================================
  1996. int downloadBMP(uint8_t picIdx, char *filename)
  1997. {
  1998. int result = PASS;
  1999. BMP *bmp;
  2000. struct stat fileSt;
  2001. uint32_t pageSize = 0xf0;
  2002. uint32_t pixelSize;
  2003. uint32_t transferedByte=0;
  2004. uint16_t bufferRamAddr = 0x8000;
  2005. uint32_t dataLen = 0;
  2006. uint32_t startAddr=0;
  2007. // Reset LCD
  2008. uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
  2009. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) != PASS)
  2010. {
  2011. DEBUG_INFO("LCD reset fail.\n");
  2012. }
  2013. sleep(1);
  2014. // Get image file size
  2015. stat(filename, &fileSt);
  2016. bmp = bopen(filename);
  2017. uint8_t buf[bmp->width*bmp->height*2];
  2018. DEBUG_INFO("Target address: %d\n", picIdx);
  2019. DEBUG_INFO("Image filename: %s\n", filename);
  2020. DEBUG_INFO("Image width: %d height: %d\n", bmp->width, bmp->height);
  2021. DEBUG_INFO("Image data size: %d\n", ARRAY_SIZE(buf));
  2022. // Get bmp pixel data and convert to 16 bit color
  2023. for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
  2024. {
  2025. for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
  2026. {
  2027. uint8_t r, g, b;
  2028. get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
  2029. buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
  2030. buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
  2031. }
  2032. }
  2033. bclose(bmp);
  2034. // Transfer pixel to screen page
  2035. pixelSize = ARRAY_SIZE(buf);
  2036. for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
  2037. {
  2038. //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
  2039. //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
  2040. uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
  2041. if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
  2042. {
  2043. // Data transfer
  2044. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, (bufferRamAddr+(dataLen>>1)), &buf[(idxSrcData*pageSize)], pageSize) != PASS)
  2045. {
  2046. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2047. }
  2048. transferedByte += pageSize;
  2049. dataLen += pageSize;
  2050. }
  2051. else
  2052. {
  2053. // Last data transfer
  2054. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, (bufferRamAddr+(dataLen>>1)), &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))) != PASS)
  2055. {
  2056. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2057. }
  2058. transferedByte += (pixelSize-(idxSrcData*pageSize));
  2059. dataLen += (pixelSize-(idxSrcData*pageSize));
  2060. }
  2061. // Move data from ram to flash
  2062. if((dataLen >= (pageSize*10)) || (idxSrcData == (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1)-1))
  2063. {
  2064. display_cmd[3] = ((dataLen>>1) >> 8) & 0xff; // Data length high byte
  2065. display_cmd[4] = ((dataLen>>1) >> 0) & 0xff; // Data length low byte
  2066. display_cmd[5] = (((startAddr)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
  2067. display_cmd[6] = (((startAddr)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
  2068. display_cmd[7] = (((startAddr)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
  2069. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) != PASS)
  2070. {
  2071. DEBUG_INFO("Write data to display buffer 0x%04X fail.\n", transferedByte);
  2072. }
  2073. startAddr += dataLen;
  2074. dataLen = 0;
  2075. }
  2076. }
  2077. // Save image to target address
  2078. uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
  2079. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
  2080. {
  2081. DEBUG_INFO("Save image fail.\n");
  2082. }
  2083. DEBUG_INFO("Save image success.\n");
  2084. sleep(1);
  2085. return result;
  2086. }
  2087. //=======================================
  2088. // Download image
  2089. //=======================================
  2090. int downloadBIN(uint8_t targetAddr, char *filename)
  2091. {
  2092. int result = PASS;
  2093. int fd;
  2094. struct stat fileSt;
  2095. uint32_t pageSize = 128;
  2096. uint32_t blocklSize = 32768;
  2097. uint32_t transferedByte=0;
  2098. uint16_t bufferRamAddr = 0x8000;
  2099. // Reset LCD
  2100. uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
  2101. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) != PASS)
  2102. {
  2103. DEBUG_INFO("LCD reset fail.\n");
  2104. }
  2105. sleep(1);
  2106. // Get image file size
  2107. stat(filename, &fileSt);
  2108. uint8_t buf[(fileSt.st_size%32768==0?(fileSt.st_size/32768)*32768:(fileSt.st_size/32768)+1)*32768];
  2109. DEBUG_INFO("Target address: %d\n", targetAddr);
  2110. DEBUG_INFO("Bin filename: %s\n", filename);
  2111. DEBUG_INFO("Bin data size: %d\n", fileSt.st_size);
  2112. fd = open(filename, O_RDWR);
  2113. if (fd < 0)
  2114. {
  2115. DEBUG_WARN("Bin can not be open.\n");
  2116. result = FAIL;
  2117. }
  2118. else
  2119. {
  2120. // Read data from bin file
  2121. memset(buf, 0x00, ARRAY_SIZE(buf));
  2122. read(fd, buf, ARRAY_SIZE(buf));
  2123. close(fd);
  2124. for(uint8_t idxBinSrc=0;idxBinSrc<(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1);idxBinSrc++)
  2125. {
  2126. // Transfer data to ram
  2127. for(uint16_t idxSrcData=0;idxSrcData<(((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1);idxSrcData++)
  2128. {
  2129. //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxBinSrc*blocklSize)+(idxSrcData*pageSize));
  2130. //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
  2131. if((idxSrcData+1) != (((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1))
  2132. {
  2133. // Data transfer
  2134. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], pageSize) != PASS)
  2135. {
  2136. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2137. }
  2138. transferedByte += pageSize;
  2139. }
  2140. else
  2141. {
  2142. // Last data transfer
  2143. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], (blocklSize-(idxSrcData*pageSize)))!= PASS)
  2144. {
  2145. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2146. }
  2147. transferedByte += (blocklSize-(idxSrcData*pageSize));
  2148. }
  2149. }
  2150. // Move data from ram to flash
  2151. uint8_t save_cmd[] ={0x5a, 0x02, ((((targetAddr*8)+idxBinSrc)>>8)&0xff), ((((targetAddr*8)+idxBinSrc)>>0)&0xff), ((bufferRamAddr>>8)&0xff), ((bufferRamAddr>>0)&0xff), 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
  2152. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xaa, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
  2153. {
  2154. DEBUG_INFO("Save bin file to 0x%04X fail.\n", ((targetAddr*8)+idxBinSrc));
  2155. }
  2156. DEBUG_INFO("Save bin file on 0x%04X success.\n", ((targetAddr*8)+idxBinSrc));
  2157. sleep(1);
  2158. }
  2159. }
  2160. return result;
  2161. }
  2162. //=======================================
  2163. // LCD upgrade
  2164. //=======================================
  2165. int lcdUpgrade(char *forlder)
  2166. {
  2167. int result = PASS;
  2168. DIR *dir;
  2169. struct dirent *file;
  2170. struct stat fileSt;
  2171. if ((dir = opendir (forlder)) != NULL)
  2172. {
  2173. /* print all the files and directories within directory */
  2174. while ((file = readdir (dir)) != NULL)
  2175. {
  2176. if((strlen(file->d_name)>2))
  2177. {
  2178. int targetAddr;
  2179. stat(file->d_name, &fileSt);
  2180. if(sscanf(file->d_name, "%d", &targetAddr) == 1)
  2181. {
  2182. char targetFile[384];
  2183. sprintf(targetFile, "/mnt/lcd/%s", file->d_name);
  2184. if(strstr(file->d_name, ".bmp") != NULL)
  2185. {
  2186. downloadBMP(targetAddr, targetFile);
  2187. }
  2188. else
  2189. {
  2190. downloadBIN(targetAddr, targetFile);
  2191. }
  2192. }
  2193. else
  2194. {
  2195. DEBUG_WARN("%s can not parse target address.\n", file->d_name);
  2196. }
  2197. }
  2198. else
  2199. {
  2200. if(strlen(file->d_name) >= 3)
  2201. {
  2202. DEBUG_ERROR("File name error.\n");
  2203. result = FAIL;
  2204. }
  2205. else
  2206. {
  2207. DEBUG_INFO("Searching file.\n");
  2208. }
  2209. }
  2210. sleep(1);
  2211. }
  2212. closedir (dir);
  2213. }
  2214. else
  2215. {
  2216. DEBUG_ERROR("%s does not valid.\n", forlder);
  2217. result = FAIL;
  2218. }
  2219. return result;
  2220. }
  2221. //=======================================
  2222. // Main process
  2223. //=======================================
  2224. int main(void)
  2225. {
  2226. uint8_t previousMode = 0xff;
  2227. if(InitShareMemory() == FAIL)
  2228. {
  2229. #ifdef SystemLogMessage
  2230. DEBUG_ERROR("InitShareMemory NG\n");
  2231. #endif
  2232. if(ShmStatusCodeData!=NULL)
  2233. {
  2234. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  2235. }
  2236. sleep(5);
  2237. return FAIL;
  2238. }
  2239. Uart1Fd=InitComPort();
  2240. if(Uart1Fd<0)
  2241. {
  2242. #ifdef SystemLogMessage
  2243. DEBUG_ERROR("InitComPort NG\n");
  2244. #endif
  2245. if(ShmStatusCodeData!=NULL)
  2246. {
  2247. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  2248. }
  2249. sleep(5);
  2250. return FAIL;
  2251. }
  2252. else
  2253. {}
  2254. DEBUG_INFO("Initial completed\n");
  2255. DEBUG_INFO("Latest Firmware Version : [%s] \n", FIRMWARE_UPDATE_IMAGE[0]);
  2256. DEBUG_INFO("Latest Upgrade Date : [%s]. \n", FIRMWARE_UPDATE_IMAGE[1]);
  2257. DEBUG_INFO("Latest Image Version : [%s]. \n", FIRMWARE_UPDATE_IMAGE[2]);
  2258. for(;;)
  2259. {
  2260. if(ShmCharger->isUpgradeLcmReq)
  2261. {
  2262. ShmCharger->isUpgradeLcmSuccess = ((lcdUpgrade("/mnt/lcd") == PASS) ? YES : NO);
  2263. ShmCharger->isUpgradeLcmReq = OFF;
  2264. }
  2265. else
  2266. {
  2267. if(previousMode != ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  2268. {
  2269. previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
  2270. }
  2271. if(ShmCharger->isAuthrizing || ShmCharger->isGetAuthResult)
  2272. {
  2273. if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) >= TIME_AUTH_RESULT_TIME)
  2274. ShmCharger->isGetAuthResult = FALSE;
  2275. if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) < TIME_AUTH_RESULT_TIME)
  2276. page_authorizing(ShmCharger->gun_selectd);
  2277. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus == SYS_MODE_IDLE) && (ShmCharger->gun_info[ShmCharger->gun_selectd].resultAuthorization == VALIDATED_RFID))
  2278. page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2279. }
  2280. else
  2281. {
  2282. ftime(&startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]);
  2283. switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  2284. {
  2285. case SYS_MODE_BOOTING:
  2286. page_booting();
  2287. break;
  2288. case SYS_MODE_IDLE:
  2289. page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2290. break;
  2291. case SYS_MODE_AUTHORIZING:
  2292. //page_authorizing(ShmCharger->gun_selectd);
  2293. break;
  2294. case SYS_MODE_PREPARING:
  2295. page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2296. break;
  2297. case SYS_MODE_CHARGING:
  2298. page_charging(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2299. break;
  2300. case SYS_MODE_TERMINATING:
  2301. page_terminating(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2302. break;
  2303. case SYS_MODE_COMPLETE:
  2304. page_complete(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2305. break;
  2306. case SYS_MODE_ALARM:
  2307. page_alarm();
  2308. break;
  2309. case SYS_MODE_FAULT:
  2310. page_fault();
  2311. break;
  2312. case SYS_MODE_MAINTAIN:
  2313. page_maintain();
  2314. break;
  2315. case SYS_MODE_UPDATE:
  2316. page_update();
  2317. break;
  2318. case SYS_MODE_RESERVATION:
  2319. //page_reservation();
  2320. page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2321. break;
  2322. case SYS_MODE_BOOKING:
  2323. page_booking();
  2324. break;
  2325. case SYS_MODE_DEBUG:
  2326. page_debug();
  2327. break;
  2328. default:
  2329. page_unknown();
  2330. break;
  2331. }
  2332. }
  2333. page_header(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2334. page_footer();
  2335. }
  2336. usleep(100000);
  2337. }
  2338. return FAIL;
  2339. }