Module_LcmControl.c 77 KB

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