Module_LcmControl.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363
  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
  653. {
  654. // SET 4G ICON STATUS ( ONLINE OR OFFLINE )
  655. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
  656. {
  657. switch(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled)
  658. {
  659. case DISABLE_4G:
  660. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  661. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  662. break;
  663. case ENABLE_4G:
  664. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
  665. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
  666. else
  667. setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
  668. break;
  669. default:
  670. break;
  671. }
  672. }
  673. // SET WIFI ICON STATUS ( ONLINE OR OFFLINE)
  674. if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
  675. {
  676. switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
  677. {
  678. case DISABLE_WIFI:
  679. setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
  680. setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
  681. break;
  682. case WIFI_STATION:
  683. if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
  684. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  685. else
  686. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
  687. break;
  688. case WIFI_ACCESS_POINT:
  689. setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
  690. break;
  691. default:
  692. break;
  693. }
  694. }
  695. }
  696. }
  697. //=======================================
  698. // Setting billing ( WEB PAGE )
  699. //=======================================
  700. void setBillingFromWebsite()
  701. {
  702. if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
  703. {
  704. setDisplayValue(ICON_PRICE, APPEAR);
  705. struct timeb csuTime;
  706. struct tm *tmCSU;
  707. ftime(&csuTime);
  708. tmCSU = localtime(&csuTime.time);
  709. if(tmCSU->tm_hour <= 23)
  710. {
  711. ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
  712. setPriceFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
  713. }
  714. // CURRENCY UNIT ( 53 COUNTRIES )
  715. if(ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
  716. {
  717. setCurrencyFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  718. }
  719. }
  720. else
  721. {
  722. setDisplayValue(ICON_PRICE, DISAPPEAR);
  723. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  724. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  725. }
  726. }
  727. //=======================================
  728. // Setting currency ( WEB PAGE )
  729. //=======================================
  730. void setCurrencyFromWebsite(uint8_t unit)
  731. {
  732. uint8_t data[16];
  733. uint8_t currency[16];
  734. unsigned char kWh [16];
  735. uint8_t final_currency[16];
  736. memset(data, 0x00, ARRAY_SIZE(data));
  737. memset(currency, 0x00, ARRAY_SIZE(currency));
  738. memset(final_currency, 0x00, ARRAY_SIZE(final_currency));
  739. strcpy((char*)kWh, "/kWh");
  740. memcpy((char*)currency, Currency[unit], 3);
  741. sprintf((char *)final_currency, "%s%s", currency,kWh);
  742. string2ByteArray(final_currency, data);
  743. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, data, ARRAY_SIZE(data));
  744. }
  745. //=======================================
  746. // Setting price ( WEB PAGE )
  747. //=======================================
  748. void setPriceFromWebsite(float monry_rate)
  749. {
  750. uint8_t data[16];
  751. uint8_t price[16];
  752. memset(data, 0x00, ARRAY_SIZE(data));
  753. memset(price, 0x00, ARRAY_SIZE(price));
  754. sprintf((char *)price, "%.2f", monry_rate);
  755. string2ByteArray(price, data);
  756. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, data, ARRAY_SIZE(data));
  757. }
  758. //=======================================
  759. // Setting final cost ( WEB PAGE )
  760. //=======================================
  761. void setPresentFinalCost(float cost)
  762. {
  763. uint8_t data[16];
  764. uint8_t finalCost[16];
  765. memset(data, 0x00, ARRAY_SIZE(data));
  766. memset(finalCost, 0x00, ARRAY_SIZE(finalCost));
  767. sprintf((char *)finalCost, "%.2f", cost);
  768. string2ByteArray(finalCost, data);
  769. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, data, ARRAY_SIZE(data));
  770. }
  771. //=======================================
  772. // Getting final cost ( WEB PAGE )
  773. //=======================================
  774. float getPresentFinalCost(uint8_t gun_index)
  775. {
  776. float result = 0.0f;
  777. for(int idx=0;idx<ARRAY_SIZE(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod);idx++)
  778. {
  779. result += ((ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idx]) * ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idx]);
  780. }
  781. return result;
  782. }
  783. //=======================================
  784. // Setting billing ( BACKEND )
  785. //=======================================
  786. void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
  787. {
  788. if((system("pidof -s OcppBackend > /dev/null") != 0))
  789. {
  790. // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
  791. setDisplayValue(ICON_PRICE, DISAPPEAR);
  792. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  793. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  794. }
  795. else
  796. {
  797. if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
  798. {
  799. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  800. {
  801. if((strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData,"") != 0))
  802. {
  803. if(system_mode == SYS_MODE_IDLE)
  804. {
  805. /*
  806. * 1. SEARCHING DEFAULT PRICE FOR PRICE TEXT
  807. * 2. SEARCHING DEFAULT PRICE FOR CURRENCY AND UNIT TO APPEAR
  808. */
  809. setDefaultPrice(CURRENT_RATE);
  810. setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
  811. }
  812. else
  813. {
  814. /*
  815. * 1. IF STARTUSERID IS NOT MATCH WITH IDTOKEN ALSO VALUE CAN'T BE NULL, OTHERWISE THE SYSTEM MUST USE DEFAULT PRICE
  816. */
  817. if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
  818. ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
  819. {
  820. /*
  821. * 1. SEARCHING USER PRICE FOR PRICE TEXT
  822. * 2. SEARCHING USER PRICE FOR URRENCY AND UNIT TO APPEAR
  823. */
  824. setUserPrice(CURRENT_RATE);
  825. setCurrencyAndUnitFromBackend(SET_USER_PRICE, CURRENT_RATE,gun_index);
  826. }
  827. else
  828. {
  829. /*
  830. * 1. SEARCHING DEFAULT PRICE FOR PRICE TEXT
  831. * 2. SEARCHING DEFAULT PRICE FOR CURRENCY AND UNIT TO APPEAR
  832. */
  833. setDefaultPrice(CURRENT_RATE);
  834. setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
  835. }
  836. }
  837. }
  838. else
  839. {
  840. // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
  841. setDisplayValue(ICON_PRICE, DISAPPEAR);
  842. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  843. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  844. }
  845. }
  846. else
  847. {
  848. // DISPLAY BY OCPP 2.0.1
  849. }
  850. }
  851. else
  852. {
  853. // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
  854. setDisplayValue(ICON_PRICE, DISAPPEAR);
  855. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  856. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  857. }
  858. }
  859. }
  860. //=======================================
  861. // Setting UserPrice ( BACKEND )
  862. //=======================================
  863. void setUserPrice(uint8_t type)
  864. {
  865. uint8_t length;
  866. uint8_t output_data[32];
  867. char input_data[32];
  868. char tmp[256];
  869. char *splitString[10];
  870. const char *Symbol = ";";
  871. memset(tmp, 0, ARRAY_SIZE(tmp));
  872. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  873. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  874. switch(type)
  875. {
  876. case CONNECTION_FEE:
  877. break;
  878. case CURRENT_RATE:
  879. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
  880. {
  881. // APPEAR PRICE ICON
  882. setDisplayValue(ICON_PRICE, APPEAR);
  883. // APPEAR PRICE TEXT
  884. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  885. split((char**)splitString, tmp, Symbol);
  886. memcpy(input_data, splitString[1], strlen(splitString[1]));
  887. length = strlen(input_data);
  888. trim_string(input_data,length);
  889. memcpy(output_data ,input_data, strlen(input_data));
  890. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
  891. }
  892. else
  893. {
  894. // DISAPPEAR PRICE ICON AND PRICE TEXT
  895. setDisplayValue(ICON_PRICE, DISAPPEAR);
  896. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  897. }
  898. break;
  899. case OCCUPANCY_FEE:
  900. break;
  901. case ACCOUNT_BALANCE:
  902. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Account Balance:") > 0)
  903. {
  904. // APPEAR ACCOUNT BALANCE ICON
  905. setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
  906. // APPEAR ACCOUNT BALANCE TEXT
  907. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  908. split((char**)splitString, tmp, Symbol);
  909. memcpy(input_data, splitString[3], strlen(splitString[3]));
  910. length = strlen(input_data);
  911. trim_string(input_data,length);
  912. memcpy(output_data ,input_data, strlen(input_data));
  913. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
  914. }
  915. else
  916. {
  917. // DISAPPEAR BALANCE ICON AND BALANCE TEXT
  918. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  919. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  920. }
  921. break;
  922. default:
  923. break;
  924. }
  925. }
  926. //=======================================
  927. // Setting DefaultPrice ( BACKEND )
  928. //=======================================
  929. void setDefaultPrice(uint8_t type)
  930. {
  931. uint8_t length;
  932. uint8_t output_data[32];
  933. char input_data[32];
  934. char tmp[256];
  935. char *splitString[10];
  936. const char *Symbol = ";";
  937. memset(tmp, 0, ARRAY_SIZE(tmp));
  938. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  939. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  940. switch(type)
  941. {
  942. case CONNECTION_FEE:
  943. break;
  944. case CURRENT_RATE:
  945. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
  946. {
  947. // APPEAR PRICE ICON
  948. setDisplayValue(ICON_PRICE, APPEAR);
  949. // APPEAR PRICE TEXT
  950. strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  951. split((char**)splitString, tmp, Symbol);
  952. memcpy(input_data, splitString[1], strlen(splitString[1]));
  953. length = strlen(input_data);
  954. trim_string(input_data,length);
  955. memcpy(output_data ,input_data, strlen(input_data));
  956. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
  957. }
  958. else
  959. {
  960. setDisplayValue(TEXT_PRICE, DISAPPEAR);
  961. setDisplayValue(ICON_PRICE, DISAPPEAR);
  962. }
  963. break;
  964. case OCCUPANCY_FEE:
  965. break;
  966. default:
  967. break;
  968. }
  969. }
  970. //=======================================
  971. // Setting FinalCost ( BACKEND )
  972. //=======================================
  973. void setFinalCost(uint8_t gun_index, uint8_t type)
  974. {
  975. uint8_t length;
  976. uint8_t output_data[32];
  977. char input_data[32];
  978. char tmp[256];
  979. char *splitString[10];
  980. const char *Symbol = ";";
  981. memset(tmp, 0, ARRAY_SIZE(tmp));
  982. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  983. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  984. switch(type)
  985. {
  986. case CONNECTION_FEE:
  987. break;
  988. case SESSION_FEE:
  989. break;
  990. case OCCUPANCY_FEE:
  991. break;
  992. case TOTAL_COST:
  993. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Total Cost:") > 0))
  994. {
  995. // APPEAR COST ICON
  996. setDisplayValue(ICON_COST_COMPLETE, APPEAR);
  997. // APPEAR COST TEXT
  998. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  999. split((char**)splitString, tmp, Symbol);
  1000. memcpy(input_data, splitString[3], strlen(splitString[3]));
  1001. length = strlen(input_data);
  1002. trim_string(input_data,length);
  1003. memcpy(output_data ,input_data, strlen(input_data));
  1004. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1005. }
  1006. else
  1007. {
  1008. // DISAPPEAR COST ICON AND COST TEXT
  1009. setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
  1010. setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
  1011. }
  1012. break;
  1013. case ACCOUNT_BALANCE:
  1014. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
  1015. {
  1016. // APPEAR BALANCE ICON
  1017. setDisplayValue(ICON_WALLER_COMPLETE, APPEAR);
  1018. setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
  1019. // APPEAR BALANCE TEXT
  1020. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  1021. split((char**)splitString, tmp, Symbol);
  1022. memcpy(input_data, splitString[4], strlen(splitString[4]));
  1023. length = strlen(input_data);
  1024. trim_string(input_data,length);
  1025. memcpy(output_data ,input_data, strlen(input_data));
  1026. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ACCOUNT_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1027. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
  1028. }
  1029. else
  1030. {
  1031. /*
  1032. * 1. DISAPPEAR ACCOUNT BALANCE WHEN THE SYSTEM IS COMPLETE MODE
  1033. * 2. DISAPPEAR ACCOUNT ICON WHEN THE SYSTEM IS COMPLETE MODE
  1034. */
  1035. setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
  1036. setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
  1037. setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
  1038. setDisplayValue(TEXT_BALANCE, DISAPPEAR);
  1039. }
  1040. break;
  1041. default:
  1042. break;
  1043. }
  1044. }
  1045. //=======================================
  1046. // Setting currency ( BACKEND )
  1047. //=======================================
  1048. void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_unit,uint8_t gun_index)
  1049. {
  1050. uint8_t length;
  1051. uint8_t output_data[32];
  1052. char input_data[32];
  1053. char tmp[256];
  1054. char *splitString[10];
  1055. const char *Symbol = ";";
  1056. memset(tmp, 0, ARRAY_SIZE(tmp));
  1057. memset(input_data, 0x00, ARRAY_SIZE(input_data));
  1058. memset(output_data, 0x00, ARRAY_SIZE(output_data));
  1059. if(type_price == DEFAULE_PRICE)
  1060. {
  1061. switch(type_currency_unit)
  1062. {
  1063. case CONNECTION_FEE:
  1064. break;
  1065. case CURRENT_RATE:
  1066. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
  1067. {
  1068. strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  1069. split((char**)splitString, tmp, Symbol);
  1070. memcpy(input_data, splitString[1], strlen(splitString[1]));
  1071. length = strlen(input_data);
  1072. memcpy(output_data , input_data+(length-7), 7);
  1073. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
  1074. }
  1075. else
  1076. {
  1077. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  1078. }
  1079. break;
  1080. case OCCUPANCY_FEE:
  1081. break;
  1082. default:
  1083. break;
  1084. }
  1085. }
  1086. else if(type_price == SET_USER_PRICE)
  1087. {
  1088. switch(type_currency_unit)
  1089. {
  1090. case CONNECTION_FEE:
  1091. break;
  1092. case CURRENT_RATE:
  1093. if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
  1094. {
  1095. strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
  1096. split((char**)splitString, tmp, Symbol);
  1097. memcpy(input_data, splitString[1], strlen(splitString[1]));
  1098. length = strlen(input_data);
  1099. memcpy(output_data , input_data+(length-7), 7);
  1100. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
  1101. }
  1102. else
  1103. {
  1104. setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
  1105. }
  1106. break;
  1107. case OCCUPANCY_FEE:
  1108. break;
  1109. case ACCOUNT_BALANCE:
  1110. break;
  1111. default:
  1112. break;
  1113. }
  1114. }
  1115. else if(type_price == FINAL_COST)
  1116. {
  1117. switch(type_currency_unit)
  1118. {
  1119. case CONNECTION_FEE:
  1120. break;
  1121. case SESSION_FEE:
  1122. break;
  1123. case OCCUPANCY_FEE:
  1124. break;
  1125. case TOTAL_COST:
  1126. break;
  1127. case ACCOUNT_BALANCE:
  1128. if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
  1129. {
  1130. strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
  1131. split((char**)splitString, tmp, Symbol);
  1132. memcpy(input_data, splitString[4], strlen(splitString[4]));
  1133. length = strlen(input_data);
  1134. memcpy(output_data , input_data+(length-3), 3);
  1135. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_COMPLETE, output_data, ARRAY_SIZE(output_data));
  1136. }
  1137. else
  1138. {
  1139. setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
  1140. }
  1141. break;
  1142. default:
  1143. break;
  1144. }
  1145. }
  1146. else
  1147. {}
  1148. }
  1149. //=======================================
  1150. // Setting RTC value
  1151. //=======================================
  1152. void setRTC()
  1153. {
  1154. uint8_t data[32];
  1155. uint8_t rtc[32];
  1156. memset(data, 0x00, ARRAY_SIZE(data));
  1157. memset(rtc, 0x00, ARRAY_SIZE(rtc));
  1158. getDateTimeString((char*)rtc);
  1159. string2ByteArray(rtc, data);
  1160. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_RTC, data, ARRAY_SIZE(data));
  1161. }
  1162. //=======================================
  1163. // Setting RFID icon status
  1164. //=======================================
  1165. void setRfidIcon()
  1166. {
  1167. //=======================================
  1168. // AX-Series Generation 1
  1169. //=======================================
  1170. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1171. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
  1172. (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '1'))
  1173. {
  1174. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1175. setDisplayValue(ICON_RFID, RFID_ENABLE);
  1176. else
  1177. setDisplayValue(ICON_RFID, RFID_DISABLE);
  1178. }
  1179. //=======================================
  1180. // AX-Series Generation 2/3/4
  1181. //=======================================
  1182. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1183. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
  1184. ((ShmSysConfigAndInfo->SysConfig.ModelName[11] == '2') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '3') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '4')))
  1185. {
  1186. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1187. setDisplayValue(ICON_RFID, VISA_ENABLE);
  1188. else
  1189. setDisplayValue(ICON_RFID, VISA_DISABLE);
  1190. }
  1191. //=======================================
  1192. // AW-Series Generation
  1193. //=======================================
  1194. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
  1195. (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  1196. {
  1197. if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
  1198. setDisplayValue(ICON_RFID, RFID_ENABLE);
  1199. else
  1200. setDisplayValue(ICON_RFID, RFID_DISABLE);
  1201. }
  1202. }
  1203. //=======================================
  1204. // Setting QRCODE icon status
  1205. //=======================================
  1206. void setQRCodeIcon()
  1207. {
  1208. uint8_t length = 0;
  1209. // QR CODE ( ENABLE / DISABLE )
  1210. if(ShmSysConfigAndInfo->SysConfig.isQRCode == ON)
  1211. {
  1212. setDisplayValue(ICON_QRCODE,QRCODE_ENABLE);
  1213. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
  1214. {
  1215. length = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
  1216. setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.SystemId, length);
  1217. }
  1218. else
  1219. {
  1220. length = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  1221. setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, length);
  1222. }
  1223. }
  1224. else
  1225. {
  1226. setDisplayValue(TEXT_QRCODE_CONTENT, DISAPPEAR);
  1227. setDisplayValue(ICON_QRCODE,QRCODE_DISABLE);
  1228. }
  1229. }
  1230. //=======================================
  1231. // Setting QR code content
  1232. //=======================================
  1233. void setQRcodeContent(char *input, uint8_t length)
  1234. {
  1235. uint8_t output[length];
  1236. int loop = 0;
  1237. input[length] = '\0';
  1238. output[length] = '\0';
  1239. while(input[loop] != '\0')
  1240. {
  1241. output[loop] = input[loop];
  1242. loop++;
  1243. }
  1244. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
  1245. }
  1246. //=======================================
  1247. // Setting warning page switch
  1248. //=======================================
  1249. void setWarningStatus(uint8_t gun_index)
  1250. {
  1251. /*
  1252. * 1. WARNING COUNT IS DIFFERENT BETWEEN BEGINNING CHANGE DISPLAY
  1253. * 2. WARNING COUNT BIGGER THAN 4 AND EVERY 5 SECONDS CHANGE NEXT PAGE
  1254. */
  1255. if(WarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
  1256. {
  1257. WarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
  1258. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1259. setAlarmCodeAndIcon();
  1260. }
  1261. else if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 4 && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_ALARM]) > (TIME_ANIMATION_ALARM)))
  1262. {
  1263. ftime(&startTime[gun_index][TMR_IDX_ALARM]);
  1264. if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
  1265. {
  1266. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
  1267. }
  1268. else
  1269. {
  1270. ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
  1271. }
  1272. setAlarmCodeAndIcon();
  1273. }
  1274. }
  1275. //=======================================
  1276. // Setting alarm code and icon status
  1277. //=======================================
  1278. void setAlarmCodeAndIcon()
  1279. {
  1280. uint8_t cmd[7];
  1281. uint8_t index = 0;
  1282. for(index = 0; (index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; index++)
  1283. {
  1284. memset(cmd, 0x00, sizeof(cmd));
  1285. if(index >= 4)
  1286. {
  1287. break;
  1288. }
  1289. // ALARM CODE TEXT (XXXXXX)
  1290. string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4][0], cmd);
  1291. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
  1292. // ALARM CODE ICON STATUS (!)
  1293. memset(cmd, 0x00, sizeof(cmd));
  1294. cmd[0] = 0x00;
  1295. cmd[1] = 0x01;
  1296. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
  1297. }
  1298. memset(cmd, 0x00, sizeof(cmd));
  1299. for(; index < 4; index++)
  1300. {
  1301. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
  1302. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
  1303. }
  1304. }
  1305. //=======================================
  1306. // Setting Battery icon animation
  1307. //=======================================
  1308. void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode)
  1309. {
  1310. switch(system_mode)
  1311. {
  1312. case SYS_MODE_IDLE:
  1313. // INITIALIZATION BATTERY ICON AND PERCENTAGE TEXT
  1314. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1315. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_EMPTY);
  1316. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1317. break;
  1318. case SYS_MODE_CHARGING:
  1319. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1320. {
  1321. if(isEmulator == YES)
  1322. {
  1323. if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_EMULATOR]) > 3000))
  1324. {
  1325. if(isCharging == YES)
  1326. PERCENTAGE++;
  1327. else
  1328. PERCENTAGE--;
  1329. ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
  1330. }
  1331. if(isCharging == YES)
  1332. {
  1333. if(PERCENTAGE > 100)
  1334. PERCENTAGE = 0;
  1335. }
  1336. else
  1337. {
  1338. if(PERCENTAGE <= 0)
  1339. PERCENTAGE = 100;
  1340. }
  1341. ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc = PERCENTAGE;
  1342. if((isChange == 0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
  1343. {
  1344. isChange = 1;
  1345. }
  1346. else if((isChange == 1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
  1347. {
  1348. isChange = 0;
  1349. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1350. }
  1351. }
  1352. else
  1353. {}
  1354. // SET BATTERY ANIMATION
  1355. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1356. {
  1357. if(isChange == 0)
  1358. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1359. else
  1360. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1361. }
  1362. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1363. {
  1364. if(isChange == 0)
  1365. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1366. else
  1367. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1368. }
  1369. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1370. {
  1371. if(isChange == 0)
  1372. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1373. else
  1374. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1375. }
  1376. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1377. {
  1378. if(isChange == 0)
  1379. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1380. else
  1381. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1382. }
  1383. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 100))
  1384. {
  1385. if(isChange == 0)
  1386. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1387. else
  1388. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1389. }
  1390. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc == 100)
  1391. {
  1392. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1393. }
  1394. // SET BATTERY SOC VALUE
  1395. setBatteryPercentageValue(gun_index);
  1396. // SET ICON TO CHARGE OR DISCHARGE
  1397. if(isCharging == YES)
  1398. setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_LEFT);
  1399. else
  1400. setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_RIGHT);
  1401. }
  1402. else
  1403. {
  1404. // SET BATTERY PERCENTAGE TEXT TO DISAPPEAR
  1405. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1406. if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
  1407. {
  1408. // SET BATTERY ANIMATION
  1409. if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
  1410. {
  1411. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1412. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_0;
  1413. }
  1414. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
  1415. {
  1416. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1417. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_1;
  1418. }
  1419. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
  1420. {
  1421. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1422. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_2;
  1423. }
  1424. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_2) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*3)))
  1425. {
  1426. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1427. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_3;
  1428. }
  1429. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_3) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*4)))
  1430. {
  1431. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1432. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_4;
  1433. }
  1434. else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_4) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*5)))
  1435. {
  1436. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1437. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1438. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1439. }
  1440. }
  1441. else
  1442. {
  1443. // SET BATTERY ICON TO EMPTY ICON
  1444. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1445. // SET BATTERY PERCENTAGE TO DISAPPEAR
  1446. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1447. // RESET TO DEFAULT VALUE
  1448. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1449. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1450. }
  1451. }
  1452. break;
  1453. case SYS_MODE_TERMINATING:
  1454. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1455. {
  1456. // SET BATTERY ANIMATION
  1457. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1458. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
  1459. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1460. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
  1461. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1462. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
  1463. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1464. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
  1465. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
  1466. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
  1467. // SET BATTERY SOC VALUE
  1468. setBatteryPercentageValue(gun_index);
  1469. // SET ELECTRIC ARROW DIRECTION ICON DISAPPEAR
  1470. setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
  1471. }
  1472. else
  1473. {
  1474. // SET BATTERY ICON TO EMPTY ICON
  1475. setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
  1476. // SET BATTERY PERCENTAGE TO DISAPPEAR
  1477. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1478. }
  1479. break;
  1480. case SYS_MODE_COMPLETE:
  1481. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1482. {
  1483. // SET BATTERY ANIMATION
  1484. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
  1485. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_20);
  1486. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
  1487. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_40);
  1488. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
  1489. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_60);
  1490. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
  1491. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_80);
  1492. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
  1493. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
  1494. // SET BATTERY SOC VALUE
  1495. setBatteryPercentageValue(gun_index);
  1496. // SET ELECTRIC ARROW DIRECTION ICON DISAPPEAR
  1497. setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
  1498. }
  1499. else
  1500. {
  1501. // SET BATTERY ICON TO FULL BATTERY ICON
  1502. setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
  1503. // SET BATTERY PERCENTAGE TO DISAPPEAR
  1504. setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
  1505. }
  1506. break;
  1507. default:
  1508. break;
  1509. }
  1510. }
  1511. //=======================================
  1512. // Setting connection icon animation
  1513. //=======================================
  1514. void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
  1515. {
  1516. switch(system_mode)
  1517. {
  1518. case SYS_MODE_PREPARING:
  1519. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1520. {
  1521. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
  1522. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1523. }
  1524. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1525. {
  1526. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_2);
  1527. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1528. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1529. }
  1530. break;
  1531. case SYS_MODE_CHARGING:
  1532. if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
  1533. {
  1534. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1535. {
  1536. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
  1537. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1538. }
  1539. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1540. {
  1541. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_2);
  1542. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1543. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1544. }
  1545. }
  1546. else
  1547. {
  1548. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1549. {
  1550. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1551. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1552. }
  1553. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1554. {
  1555. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
  1556. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1557. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1558. }
  1559. }
  1560. break;
  1561. case SYS_MODE_TERMINATING:
  1562. if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
  1563. {
  1564. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1565. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
  1566. }
  1567. else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
  1568. {
  1569. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
  1570. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1571. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1572. }
  1573. break;
  1574. default:
  1575. break;
  1576. }
  1577. }
  1578. //=======================================
  1579. // Setting gun plug-in animation
  1580. //=======================================
  1581. void setGunPluginAnimation(uint8_t gun_index)
  1582. {
  1583. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) ||
  1584. (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) ||
  1585. (ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON))
  1586. {
  1587. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
  1588. }
  1589. else
  1590. {
  1591. if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN)))
  1592. {
  1593. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
  1594. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_1;
  1595. }
  1596. else if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN*2)))
  1597. {
  1598. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
  1599. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  1600. ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
  1601. }
  1602. }
  1603. }
  1604. //=======================================
  1605. // Setting battery SOC value
  1606. //=======================================
  1607. void setBatteryPercentageValue(uint8_t gun_index)
  1608. {
  1609. uint8_t data[16];
  1610. uint8_t soc[16];
  1611. memset(data, 0x00, ARRAY_SIZE(data));
  1612. memset(soc, 0x00, ARRAY_SIZE(soc));
  1613. sprintf((char *)soc, "%d%%", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc);
  1614. string2ByteArray(soc, data);
  1615. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PERCENTAGE, data, ARRAY_SIZE(data));
  1616. }
  1617. //=======================================
  1618. // Setting present charging power
  1619. //=======================================
  1620. void setPresentChargingPower(uint8_t gun_index)
  1621. {
  1622. uint8_t data[16];
  1623. uint8_t power[16];
  1624. memset(data, 0x00, ARRAY_SIZE(data));
  1625. memset(power, 0x00, ARRAY_SIZE(power));
  1626. sprintf((char *)power, "%.2f kW", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingPower);
  1627. string2ByteArray(power, data);
  1628. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_POWER_CHARGING, data, ARRAY_SIZE(data));
  1629. }
  1630. //=======================================
  1631. // Setting present charged energy
  1632. //=======================================
  1633. void setPresentChargedEnergy(uint8_t gun_index)
  1634. {
  1635. uint8_t data[16];
  1636. uint8_t energy[16];
  1637. memset(data, 0x00, ARRAY_SIZE(data));
  1638. memset(energy, 0x00, ARRAY_SIZE(energy));
  1639. sprintf((char *)energy, "%.4f kWh", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy);
  1640. string2ByteArray(energy, data);
  1641. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ENERGY_CHARGING, data, ARRAY_SIZE(data));
  1642. }
  1643. //=======================================
  1644. // Setting present charged duration
  1645. //=======================================
  1646. void setPresentChargedDuration(uint8_t gun_index)
  1647. {
  1648. uint8_t data[16];
  1649. uint8_t time[16];
  1650. uint16_t hour;
  1651. uint16_t minute;
  1652. uint16_t second;
  1653. uint32_t PresentChargedDuration = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration;
  1654. memset(data, 0x00, ARRAY_SIZE(data));
  1655. memset(time, 0x00, ARRAY_SIZE(time));
  1656. hour = (PresentChargedDuration / 3600);
  1657. minute = (PresentChargedDuration - (3600 * hour)) / 60;
  1658. second = (PresentChargedDuration - (3600 * hour) - (minute * 60));
  1659. sprintf((char *)time, "%02d:%02d:%02d", hour, minute, second);
  1660. string2ByteArray(time, data);
  1661. lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_TIMER_CHARGING, data, ARRAY_SIZE(data));
  1662. }
  1663. //=======================================
  1664. // Setting authorization page
  1665. //=======================================
  1666. void setAuthorizationPage(uint8_t gun_index)
  1667. {
  1668. switch(ShmCharger->gun_info[gun_index].resultAuthorization)
  1669. {
  1670. case VALIDATED_RFID:
  1671. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_PASS)
  1672. {
  1673. setCurrentPage(SYSTEM_SCREEN_AUTH_PASS);
  1674. DEBUG_INFO("Setting page to authorizing : Validated RFID.\n");
  1675. }
  1676. else
  1677. {}
  1678. break;
  1679. case UNVALIDATED_RFID:
  1680. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_FAIL)
  1681. {
  1682. setCurrentPage(SYSTEM_SCREEN_AUTH_FAIL);
  1683. DEBUG_INFO("Setting page to authorizing : Unvalidated RFID.\n");
  1684. }
  1685. else
  1686. {}
  1687. break;
  1688. case UNKNOW_RFID:
  1689. if(getCurrentPage() != SYSTEM_SCREEN_AUTH_UNKNOW)
  1690. {
  1691. setCurrentPage(SYSTEM_SCREEN_AUTH_UNKNOW);
  1692. DEBUG_INFO("Setting page to authorizing : Unknown RFID\n");
  1693. }
  1694. else
  1695. {}
  1696. break;
  1697. case DEFAULT_RFID:
  1698. break;
  1699. default:
  1700. break;
  1701. }
  1702. }
  1703. //=======================================
  1704. // Setting default values
  1705. //=======================================
  1706. void setDefaultValue(uint8_t gun_index, uint8_t system_mode)
  1707. {
  1708. switch(system_mode)
  1709. {
  1710. case SYS_MODE_BOOTING:
  1711. break;
  1712. case SYS_MODE_IDLE:
  1713. setBatteryAnimation(gun_index, system_mode);
  1714. break;
  1715. case SYS_MODE_AUTHORIZING:
  1716. break;
  1717. case SYS_MODE_PREPARING:
  1718. // DEFAULT TIMER, ICON AND STATUS OF ANIMATION. ( BS / HLC ) MODE
  1719. if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
  1720. {
  1721. setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
  1722. setDisplayValue(ICON_BATTERY_PRECHARGING, BATTERY_CAPACITY_EMPTY);
  1723. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1724. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1725. }
  1726. else
  1727. {
  1728. setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
  1729. GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
  1730. ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
  1731. }
  1732. break;
  1733. case SYS_MODE_CHARGING:
  1734. // DEFAULT TIMER, ICON AND STATUS OF ANIMATION
  1735. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
  1736. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1737. ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
  1738. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1739. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1740. break;
  1741. case SYS_MODE_TERMINATING:
  1742. // DEFAULT TIMER, ICON AND STATUS OF ANIMATION
  1743. setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
  1744. ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
  1745. CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
  1746. BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
  1747. break;
  1748. case SYS_MODE_COMPLETE:
  1749. break;
  1750. case SYS_MODE_ALARM:
  1751. break;
  1752. case SYS_MODE_FAULT:
  1753. break;
  1754. case SYS_MODE_MAINTAIN:
  1755. break;
  1756. case SYS_MODE_UPDATE:
  1757. break;
  1758. case SYS_MODE_RESERVATION:
  1759. break;
  1760. case SYS_MODE_BOOKING:
  1761. break;
  1762. case SYS_MODE_DEBUG:
  1763. break;
  1764. default:
  1765. break;
  1766. }
  1767. }
  1768. //=======================================
  1769. // Initial all share memory
  1770. //=======================================
  1771. int InitShareMemory()
  1772. {
  1773. int result = PASS;
  1774. int MeterSMId;
  1775. // Initial ShmSysConfigAndInfo
  1776. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1777. {
  1778. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1779. result = FAIL;
  1780. }
  1781. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1782. {
  1783. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1784. result = FAIL;
  1785. }
  1786. else
  1787. {}
  1788. // Initial ShmStatusCodeData
  1789. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1790. {
  1791. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1792. result = FAIL;
  1793. }
  1794. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1795. {
  1796. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1797. result = FAIL;
  1798. }
  1799. else
  1800. {}
  1801. // Initial ShmCharger
  1802. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  1803. {
  1804. DEBUG_ERROR("shmget ShmChargerKey NG\n");
  1805. result = FAIL;
  1806. }
  1807. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1808. {
  1809. DEBUG_ERROR("shmat ShmChargerKey NG\n");
  1810. result = FAIL;
  1811. }
  1812. // Initial ShmOCPP16Data
  1813. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1814. {
  1815. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  1816. result = FAIL;
  1817. }
  1818. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1819. {
  1820. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  1821. result = FAIL;
  1822. }
  1823. // Initial ShmOCPP20Data
  1824. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  1825. {
  1826. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  1827. result = FAIL;
  1828. }
  1829. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1830. {
  1831. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  1832. result = FAIL;
  1833. }
  1834. return result;
  1835. }
  1836. //=======================================
  1837. // Initial communication port
  1838. //=======================================
  1839. int InitComPort()
  1840. {
  1841. int fd;
  1842. struct termios tios;
  1843. fd = open("/dev/ttyS3", O_RDWR);
  1844. if(fd<=0)
  1845. {
  1846. DEBUG_ERROR("open /dev/ttyS3 NG\n");
  1847. return -1;
  1848. }
  1849. ioctl (fd, TCGETS, &tios);
  1850. tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
  1851. tios.c_lflag = 0;
  1852. tios.c_iflag = 0;
  1853. tios.c_oflag = 0;
  1854. tios.c_cc[VMIN]=0;
  1855. tios.c_cc[VTIME]=(unsigned char)5; // timeout 500ms
  1856. tios.c_lflag=0;
  1857. tcflush(fd, TCIFLUSH);
  1858. ioctl (fd, TCSETS, &tios);
  1859. return fd;
  1860. }
  1861. //=======================================
  1862. // Download image
  1863. //=======================================
  1864. int downloadBMP(uint8_t picIdx, char *filename)
  1865. {
  1866. int result = PASS;
  1867. BMP *bmp;
  1868. struct stat fileSt;
  1869. uint32_t pageSize = 0xf0;
  1870. uint32_t pixelSize;
  1871. uint32_t transferedByte=0;
  1872. uint16_t bufferRamAddr = 0x8000;
  1873. // Reset LCD
  1874. uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
  1875. if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
  1876. {
  1877. DEBUG_INFO("LCD reset fail.\n");
  1878. }
  1879. // Get image file size
  1880. stat(filename, &fileSt);
  1881. bmp = bopen(filename);
  1882. uint8_t buf[bmp->width*bmp->height*2];
  1883. DEBUG_INFO("Image filename: %s\n", filename);
  1884. DEBUG_INFO("Image width: %d height: %d\n", bmp->width, bmp->height);
  1885. DEBUG_INFO("Image data size: %d\n", ARRAY_SIZE(buf));
  1886. // Get bmp pixel data and convert to 16 bit color
  1887. for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
  1888. {
  1889. for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
  1890. {
  1891. uint8_t r, g, b;
  1892. get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
  1893. buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
  1894. buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
  1895. }
  1896. }
  1897. bclose(bmp);
  1898. // Transfer pixel to screen page
  1899. pixelSize = ARRAY_SIZE(buf);
  1900. for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
  1901. {
  1902. //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
  1903. //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
  1904. uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
  1905. if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
  1906. {
  1907. // Data transfer
  1908. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], pageSize) != PASS)
  1909. {
  1910. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  1911. }
  1912. transferedByte += pageSize;
  1913. display_cmd[3] = ((pageSize>>1) >> 8) & 0xff; // Data length high byte
  1914. display_cmd[4] = ((pageSize>>1) >> 0) & 0xff; // Data length low byte
  1915. display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
  1916. display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
  1917. display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
  1918. }
  1919. else
  1920. {
  1921. // Last data transfer
  1922. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))) != PASS)
  1923. {
  1924. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  1925. }
  1926. transferedByte += (pixelSize-(idxSrcData*pageSize));
  1927. display_cmd[3] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 8) & 0xff; // Data length high byte
  1928. display_cmd[4] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 0) & 0xff; // Data length low byte
  1929. display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
  1930. display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
  1931. display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
  1932. }
  1933. // Move data from ram to flash
  1934. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) != PASS)
  1935. {
  1936. DEBUG_INFO("Write data to display buffer 0x%04X fail.\n", transferedByte);
  1937. }
  1938. }
  1939. // Save image to target address
  1940. uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
  1941. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
  1942. {
  1943. DEBUG_INFO("Save image fail.\n");
  1944. }
  1945. DEBUG_INFO("Save image success.\n");
  1946. return result;
  1947. }
  1948. //=======================================
  1949. // Download image
  1950. //=======================================
  1951. int downloadBIN(uint8_t targetAddr, char *filename)
  1952. {
  1953. int result = PASS;
  1954. int fd;
  1955. struct stat fileSt;
  1956. uint32_t pageSize = 128;
  1957. uint32_t blocklSize = 32768;
  1958. uint32_t transferedByte=0;
  1959. uint16_t bufferRamAddr = 0x8000;
  1960. // Reset LCD
  1961. uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
  1962. if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
  1963. {
  1964. DEBUG_INFO("LCD reset fail.\n");
  1965. }
  1966. // Get image file size
  1967. stat(filename, &fileSt);
  1968. uint8_t buf[(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1)*32768];
  1969. DEBUG_INFO("Bin filename: %s\n", filename);
  1970. DEBUG_INFO("Bin data size: %d\n", fileSt.st_size);
  1971. fd = open(filename, O_RDWR);
  1972. if (fd < 0)
  1973. {
  1974. DEBUG_WARN("Bin can not be open.\n");
  1975. result = FAIL;
  1976. }
  1977. else
  1978. {
  1979. for(uint8_t idxBinSrc=0;idxBinSrc<(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1);idxBinSrc++)
  1980. {
  1981. // Read data from bin file
  1982. memset(buf, 0x00, ARRAY_SIZE(buf));
  1983. read(fd, buf, ARRAY_SIZE(buf));
  1984. close(fd);
  1985. // Transfer data to ram
  1986. for(uint16_t idxSrcData=0;idxSrcData<(((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1);idxSrcData++)
  1987. {
  1988. //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxBinSrc*blocklSize)+(idxSrcData*pageSize));
  1989. //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
  1990. if((idxSrcData+1) != (((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1))
  1991. {
  1992. // Data transfer
  1993. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], pageSize) != PASS)
  1994. {
  1995. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  1996. }
  1997. transferedByte += pageSize;
  1998. }
  1999. else
  2000. {
  2001. // Last data transfer
  2002. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], (blocklSize-(idxSrcData*pageSize)))!= PASS)
  2003. {
  2004. DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
  2005. }
  2006. transferedByte += (blocklSize-(idxSrcData*pageSize));
  2007. }
  2008. }
  2009. // Move data from ram to flash
  2010. 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};
  2011. while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xaa, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
  2012. {
  2013. DEBUG_INFO("Save bin file to 0x%04X fail.\n", ((targetAddr*8)+idxBinSrc));
  2014. }
  2015. DEBUG_INFO("Save bin file on 0x%04X success.\n", ((targetAddr*8)+idxBinSrc));
  2016. }
  2017. }
  2018. return result;
  2019. }
  2020. //=======================================
  2021. // Main process
  2022. //=======================================
  2023. int main(void)
  2024. {
  2025. uint8_t previousMode = 0xff;
  2026. if(InitShareMemory() == FAIL)
  2027. {
  2028. #ifdef SystemLogMessage
  2029. DEBUG_ERROR("InitShareMemory NG\n");
  2030. #endif
  2031. if(ShmStatusCodeData!=NULL)
  2032. {
  2033. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  2034. }
  2035. sleep(5);
  2036. return FAIL;
  2037. }
  2038. Uart1Fd=InitComPort();
  2039. if(Uart1Fd<0)
  2040. {
  2041. #ifdef SystemLogMessage
  2042. DEBUG_ERROR("InitComPort NG\n");
  2043. #endif
  2044. if(ShmStatusCodeData!=NULL)
  2045. {
  2046. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  2047. }
  2048. sleep(5);
  2049. return FAIL;
  2050. }
  2051. else
  2052. {}
  2053. DEBUG_INFO("Initial completed\n");
  2054. DEBUG_INFO("Latest Firmware Version : [%s] \n", FIRMWARE_UPDATE_IMAGE[0]);
  2055. DEBUG_INFO("Latest Upgrade Date : [%s]. \n", FIRMWARE_UPDATE_IMAGE[1]);
  2056. DEBUG_INFO("Latest Image Version : [%s]. \n", FIRMWARE_UPDATE_IMAGE[2]);
  2057. for(;;)
  2058. {
  2059. if(previousMode != ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  2060. {
  2061. previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
  2062. }
  2063. if(ShmCharger->isAuthrizing || ShmCharger->isGetAuthResult)
  2064. {
  2065. if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) >= TIME_AUTH_RESULT_TIME)
  2066. ShmCharger->isGetAuthResult = FALSE;
  2067. if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) < TIME_AUTH_RESULT_TIME)
  2068. page_authorizing(ShmCharger->gun_selectd);
  2069. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus == SYS_MODE_IDLE) && (ShmCharger->gun_info[ShmCharger->gun_selectd].resultAuthorization == VALIDATED_RFID))
  2070. page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2071. }
  2072. else
  2073. {
  2074. ftime(&startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]);
  2075. switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
  2076. {
  2077. case SYS_MODE_BOOTING:
  2078. page_booting();
  2079. break;
  2080. case SYS_MODE_IDLE:
  2081. page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2082. break;
  2083. case SYS_MODE_AUTHORIZING:
  2084. //page_authorizing(ShmCharger->gun_selectd);
  2085. break;
  2086. case SYS_MODE_PREPARING:
  2087. page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2088. break;
  2089. case SYS_MODE_CHARGING:
  2090. page_charging(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2091. break;
  2092. case SYS_MODE_TERMINATING:
  2093. page_terminating(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2094. break;
  2095. case SYS_MODE_COMPLETE:
  2096. page_complete(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2097. break;
  2098. case SYS_MODE_ALARM:
  2099. page_alarm();
  2100. break;
  2101. case SYS_MODE_FAULT:
  2102. page_fault();
  2103. break;
  2104. case SYS_MODE_MAINTAIN:
  2105. page_maintain();
  2106. break;
  2107. case SYS_MODE_UPDATE:
  2108. page_update();
  2109. break;
  2110. case SYS_MODE_RESERVATION:
  2111. //page_reservation();
  2112. page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2113. break;
  2114. case SYS_MODE_BOOKING:
  2115. page_booking();
  2116. break;
  2117. case SYS_MODE_DEBUG:
  2118. page_debug();
  2119. break;
  2120. default:
  2121. page_unknown();
  2122. break;
  2123. }
  2124. }
  2125. page_header(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
  2126. page_footer();
  2127. usleep(100000);
  2128. }
  2129. return FAIL;
  2130. }