Module_LcmControl.c 113 KB

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