Module_LcmControl.c 79 KB

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