Module_LcmControl.c 94 KB

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