Module_LcmControl.c 78 KB

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