Module_LcmControl.c 90 KB

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