Module_LcmControl.c 78 KB

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