Module_LcmControl.c 73 KB

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