1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056 |
- /*
- * Module_LcmControl.c
- *
- * Created on : 2020-10-20
- * Update on : 2021-02-20
- * Author : Folus Wen, Eason Yang
- * Version : D0.01
- *
- */
- #include <sys/time.h>
- #include "define.h"
- #include "main.h"
- #include "lcmComm_dgus.h"
- //=======================================
- // Declare share memory
- //=======================================
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- struct Charger *ShmCharger;
- //=======================================
- // Declare Basic function
- //=======================================
- void trim(char *s);
- int mystrcmp(char *p1,char *p2);
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
- uint8_t split(char **arr, char *str, const char *del);
- void string2ByteArray(uint8_t *input, uint8_t *output);
- //=======================================
- // Declare Control panel function
- //=======================================
- uint8_t getCurrentPage();
- void setCurrentPage(uint8_t page);
- void setCurrencyFromWebsite(char *unit);
- void setWarningStatus(uint8_t gun_index);
- void setAuthorizationPage(uint8_t gun_index);
- void setPriceFromWebsite(float monry_rate);
- void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode);
- void setPresentChargedEnergy(uint8_t gun_index);
- void setPresentChargingPower(uint8_t gun_index);
- void setBatteryPercentageValue(uint8_t gun_index);
- void setPresentChargedDuration(uint8_t gun_index);
- void setQRcodeContent(char *input, uint8_t length);
- void setDisplayValue(uint16_t address, uint8_t value);
- void setGunPluginAnimation(uint8_t gun_index);
- void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode);
- void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode);
- void setUserPrice(uint8_t type);
- void setDefaultPrice(uint8_t type);
- void setFinalCost(uint8_t gun_index, uint8_t type);
- void setCurrencyAndUnitFromBackend(uint8_t type_price,uint8_t type_currency_unit, uint8_t gun_index);
- void setRTC();
- void setRfidIcon();
- void setWifi4GIcon();
- void setQRCodeIcon();
- void setBackendIcon();
- void setEthernetIcon();
- void setAlarmCodeAndIcon();
- void setBillingFromWebsite();
- //=======================================
- // Declare Timer
- //=======================================
- #define TMR_IDX_BATTERY 0
- #define TMR_IDX_CONNECTION 1
- #define TMR_IDX_PLUGIN 2
- #define TMR_IDX_ALARM 3
- #define TMR_IDX_PRICE 4
- #define TMR_IDX_EMULATOR 5
- #define TMR_IDX_6 6
- #define TMR_IDX_7 7
- #define TMR_IDX_8 8
- #define TMR_IDX_9 9
- struct timeb startTime[AC_QUANTITY][10];
- #define TIME_ANIMATION_PLUGIN 1000
- #define TIME_ANIMATION_BATTERY 1000
- #define TIME_ANIMATION_CONNECTION 1000
- #define TIME_ANIMATION_ALARM 5000
- #define TIME_REFRESH_TIME 2000
- //=======================================
- // Declare Variable
- //=======================================
- uint8_t BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- uint8_t CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- uint8_t GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
- uint8_t WarningCount = 255;
- int Uart1Fd;
- //=======================================
- // Emulator
- //=======================================
- int PERCENTAGE;
- uint8_t isChange;
- uint8_t isEmulator = NO;
- uint8_t isCharging = YES;
- //=======================================
- // Record version and date
- //=======================================
- char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.16", "2021-03-26", "REV.01.00"};
- //=======================================
- // Common routine
- //=======================================
- int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- time_t CurrentTime;
- struct tm *tm;
- struct timeval tv;
- va_list args;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- gettimeofday(&tv, NULL); // get microseconds, 10^-6
- sprintf(Buf,"echo -n \'[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\' >> /Storage/SystemLog/[%04d.%02d]Module_LcmControlLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- #ifdef SystemLogMessage
- system(Buf);
- #endif
- #ifdef ConsloePrintLog
- 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);
- #endif
- return rc;
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- long long StartTime,StopTime;
- ftime(&ET);
- StartTime=(long long)ST.time;
- StopTime=(long long)ET.time;
- return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
- }
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime,StopTime;
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
- }
- void trim(char *s)
- {
- int i=0, j, k, l=0;
- while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
- i++;
- j = strlen(s)-1;
- while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
- j--;
- if(i==0 && j==strlen(s)-1) { }
- else if(i==0) s[j+1] = '\0';
- else {
- for(k=i; k<=j; k++) s[l++] = s[k];
- s[l] = '\0';
- }
- }
- void trim_string(char *s, unsigned char len)
- {
- for(unsigned char i = 0 ; i < len; i++)
- {
- if (!(s[i] =='.')&& !((s[i]>='0') && (s[i]<='9')))
- {
- s[i] = s[i + 1];
- strncpy(s + i, s + i + 1, len);
- i -= 1;
- len -= 1;
- }
- }
- s[len + 1] = '\0';
- }
- int mystrcmp(char *p1,char *p2)
- {
- while(*p1==*p2)
- {
- if(*p1=='\0' || *p2=='\0')
- break;
- p1++;
- p2++;
- }
- if(*p1=='\0' && *p2=='\0')
- return(PASS);
- else
- return(FAIL);
- }
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- uint8_t split(char **arr, char *str, const char *del)
- {
- uint8_t result = 0;
- char *s = strtok(str, del);
- while(s != NULL)
- {
- *arr++ = s;
- result += 1;
- s = strtok(NULL, del);
- }
- return result;
- }
- void getDateTimeString(char* result)
- {
- time_t CurrentTime;
- struct tm *tm;
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- sprintf(result, "%04d/%02d/%02d %02d:%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min);
- }
- //=======================================
- // Function to page routine
- //=======================================
- void page_booting()
- {
- if(getCurrentPage() != SYSTEM_SCREEN_BOOTING)
- {
- setCurrentPage(SYSTEM_SCREEN_BOOTING);
- DEBUG_INFO("Setting page to booting.\n");
- }
- else
- {
- //DEBUG_INFO("Page booting.\n");
- }
- }
- void page_idle(uint8_t gun_index, uint8_t system_mode)
- {
- if(getCurrentPage() != SYSTEM_SCREEN_IDLE)
- {
- setCurrentPage(SYSTEM_SCREEN_IDLE);
- setBatteryAnimation(gun_index, system_mode);
- //DEBUG_INFO("Setting page to idle.\n");
- }
- else
- {
- setRfidIcon();
- setQRCodeIcon();
- //if(isCharging == YES)
- //PERCENTAGE = 0;
- //else
- //PERCENTAGE = 100;
- //DEBUG_INFO("Page idle.\n");
- }
- }
- void page_authorizing(uint8_t gun_index)
- {
- if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
- ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
- {
- // Searching User price for account balance
- setUserPrice(ACCOUNT_BALANCE);
- }
- else
- {
- // Disappear account balance and icon
- setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
- setDisplayValue(TEXT_BALANCE, DISAPPEAR);
- }
- }
- else
- {
- // Display by OCPP 2.0.1
- }
- }
- else
- {
- // Disappear account balance and icon
- setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
- setDisplayValue(TEXT_BALANCE, DISAPPEAR);
- }
- setAuthorizationPage(gun_index);
- }
- void page_preparing(uint8_t gun_index, uint8_t system_mode)
- {
- // Check handshaking mode BS / HLC
- if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_PREPARING))
- {
- setCurrentPage(SYSTEM_SCREEN_PREPARING);
- setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
- ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
- GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
- DEBUG_INFO("Setting page to preparing.\n");
- }
- else
- {
- setGunPluginAnimation(gun_index);
- //DEBUG_INFO("Page preparing.\n");
- }
- }
- else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_PREPARE_FOR_EVSE))
- {
- setCurrentPage(SYSTEM_SCREEN_PREPARE_FOR_EVSE);
- setDisplayValue(ICON_BATTERY_PRECHARGING, BATTERY_CAPACITY_EMPTY);
- setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- DEBUG_INFO("Setting page to prepare for EVSE.\n");
- }
- else
- {
- setConnectionAnimation(gun_index, system_mode);
- //DEBUG_INFO("Page preparing.\n");
- }
- }
- }
- void page_charging(uint8_t gun_index, uint8_t system_mode)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_CHARGING) && (ShmCharger->gun_info[gun_index].resultAuthorization == DEFAULT_RFID))
- {
- setCurrentPage(SYSTEM_SCREEN_CHARGING);
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
- ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- DEBUG_INFO("Setting page to charging.\n");
- //isChange = 0;
- //ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
- }
- else
- {
- setConnectionAnimation(gun_index, system_mode);
- setBatteryAnimation(gun_index, system_mode);
- setPresentChargedDuration(gun_index);
- setPresentChargedEnergy(gun_index);
- setPresentChargingPower(gun_index);
- setAuthorizationPage(gun_index);
- //DEBUG_INFO("Page charging.\n");
- }
- }
- void page_complete(uint8_t gun_index, uint8_t system_mode)
- {
- if(getCurrentPage() != SYSTEM_SCREEN_COMPLETE)
- {
- setCurrentPage(SYSTEM_SCREEN_COMPLETE);
- DEBUG_INFO("Setting page to complete.\n");
- }
- else
- {
- setPresentChargedDuration(gun_index);
- setPresentChargedEnergy(gun_index);
- setBatteryAnimation(gun_index, system_mode);
- if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- setFinalCost(gun_index, TOTAL_COST);
- setFinalCost(gun_index, ACCOUNT_BALANCE);
- setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
- }
- else
- {
- // Display by OCPP 2.0.1
- }
- }
- else
- {
- // Disappear account balance and icon
- setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
- // Disappear cost and icon
- setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
- // Disappear balance currency unit
- setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
- }
- //DEBUG_INFO("Page complete.\n");
- }
- }
- void page_terminating(uint8_t gun_index, uint8_t system_mode)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_TERMINATING) && (ShmCharger->gun_info[gun_index].resultAuthorization == DEFAULT_RFID))
- {
- setCurrentPage(SYSTEM_SCREEN_TERMINATING);
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- DEBUG_INFO("Setting page to terminating.\n");
- }
- else
- {
- setConnectionAnimation(gun_index, system_mode);
- setBatteryAnimation(gun_index, system_mode);
- setPresentChargedDuration(gun_index);
- setPresentChargedEnergy(gun_index);
- setPresentChargingPower(gun_index);
- setAuthorizationPage(gun_index);
- if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- setFinalCost(gun_index, TOTAL_COST);
- setFinalCost(gun_index, ACCOUNT_BALANCE);
- setCurrencyAndUnitFromBackend(FINAL_COST, ACCOUNT_BALANCE, gun_index);
- }
- else
- {
- // Display by OCPP 2.0.1
- }
- }
- else
- {
- // Disappear account balance and icon
- setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
- // Disappear cost and icon
- setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
- // Disappear balance currency unit
- setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
- }
- //DEBUG_INFO("Page terminating.\n");
- }
- }
- void page_alarm()
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip != ON)
- {
- if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
- {
- setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
- DEBUG_INFO("Setting page to repair man.\n");
- }
- else
- {}
- }
- else
- {
- if(getCurrentPage() != SYSTEM_SCREEN_EMERGENCY)
- {
- setCurrentPage(SYSTEM_SCREEN_EMERGENCY);
- DEBUG_INFO("Setting page to emergency.\n");
- }
- else
- {}
- }
- }
- void page_fault()
- {
- DEBUG_INFO("Page fault.\n");
- }
- void page_maintain()
- {
- if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
- {
- setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
- DEBUG_INFO("Setting page to maintain.\n");
- }
- else
- {
- //DEBUG_INFO("Page maintain.\n");
- }
- }
- void page_update()
- {
- if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
- {
- setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
- DEBUG_INFO("Setting page to update.\n");
- }
- else
- {
- //DEBUG_INFO("Page update.\n");
- }
- }
- void page_reservation()
- {
- DEBUG_INFO("Page reservation.\n");
- }
- void page_booking()
- {
- DEBUG_INFO("Page booking.\n");
- }
- void page_debug()
- {
- if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
- {
- setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
- DEBUG_INFO("Setting page to debug.\n");
- }
- else
- {
- //DEBUG_INFO("Page debug.\n");
- }
- }
- void page_unknown()
- {
- DEBUG_INFO("Page unknown.\n");
- }
- void page_header(uint8_t gun_index, uint8_t system_mode)
- {
- setEthernetIcon();
- setBackendIcon();
- setWifi4GIcon();
- setRTC();
- setWarningStatus(gun_index);
- // Set LCM to save energy mode
- if((ShmCharger->isLcdOn == ON))
- setDisplayValue(REG_ADDRESS_WRITE_BRIGHTNESS,BRIGHTNESS_100);
- else
- setDisplayValue(REG_ADDRESS_WRITE_BRIGHTNESS,BRIGHTNESS_10);
- // Set billing
- if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
- {
- setBillingFromWebsite();
- }
- else
- {
- if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PRICE]) > (TIME_REFRESH_TIME))
- {
- ftime(&startTime[gun_index][TMR_IDX_PRICE]);
- setBillingFromBackend(gun_index, system_mode);
- }
- }
- //DEBUG_INFO("Page heading.\n");
- }
- //=======================================
- // Setting icon display value
- //=======================================
- void setDisplayValue(uint16_t address, uint8_t value)
- {
- uint8_t data[2];
- data[0] = value >> 8;
- data[1] = value & 0X00FF;
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, address, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Getting current page
- //=======================================
- uint8_t getCurrentPage()
- {
- uint8_t currentPage[2];
- uint8_t result = 255;
- if(lcdRegisterRead(Uart1Fd, REG_TYPE_CONTROL, REG_ADDRESS_READ_PAGE_ID, currentPage, ARRAY_SIZE(currentPage)))
- {
- result = currentPage[1];
- // DEBUG_INFO("currentPage[0] : %X\n", currentPage[0]);
- // DEBUG_INFO("currentPage[1] : %X\n", currentPage[1]);
- // DEBUG_INFO("getCurrentPage : %d \n", result);
- }
- else
- {
- DEBUG_INFO("Get current page fail! \n");
- }
- return result;
- }
- //=======================================
- // Setting current page
- //=======================================
- void setCurrentPage(uint8_t page)
- {
- uint8_t settingPage[2] = {0x00, page};
- if(lcdRegisterWrite(Uart1Fd, REG_TYPE_CONTROL, REG_ADDRESS_SET_PAGE_ID, settingPage, ARRAY_SIZE(settingPage)))
- DEBUG_INFO("setCurrentPage : %d \n", page);
- else
- DEBUG_INFO("Setting current page fail! \n");
- }
- //=======================================
- // Convert string to byte array
- //=======================================
- void string2ByteArray(unsigned char *input, uint8_t *output)
- {
- int loop;
- int i;
- loop = 0;
- i = 0;
- while(input[loop] != '\0')
- {
- output[i++] = input[loop++];
- }
- output[loop] = '\0';
- }
- //=======================================
- // Setting ETHERNET icon status
- //=======================================
- void setEthernetIcon()
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet == ON)
- setDisplayValue(ICON_ETHERENT_CONNECTION, ETHERENT_OFFLINE);
- else
- setDisplayValue(ICON_ETHERENT_CONNECTION, EHTERNET_ONLINE);
- }
- //=======================================
- // Setting BACKEND icon status
- //=======================================
- void setBackendIcon()
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus != ON)
- setDisplayValue(ICON_BACKEND_CONNECTION,BACKEND_OFFLINE);
- else
- setDisplayValue(ICON_BACKEND_CONNECTION,BACKEND_ONLINE);
- }
- //=======================================
- // Setting WIFI / 4G icon status
- //=======================================
- void setWifi4GIcon()
- {
- //==============================================
- // Setting WIFI + 4G icon status online / off-line
- //==============================================
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == DISABLE_WIFI)
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G)
- {
- setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- }
- else
- {
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
- setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
- else
- setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
- }
- }
- else
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == WIFI_STATION)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
- setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
- else
- setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
- }
- else
- setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == DISABLE_4G)
- {
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- }
- else
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
- setDisplayValue(ICON_4G_CONNECTION, TELECOM_OFFLINE);
- else
- setDisplayValue(ICON_4G_CONNECTION, TELECOM_ONLINE);
- }
- }
- }
- else
- {
- //========================================
- // Setting 4G icon status online / off-line
- //========================================
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- switch(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled)
- {
- case DISABLE_4G:
- setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- break;
- case ENABLE_4G:
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == ON)
- setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_OFFLINE);
- else
- setDisplayValue(ICON_WIFI_CONNECTION, TELECOM_ONLINE);
- break;
- default:
- break;
- }
- }
- //========================================
- // Setting WIFI icon status online / off-line
- //========================================
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- switch(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode)
- {
- case DISABLE_WIFI:
- setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- break;
- case WIFI_STATION:
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == ON)
- setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
- else
- setDisplayValue(ICON_WIFI_CONNECTION, WIFI_ONLINE);
- break;
- case WIFI_ACCESS_POINT:
- setDisplayValue(ICON_WIFI_CONNECTION, WIFI_OFFLINE);
- break;
- default:
- break;
- }
- }
- }
- }
- //=======================================
- // Setting billing (Web page)
- //=======================================
- void setBillingFromWebsite()
- {
- if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
- {
- setDisplayValue(ICON_PRICE, APPEAR);
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- if(tmCSU->tm_hour <= 23)
- {
- ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
- setPriceFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
- }
- // Currency unit 53 countries
- if(ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
- {
- setCurrencyFromWebsite((char *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
- }
- }
- else
- {
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- }
- }
- //=======================================
- // Setting currency (Web page)
- //=======================================
- void setCurrencyFromWebsite(char *unit)
- {
- uint8_t data[16];
- uint8_t currency[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(currency, 0x00, ARRAY_SIZE(currency));
- *(unit + 3) = '\0';
- sprintf((char *) currency, "%s", unit);
- string2ByteArray(currency, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting price (Web page)
- //=======================================
- void setPriceFromWebsite(float monry_rate)
- {
- uint8_t data[16];
- uint8_t price[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(price, 0x00, ARRAY_SIZE(price));
- sprintf((char *)price, "%.2f", monry_rate);
- string2ByteArray(price, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting billing (Backend)
- //=======================================
- void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
- {
- if((system("pidof -s OcppBackend > /dev/null") != 0))
- {
- // Price, currency and icon disappear
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- }
- else
- {
- if((ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if((strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData,"") != 0))
- {
- if(system_mode == SYS_MODE_IDLE)
- {
- // Searching defaultPrice for price
- setDefaultPrice(CURRENT_RATE);
- // Searching DefaultPrice for Currency and unit appear
- setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
- }
- else
- {
- // If startUserId is not match with idToken and it can not be null, otherwise the system should use default price
- if((strcmp((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) == 0) &&
- ((strcmp((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,"") != 0)))
- {
- // Searching UserPrice for price
- setUserPrice(CURRENT_RATE);
- // Searching UserPrice for Currency and unit appear
- setCurrencyAndUnitFromBackend(SET_USER_PRICE, CURRENT_RATE,gun_index);
- }
- else
- {
- // Searching defaultPrice for price
- setDefaultPrice(CURRENT_RATE);
- // Searching DefaultPrice for Currency and unit appear
- setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
- }
- }
- }
- else
- {
- // Price, currency and icon disappear
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- }
- }
- else
- {
- // Display default price by OCPP 2.0.1
- }
- }
- else
- {
- // Price, currency and icon disappear
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- }
- }
- }
- //=======================================
- // Setting UserPrice (Backend)
- //=======================================
- void setUserPrice(uint8_t type)
- {
- uint8_t length;
- uint8_t Split_String_Count;
- uint8_t output_data[32];
- char input_data[32];
- char tmp[256];
- char *splitString[10];
- const char *Symbol = ";";
- memset(tmp, 0, ARRAY_SIZE(tmp));
- memset(input_data, 0x00, ARRAY_SIZE(input_data));
- memset(output_data, 0x00, ARRAY_SIZE(output_data));
- switch(type)
- {
- case CONNECTION_FEE:
- break;
- case CURRENT_RATE:
- if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
- {
- // Appear price icon
- setDisplayValue(ICON_PRICE, APPEAR);
- // Appear price text
- strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[1], strlen(splitString[1]));
- length = strlen(input_data);
- trim_string(input_data,length);
- memcpy(output_data ,input_data, strlen(input_data));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- // Disappear price text and price icon
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- }
- break;
- case OCCUPANCY_FEE:
- break;
- case ACCOUNT_BALANCE:
- if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Account Balance:") > 0)
- {
- // Appear account balance icon
- setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
- // Appear account balance text
- strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[3], strlen(splitString[3]));
- length = strlen(input_data);
- trim_string(input_data,length);
- memcpy(output_data ,input_data, strlen(input_data));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- // Disappear balance text and balance icon
- setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
- setDisplayValue(TEXT_BALANCE, DISAPPEAR);
- }
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting DefaultPrice (Backend)
- //=======================================
- void setDefaultPrice(uint8_t type)
- {
- uint8_t length;
- uint8_t Split_String_Count;
- uint8_t output_data[32];
- char input_data[32];
- char tmp[256];
- char *splitString[10];
- const char *Symbol = ";";
- memset(tmp, 0, ARRAY_SIZE(tmp));
- memset(input_data, 0x00, ARRAY_SIZE(input_data));
- memset(output_data, 0x00, ARRAY_SIZE(output_data));
- switch(type)
- {
- case CONNECTION_FEE:
- break;
- case CURRENT_RATE:
- if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
- {
- // Appear price icon
- setDisplayValue(ICON_PRICE, APPEAR);
- // Appear price text
- strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[1], strlen(splitString[1]));
- length = strlen(input_data);
- trim_string(input_data,length);
- memcpy(output_data ,input_data, strlen(input_data));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PRICE, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- }
- break;
- case OCCUPANCY_FEE:
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting FinalCost (Backend)
- //=======================================
- void setFinalCost(uint8_t gun_index, uint8_t type)
- {
- uint8_t length;
- uint8_t Split_String_Count;
- uint8_t output_data[32];
- char input_data[32];
- char tmp[256];
- char *splitString[10];
- const char *Symbol = ";";
- memset(tmp, 0, ARRAY_SIZE(tmp));
- memset(output_data, 0x00, ARRAY_SIZE(output_data));
- memset(input_data, 0x00, ARRAY_SIZE(input_data));
- switch(type)
- {
- case CONNECTION_FEE:
- break;
- case SESSION_FEE:
- break;
- case OCCUPANCY_FEE:
- break;
- case TOTAL_COST:
- if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Total Cost:") > 0))
- {
- // Appear cost icon
- setDisplayValue(ICON_COST_COMPLETE, APPEAR);
- // Appear cost test
- strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[3], strlen(splitString[3]));
- length = strlen(input_data);
- trim_string(input_data,length);
- memcpy(output_data ,input_data, strlen(input_data));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- // Disappear cost icon and text
- setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
- }
- break;
- case ACCOUNT_BALANCE:
- if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
- {
- // Appear balance icon
- setDisplayValue(ICON_WALLER_COMPLETE, APPEAR);
- setDisplayValue(ICON_BALANCE_WALLET, APPEAR);
- // Appear balance test
- strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[4], strlen(splitString[4]));
- length = strlen(input_data);
- trim_string(input_data,length);
- memcpy(output_data ,input_data, strlen(input_data));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ACCOUNT_COMPLETE, output_data, ARRAY_SIZE(output_data));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_BALANCE, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- // Disappear account balance and icon on complete
- setDisplayValue(ICON_WALLER_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_ACCOUNT_COMPLETE, DISAPPEAR);
- setDisplayValue(ICON_BALANCE_WALLET, DISAPPEAR);
- setDisplayValue(TEXT_BALANCE, DISAPPEAR);
- }
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting currency (Backend)
- //=======================================
- void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_unit,uint8_t gun_index)
- {
- uint8_t length;
- uint8_t Split_String_Count;
- uint8_t output_data[32];
- char input_data[32];
- char tmp[256];
- char *splitString[10];
- const char *Symbol = ";";
- memset(tmp, 0, ARRAY_SIZE(tmp));
- memset(input_data, 0x00, ARRAY_SIZE(input_data));
- memset(output_data, 0x00, ARRAY_SIZE(output_data));
- if(type_price == DEFAULE_PRICE)
- {
- switch(type_currency_unit)
- {
- case CONNECTION_FEE:
- break;
- case CURRENT_RATE:
- if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
- {
- strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[1], strlen(splitString[1]));
- length = strlen(input_data);
- memcpy(output_data , input_data+(length-7), 7);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- }
- break;
- case OCCUPANCY_FEE:
- break;
- default:
- break;
- }
- }
- else if(type_price == SET_USER_PRICE)
- {
- switch(type_currency_unit)
- {
- case CONNECTION_FEE:
- break;
- case CURRENT_RATE:
- if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
- {
- strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[1], strlen(splitString[1]));
- length = strlen(input_data);
- memcpy(output_data , input_data+(length-7), 7);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- }
- break;
- case OCCUPANCY_FEE:
- break;
- case ACCOUNT_BALANCE:
- break;
- default:
- break;
- }
- }
- else if(type_price == FINAL_COST)
- {
- switch(type_currency_unit)
- {
- case CONNECTION_FEE:
- break;
- case SESSION_FEE:
- break;
- case OCCUPANCY_FEE:
- break;
- case TOTAL_COST:
- break;
- case ACCOUNT_BALANCE:
- if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
- {
- strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- Split_String_Count = split((char**)splitString, tmp, Symbol);
- memcpy(input_data, splitString[4], strlen(splitString[4]));
- length = strlen(input_data);
- memcpy(output_data , input_data+(length-3), 3);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_COMPLETE, output_data, ARRAY_SIZE(output_data));
- }
- else
- {
- setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
- }
- break;
- default:
- break;
- }
- }
- else
- {}
- }
- //=======================================
- // Setting RTC value
- //=======================================
- void setRTC()
- {
- uint8_t data[32];
- uint8_t rtc[32];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(rtc, 0x00, ARRAY_SIZE(rtc));
- getDateTimeString((char*)rtc);
- string2ByteArray(rtc, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_RTC, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting RFID icon status
- //=======================================
- void setRfidIcon()
- {
- //=======================================
- // AX-Series Generation 1
- //=======================================
- if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '1'))
- {
- if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
- setDisplayValue(ICON_RFID, RFID_ENABLE);
- else
- setDisplayValue(ICON_RFID, RFID_DISABLE);
- }
- //=======================================
- // AX-Series Generation 2/3/4
- //=======================================
- if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'X') &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[11] == '2') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '3') || (ShmSysConfigAndInfo->SysConfig.ModelName[11] == '4')))
- {
- if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
- setDisplayValue(ICON_RFID, VISA_ENABLE);
- else
- setDisplayValue(ICON_RFID, VISA_DISABLE);
- }
- //=======================================
- // AW-Series Generation
- //=======================================
- if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A') &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'w'))
- {
- if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
- setDisplayValue(ICON_RFID, RFID_ENABLE);
- else
- setDisplayValue(ICON_RFID, RFID_DISABLE);
- }
- }
- //=======================================
- // Setting QRCODE icon status
- //=======================================
- void setQRCodeIcon()
- {
- uint8_t length = 0;
- // QR code enable / disable
- if(ShmSysConfigAndInfo->SysConfig.isQRCode == ON)
- {
- setDisplayValue(ICON_QRCODE,QRCODE_ENABLE);
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
- {
- length = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
- setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.SystemId, length);
- }
- else
- {
- length = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
- setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, length);
- }
- }
- else
- {
- setDisplayValue(TEXT_QRCODE_CONTENT, DISAPPEAR);
- setDisplayValue(ICON_QRCODE,QRCODE_DISABLE);
- }
- }
- //=======================================
- // Setting QR code content
- //=======================================
- void setQRcodeContent(char *input, uint8_t length)
- {
- uint8_t output[length];
- int loop = 0;
- input[length] = '\0';
- output[length] = '\0';
- while(input[loop] != '\0')
- {
- output[loop] = input[loop];
- loop++;
- }
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
- }
- //=======================================
- // Setting warning page switch
- //=======================================
- void setWarningStatus(uint8_t gun_index)
- {
- if(WarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
- {
- WarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
- ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
- setAlarmCodeAndIcon();
- }
- else if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 4 && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_ALARM]) > (TIME_ANIMATION_ALARM)))
- {
- ftime(&startTime[gun_index][TMR_IDX_ALARM]);
- if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
- {
- ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
- }
- else
- {
- ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
- }
- setAlarmCodeAndIcon();
- }
- }
- //=======================================
- // Setting alarm code and icon status
- //=======================================
- void setAlarmCodeAndIcon()
- {
- uint8_t cmd[7];
- uint8_t index = 0;
- for(index = 0; (index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; index++)
- {
- memset(cmd, 0x00, sizeof(cmd));
- if(index >= 4)
- {
- break;
- }
- // Alarm code
- string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[index + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 4][0], cmd);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
- // Icon status
- memset(cmd, 0x00, sizeof(cmd));
- cmd[0] = 0x00;
- cmd[1] = 0x01;
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
- }
- memset(cmd, 0x00, sizeof(cmd));
- for(; index < 4; index++)
- {
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ALARM_CODE_1 + (index * 6), cmd, ARRAY_SIZE(cmd));
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, ICON_ALARM_1 + index, cmd, 2);
- }
- }
- //=======================================
- // Setting Battery icon animation
- //=======================================
- void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode)
- {
- switch(system_mode)
- {
- case SYS_MODE_IDLE:
- // Setting battery icon to initial status
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_EMPTY);
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- break;
- case SYS_MODE_CHARGING:
- if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
- {
- // Set battery percentage text to disappear
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- // Set battery animation
- if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_0;
- }
- else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_1;
- }
- else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_2;
- }
- else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_2) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*3)))
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_3;
- }
- else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_3) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*4)))
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_4;
- }
- else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_4) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*5)))
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
- }
- }
- else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
- {
- if(isEmulator == YES)
- {
- if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_EMULATOR]) > 3000))
- {
- if(isCharging == YES)
- PERCENTAGE++;
- else
- PERCENTAGE--;
- ftime(&startTime[gun_index][TMR_IDX_EMULATOR]);
- }
- if(isCharging == YES)
- {
- if(PERCENTAGE > 100)
- PERCENTAGE = 0;
- }
- else
- {
- if(PERCENTAGE <= 0)
- PERCENTAGE = 100;
- }
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc = PERCENTAGE;
- if((isChange == 0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
- {
- isChange = 1;
- }
- else if((isChange == 1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
- {
- isChange = 0;
- ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
- }
- }
- else
- {}
- // Set battery animation
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
- {
- if(isChange == 0)
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
- else
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
- }
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
- {
- if(isChange == 0)
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
- else
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
- }
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
- {
- if(isChange == 0)
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
- else
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
- }
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
- {
- if(isChange == 0)
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
- else
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
- }
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 100))
- {
- if(isChange == 0)
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
- else
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
- }
- else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc == 100)
- {
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
- }
- // Set battery SOC value
- setBatteryPercentageValue(gun_index);
- // Set electric arrow icon direction
- if(isCharging == YES)
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_LEFT);
- else
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_RIGHT);
- }
- break;
- case SYS_MODE_TERMINATING:
- if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
- {
- // Set battery icon to empty
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
- // Set battery percentage to disappear
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- }
- else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
- {
- // Set battery animation
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
- // Set battery SOC value
- setBatteryPercentageValue(gun_index);
- // Set electric arrow icon direction disappear
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
- }
- break;
- case SYS_MODE_COMPLETE:
- if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
- {
- // Set battery icon to 100%
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
- // Set battery percentage to disappear
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- }
- else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
- {
- // Set battery animation
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 20)
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_20);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 20) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 40))
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_40);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 40) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 60))
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_60);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 60) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc < 80))
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_80);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc >= 80) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc <= 100))
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
- // Set battery SOC value
- setBatteryPercentageValue(gun_index);
- // Set electric arrow icon direction disappear
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
- }
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting connection icon animation
- //=======================================
- void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
- {
- switch(system_mode)
- {
- case SYS_MODE_PREPARING:
- if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
- {
- setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
- }
- else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
- {
- setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_2);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- }
- break;
- case SYS_MODE_CHARGING:
- if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
- {
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
- }
- else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
- {
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_2);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- }
- break;
- case SYS_MODE_TERMINATING:
- if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
- {
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
- }
- else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
- {
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- }
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting gun plug-in animation
- //=======================================
- void setGunPluginAnimation(uint8_t gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_B)
- {
- if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN)))
- {
- setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
- GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_1;
- }
- else if((GUN_PLUGING_LEVEL_STATUS == GUN_PLUGING_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN*2)))
- {
- setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
- GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
- ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
- }
- }
- else
- {
- setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
- }
- }
- //=======================================
- // Setting battery SOC value
- //=======================================
- void setBatteryPercentageValue(uint8_t gun_index)
- {
- uint8_t data[16];
- uint8_t soc[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(soc, 0x00, ARRAY_SIZE(soc));
- sprintf((char *)soc, "%d%%", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc);
- string2ByteArray(soc, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_PERCENTAGE, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting present charging power
- //=======================================
- void setPresentChargingPower(uint8_t gun_index)
- {
- uint8_t data[16];
- uint8_t power[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(power, 0x00, ARRAY_SIZE(power));
- sprintf((char *)power, "%.2f kW", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingPower);
- string2ByteArray(power, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_POWER_CHARGING, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting present charged energy
- //=======================================
- void setPresentChargedEnergy(uint8_t gun_index)
- {
- uint8_t data[16];
- uint8_t energy[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(energy, 0x00, ARRAY_SIZE(energy));
- sprintf((char *)energy, "%.4f kWh", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy);
- string2ByteArray(energy, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_ENERGY_CHARGING, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting present charged duration
- //=======================================
- void setPresentChargedDuration(uint8_t gun_index)
- {
- uint8_t data[16];
- uint8_t time[16];
- uint16_t hour;
- uint16_t minute;
- uint16_t second;
- uint16_t PresentChargedDuration = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration;
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(time, 0x00, ARRAY_SIZE(time));
- hour = (PresentChargedDuration / 3600);
- minute = (PresentChargedDuration - (3600 * hour)) / 60;
- second = (PresentChargedDuration - (3600 * hour) - (minute * 60));
- sprintf((char *)time, "%02d:%02d:%02d", hour, minute, second);
- string2ByteArray(time, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_TIMER_CHARGING, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Setting authorization page
- //=======================================
- void setAuthorizationPage(uint8_t gun_index)
- {
- switch(ShmCharger->gun_info[gun_index].resultAuthorization)
- {
- case VALIDATED_RFID:
- if(getCurrentPage() != SYSTEM_SCREEN_AUTH_PASS)
- {
- setCurrentPage(SYSTEM_SCREEN_AUTH_PASS);
- DEBUG_INFO("Setting page to authorizing : Validated RFID.\n");
- }
- else
- {
- DEBUG_INFO("Page authorizing validated.\n");
- }
- break;
- case UNVALIDATED_RFID:
- if(getCurrentPage() != SYSTEM_SCREEN_AUTH_FAIL)
- {
- setCurrentPage(SYSTEM_SCREEN_AUTH_FAIL);
- DEBUG_INFO("Setting page to authorizing : Unvalidated RFID.\n");
- }
- else
- {
- DEBUG_INFO("Page authorizing unvalidated.\n");
- }
- break;
- case UNKNOW_RFID:
- if(getCurrentPage() != SYSTEM_SCREEN_AUTH_UNKNOW)
- {
- setCurrentPage(SYSTEM_SCREEN_AUTH_UNKNOW);
- DEBUG_INFO("Setting page to authorizing : Unknow RFID\n");
- }
- else
- {
- DEBUG_INFO("Page authorizing unknow.\n");
- }
- break;
- case DEFAULT_RFID:
- break;
- default:
- break;
- }
- }
- //=======================================
- // Initial all share memory
- //=======================================
- int InitShareMemory()
- {
- int result = PASS;
- int MeterSMId;
- // Initial ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
- result = FAIL;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
- result = FAIL;
- }
- else
- {}
- // Initial ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
- result = FAIL;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
- result = FAIL;
- }
- else
- {}
- // Initial ShmCharger
- if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmChargerKey NG\n");
- result = FAIL;
- }
- else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmChargerKey NG\n");
- result = FAIL;
- }
- // Initial ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
- result = FAIL;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
- result = FAIL;
- }
- // Initial ShmOCPP20Data
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
- {
- DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
- result = FAIL;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
- result = FAIL;
- }
- return result;
- }
- //=======================================
- // Initial communication port
- //=======================================
- int InitComPort()
- {
- int fd;
- struct termios tios;
- fd = open("/dev/ttyS3", O_RDWR);
- if(fd<=0)
- {
- DEBUG_ERROR("open /dev/ttyS3 NG\n");
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)5; // timeout 500ms
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- //=======================================
- // Main process
- //=======================================
- int main(void)
- {
- uint8_t previousMode = 0xff;
- if(InitShareMemory() == FAIL)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("InitShareMemory NG\n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- return FAIL;
- }
- Uart1Fd=InitComPort();
- if(Uart1Fd<0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR("InitComPort NG\n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- return FAIL;
- }
- else
- {}
- DEBUG_INFO("Initial completed\n");
- DEBUG_INFO("Latest Firmware Version : [%s] \n", FIRMWARE_UPDATE_IMAGE[0]);
- DEBUG_INFO("Latest Upgrade Date : [%s]. \n", FIRMWARE_UPDATE_IMAGE[1]);
- DEBUG_INFO("Latest Image Version : [%s]. \n", FIRMWARE_UPDATE_IMAGE[2]);
- for(;;)
- {
- if(previousMode != ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
- {
- previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
- }
- switch(ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
- {
- case SYS_MODE_BOOTING:
- page_booting();
- break;
- case SYS_MODE_IDLE:
- page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- break;
- case SYS_MODE_AUTHORIZING:
- page_authorizing(ShmCharger->gun_selectd);
- break;
- case SYS_MODE_PREPARING:
- page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- break;
- case SYS_MODE_CHARGING:
- page_charging(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- break;
- case SYS_MODE_TERMINATING:
- page_terminating(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- break;
- case SYS_MODE_COMPLETE:
- page_complete(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- break;
- case SYS_MODE_ALARM:
- page_alarm();
- break;
- case SYS_MODE_FAULT:
- page_fault();
- break;
- case SYS_MODE_MAINTAIN:
- page_maintain();
- break;
- case SYS_MODE_UPDATE:
- page_update();
- break;
- case SYS_MODE_RESERVATION:
- page_reservation();
- break;
- case SYS_MODE_BOOKING:
- page_booking();
- break;
- case SYS_MODE_DEBUG:
- page_debug();
- break;
- default:
- page_unknown();
- break;
- }
- page_header(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- usleep(100000);
- }
- return FAIL;
- }
|