Module_LcmControl.c 91 KB

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