Module_LcmControl.c 90 KB

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