Module_LcmControl.c 77 KB

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