123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592 |
- /*
- * Module_LcmControl.c
- *
- * Created on : 2020-10-20
- * Update on : 2021-06-23
- * Author : Folus Wen, Eason Yang
- * Version : D0.01
- *
- */
- #include <sys/time.h>
- #include "define.h"
- #include "main.h"
- #include "lcmComm_dgus.h"
- #include "cbmp.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(uint8_t 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 setPresentPowerConsumption(uint8_t gun_index);
- void setQRcodeContent(char *input, uint8_t length, uint8_t mode);
- 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 setPresentFinalCost(float cost);
- float getPresentFinalCost(uint8_t gun_index);
- void setDefaultValue(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();
- void setQRCodeReceipt(uint8_t gun_index);
- void setReceiptIcon(uint8_t gun_index);
- //=======================================
- // Declare Timer
- //=======================================
- enum TMR_IDX
- {
- TMR_IDX_BATTERY=0,
- TMR_IDX_CONNECTION,
- TMR_IDX_PLUGIN,
- TMR_IDX_ALARM,
- TMR_IDX_PRICE,
- TMR_IDX_EMULATOR,
- TMR_IDX_6,
- TMR_IDX_7,
- TMR_IDX_8,
- TMR_IDX_SHOW_AUTH_RESULT
- };
- 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 5000
- #define TIME_AUTH_RESULT_TIME 5000
- //=======================================
- // 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.19", "2021-09-28", "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
- {}
- }
- void page_idle(uint8_t gun_index, uint8_t system_mode)
- {
- if(ShmCharger->gun_info[gun_index].isSleepOn == YES)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_SLEEP))
- {
- setCurrentPage(SYSTEM_SCREEN_SLEEP);
- }
- else
- {}
- }
- else
- {
- if(ShmCharger->gun_info[gun_index].isCheckPowerConsumption == YES)
- {
- setCurrentPage(SYSTEM_SCREEN_POWER_CONSUMPTION);
- setDisplayValue(ICON_POWER_CONSUMPTION, APPEAR);
- setPresentPowerConsumption(gun_index);
- }
- else
- {
- if((getCurrentPage() != SYSTEM_SCREEN_IDLE) && (ShmCharger->gun_info[gun_index].resultAuthorization != VALIDATED_RFID))
- {
- setCurrentPage(SYSTEM_SCREEN_IDLE);
- setDefaultValue(gun_index, system_mode);
- DEBUG_INFO("Setting page to idle.\n");
- }
- else
- {
- setRfidIcon();
- setQRCodeIcon();
- if(isEmulator == YES)
- {
- //if(isCharging == YES)
- //PERCENTAGE = 0;
- //else
- //PERCENTAGE = 100;
- }
- }
- }
- }
- }
- void page_authorizing(uint8_t gun_index)
- {
- // CHANGE DISPLAY TO AUTHORIZATION
- setAuthorizationPage(gun_index);
- // SHOW USER ACCOUNT BALANCE WHEN THE SYSTEM IS ONLINE
- 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);
- }
- }
- void page_preparing(uint8_t gun_index, uint8_t system_mode)
- {
- // CHECK PREPARING MODE (BS & SOCKET) / HLC
- if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_PREPARE_FOR_EVSE))
- {
- setCurrentPage(SYSTEM_SCREEN_PREPARE_FOR_EVSE);
- setDefaultValue(gun_index, system_mode);
- DEBUG_INFO("Setting page to prepare for EVSE.\n");
- }
- else
- {
- setConnectionAnimation(gun_index, system_mode);
- }
- }
- else
- {
- if((getCurrentPage() != SYSTEM_SCREEN_PREPARING))
- {
- setCurrentPage(SYSTEM_SCREEN_PREPARING);
- setDefaultValue(gun_index, system_mode);
- DEBUG_INFO("Setting page to preparing.\n");
- }
- else
- {
- setGunPluginAnimation(gun_index);
- }
- }
- }
- void page_charging(uint8_t gun_index, uint8_t system_mode)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_CHARGING) && (!ShmCharger->isAuthrizing && !ShmCharger->isGetAuthResult))
- {
- setCurrentPage(SYSTEM_SCREEN_CHARGING);
- setDefaultValue(gun_index, system_mode);
- 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);
- }
- }
- 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
- {
- setPresentChargedEnergy(gun_index);
- setPresentChargedDuration(gun_index);
- setBatteryAnimation(gun_index, system_mode);
- setReceiptIcon(gun_index);
- // SHOW FINAL COST AND ACCOUNT BALANCE AFTER THE END OF TRANSACTION
- 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
- {
- if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling == ON)
- {
- // APPEAR COST AND ICON
- setDisplayValue(ICON_COST_COMPLETE, APPEAR);
- setPresentFinalCost(getPresentFinalCost(gun_index));
- }
- 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);
- }
- }
- }
- }
- void page_terminating(uint8_t gun_index, uint8_t system_mode)
- {
- if((getCurrentPage() != SYSTEM_SCREEN_TERMINATING) && (!ShmCharger->isAuthrizing && !ShmCharger->isGetAuthResult))
- {
- setCurrentPage(SYSTEM_SCREEN_TERMINATING);
- setDefaultValue(gun_index, system_mode);
- 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);
- setReceiptIcon(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 ADN ICON
- setDisplayValue(ICON_COST_COMPLETE, DISAPPEAR);
- setDisplayValue(TEXT_COST_COMPLETE, DISAPPEAR);
- // DISAPPEAR BALANCE CURRENCY UNIT
- setDisplayValue(TEXT_CURRENCY_COMPLETE, DISAPPEAR);
- }
- }
- }
- 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
- {}
- }
- void page_update()
- {
- if(getCurrentPage() != SYSTEM_SCREEN_MAINTAIN)
- {
- setCurrentPage(SYSTEM_SCREEN_MAINTAIN);
- DEBUG_INFO("Setting page to update.\n");
- }
- else
- {}
- }
- 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
- {}
- }
- void page_unknown()
- {
- //DEBUG_INFO("Page unknown.\n");
- }
- void page_header(uint8_t gun_index, uint8_t system_mode)
- {
- setEthernetIcon();
- setBackendIcon();
- setWifi4GIcon();
- setWarningStatus(gun_index);
- // CHANGE LCD BRIGHNESS ( POWER SAVING 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) && (ShmSysConfigAndInfo->SysInfo.OcppConnStatus != ON))
- {
- setBillingFromWebsite();
- }
- else
- {
- // EVERY 5 SECONDS TO UPDATE PRICE
- if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PRICE]) > (TIME_REFRESH_TIME))
- {
- ftime(&startTime[gun_index][TMR_IDX_PRICE]);
- setBillingFromBackend(gun_index, system_mode);
- }
- }
- }
- void page_footer()
- {
- setRTC();
- }
- //=======================================
- // 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("Getting current page : [%d] \n", result);
- }
- else
- {
- DEBUG_INFO("Getting 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("Setting current page to : [%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()
- {
- // SET WIFI + 4G ICON STATUS ( ONLINE OR OFFLINE )
- 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 if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'E')
- {
- setDisplayValue(ICON_WIFI_CONNECTION, DISAPPEAR);
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- }
- else
- {
- // SET 4G ICON STATUS ( ONLINE OR OFFLINE )
- 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:
- // Clean icon
- 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);
- break;
- default:
- break;
- }
- }
- // SET WIFI ICON STATUS ( ONLINE OR OFFLINE)
- 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:
- // Clean icon
- setDisplayValue(ICON_4G_CONNECTION, DISAPPEAR);
- 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(ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
- }
- }
- else
- {
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- }
- }
- //=======================================
- // Setting currency ( WEB PAGE )
- //=======================================
- void setCurrencyFromWebsite(uint8_t unit)
- {
- uint8_t data[16];
- uint8_t currency[16];
- unsigned char kWh [16];
- uint8_t final_currency[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(currency, 0x00, ARRAY_SIZE(currency));
- memset(final_currency, 0x00, ARRAY_SIZE(final_currency));
- strcpy((char*)kWh, "/kWh");
- memcpy((char*)currency, Currency[unit], 3);
- sprintf((char *)final_currency, "%s%s", currency,kWh);
- string2ByteArray(final_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 final cost ( WEB PAGE )
- //=======================================
- void setPresentFinalCost(float cost)
- {
- uint8_t data[16];
- uint8_t finalCost[16];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(finalCost, 0x00, ARRAY_SIZE(finalCost));
- sprintf((char *)finalCost, "%.2f", cost);
- string2ByteArray(finalCost, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_COST_COMPLETE, data, ARRAY_SIZE(data));
- }
- //=======================================
- // Getting final cost ( WEB PAGE )
- //=======================================
- float getPresentFinalCost(uint8_t gun_index)
- {
- float result = 0.0f;
- for(int idx=0;idx<ARRAY_SIZE(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod);idx++)
- {
- result += ((ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idx]) * ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idx]);
- }
- return result;
- }
- //=======================================
- // Setting billing ( BACKEND )
- //=======================================
- void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
- {
- if((system("pidof -s OcppBackend > /dev/null") != 0))
- {
- // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
- 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)
- {
- /*
- * 1. SEARCHING DEFAULT PRICE FOR PRICE TEXT
- * 2. SEARCHING DEFAULT PRICE FOR CURRENCY AND UNIT TO APPEAR
- */
- setDefaultPrice(CURRENT_RATE);
- setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
- }
- else
- {
- /*
- * 1. IF STARTUSERID IS NOT MATCH WITH IDTOKEN ALSO VALUE CAN'T BE NULL, OTHERWISE THE SYSTEM MUST 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)))
- {
- /*
- * 1. SEARCHING USER PRICE FOR PRICE TEXT
- * 2. SEARCHING USER PRICE FOR CURRENCY AND UNIT TO APPEAR
- */
- setUserPrice(CURRENT_RATE);
- setCurrencyAndUnitFromBackend(SET_USER_PRICE, CURRENT_RATE,gun_index);
- }
- else
- {
- /*
- * 1. SEARCHING DEFAULT PRICE FOR PRICE TEXT
- * 2. SEARCHING DEFAULT PRICE FOR CURRENCY AND UNIT TO APPEAR
- */
- setDefaultPrice(CURRENT_RATE);
- setCurrencyAndUnitFromBackend(DEFAULE_PRICE, CURRENT_RATE, gun_index);
- }
- }
- }
- else
- {
- // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
- setDisplayValue(ICON_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_PRICE, DISAPPEAR);
- setDisplayValue(TEXT_CURRENCY_UNIT, DISAPPEAR);
- }
- }
- else
- {
- // DISPLAY BY OCPP 2.0.1
- }
- }
- else
- {
- // DISAPPEAR PRICE ICON, PRICE TEXT AND CURRENCY TEXT
- 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 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((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 ICON AND PRICE TEXT
- 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((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 ICON AND BALANCE TEXT
- 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 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((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 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 TEXT
- strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- 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 COST 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 TEXT
- strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- 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
- {
- /*
- * 1. DISAPPEAR ACCOUNT BALANCE WHEN THE SYSTEM IS COMPLETE MODE
- * 2. DISAPPEAR ACCOUNT ICON WHEN THE SYSTEM IS COMPLETE MODE
- */
- 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 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((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((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((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);
- }
- */
- if(ShmSysConfigAndInfo->SysConfig.isRFID == ON)
- setDisplayValue(ICON_NEW_RFID, NEW_RFID_ENABLE);
- else
- setDisplayValue(ICON_NEW_RFID, NEW_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, QRCODE_FOR_IDLE);
- }
- else
- {
- length = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
- setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, length, QRCODE_FOR_IDLE);
- }
- }
- else
- {
- setDisplayValue(TEXT_QRCODE_CONTENT, DISAPPEAR);
- setDisplayValue(ICON_QRCODE,QRCODE_DISABLE);
- }
- */
- if(ShmSysConfigAndInfo->SysConfig.isQRCode == ON)
- {
- setDisplayValue(ICON_NEW_QR_CODE,NEW_QRCODE_ENABLE);
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
- {
- length = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
- setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.SystemId, length, QRCODE_FOR_IDLE);
- }
- else
- {
- length = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
- setQRcodeContent((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, length, QRCODE_FOR_IDLE);
- }
- }
- else
- {
- setDisplayValue(TEXT_QRCODE_CONTENT, DISAPPEAR);
- setDisplayValue(ICON_NEW_QR_CODE,NEW_QRCODE_DISABLE);
- }
- }
- //=======================================
- // Setting QRCODE icon for receipt
- //=======================================
- void setQRCodeReceipt(uint8_t gun_index)
- {
- uint8_t length = 0;
- uint8_t data[128];
- int TransactionId;
- unsigned char QRCodeContent[128];
- unsigned char QRCodeReceipt[128];
- memset(QRCodeReceipt, 0x00, ARRAY_SIZE(QRCodeReceipt));
- memset(QRCodeReceipt, 0x00, ARRAY_SIZE(QRCodeReceipt));
- memset(data, 0x00, ARRAY_SIZE(data));
- strcpy((char*)QRCodeContent, "https://ocpp.phihong.com.tw/CDFA/");
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- TransactionId = ShmOCPP16Data->StopTransaction[gun_index].TransactionId;
- }
- else
- {}
- sprintf((char *)QRCodeReceipt, "%s%d", QRCodeContent,TransactionId);
- string2ByteArray(QRCodeReceipt, data);
- if(strstr((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, "phihong") && (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
- {
- length = strlen((char *)data);
- setQRcodeContent((char *)data, length, QRCODE_FOR_COMPLETE);
- }
- else
- {
- setDisplayValue(TEXT_QRCODE_RECEIPT, DISAPPEAR);
- }
- }
- //=======================================
- // Setting QR code content
- //=======================================
- void setQRcodeContent(char *input, uint8_t length, uint8_t mode)
- {
- uint8_t output[length];
- int loop = 0;
- input[length] = '\0';
- output[length] = '\0';
- while(input[loop] != '\0')
- {
- output[loop] = input[loop];
- loop++;
- }
- switch(mode)
- {
- case QRCODE_FOR_IDLE:
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
- break;
- case QRCODE_FOR_COMPLETE:
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_RECEIPT, output, ARRAY_SIZE(output)+1);
- break;
- default:
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_QRCODE_CONTENT, output, ARRAY_SIZE(output)+1);
- break;
- }
- }
- //=======================================
- // Setting warning page switch
- //=======================================
- void setWarningStatus(uint8_t gun_index)
- {
- /*
- * 1. WARNING COUNT IS DIFFERENT BETWEEN BEGINNING CHANGE DISPLAY
- * 2. WARNING COUNT BIGGER THAN 4 AND EVERY 5 SECONDS CHANGE NEXT PAGE
- */
- 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 TEXT (XXXXXX)
- 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));
- // ALARM CODE 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:
- // INITIALIZATION BATTERY ICON AND PERCENTAGE TEXT
- 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_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 ICON TO CHARGE OR DISCHARGE
- if(isCharging == YES)
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_LEFT);
- else
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, ELECTRICITY_DIRECTION_RIGHT);
- }
- else
- {
- // SET BATTERY PERCENTAGE TEXT TO DISAPPEAR
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
- {
- // 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
- {
- // SET BATTERY ICON TO EMPTY ICON
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
- // SET BATTERY PERCENTAGE TO DISAPPEAR
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- // RESET TO DEFAULT VALUE
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
- }
- }
- break;
- case SYS_MODE_TERMINATING:
- 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 DIRECTION ICON DISAPPEAR
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
- }
- else
- {
- // SET BATTERY ICON TO EMPTY ICON
- setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
- // SET BATTERY PERCENTAGE TO DISAPPEAR
- setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
- }
- break;
- case SYS_MODE_COMPLETE:
- 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 DIRECTION ICON DISAPPEAR
- setDisplayValue(ICON_ELECTRICITY_DIRECTION, DISAPPEAR);
- }
- else
- {
- // SET BATTERY ICON TO FULL BATTERY ICON
- setDisplayValue(ICON_BATTERY_COMPLETE, BATTERY_SOC_100);
- // SET BATTERY PERCENTAGE TO DISAPPEAR
- setDisplayValue(TEXT_PERCENTAGE, 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((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
- {
- 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]);
- }
- }
- else
- {
- 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;
- 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) ||
- (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) ||
- (ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON))
- {
- setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
- }
- else
- {
- 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]);
- }
- }
- }
- //=======================================
- // 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 power consumption
- //=======================================
- void setPresentPowerConsumption(uint8_t gun_index)
- {
- uint8_t data[32];
- uint8_t powerConsumption[32];
- memset(data, 0x00, ARRAY_SIZE(data));
- memset(powerConsumption, 0x00, ARRAY_SIZE(powerConsumption));
- sprintf((char *)powerConsumption, "%.4f kWh", ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
- string2ByteArray(powerConsumption, data);
- lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_POWER_CONSUMPTION, 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;
- uint32_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
- {}
- 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
- {}
- break;
- case UNKNOW_RFID:
- if(getCurrentPage() != SYSTEM_SCREEN_AUTH_UNKNOW)
- {
- setCurrentPage(SYSTEM_SCREEN_AUTH_UNKNOW);
- DEBUG_INFO("Setting page to authorizing : Unknown RFID\n");
- }
- else
- {}
- break;
- case DEFAULT_RFID:
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting default values
- //=======================================
- void setDefaultValue(uint8_t gun_index, uint8_t system_mode)
- {
- switch(system_mode)
- {
- case SYS_MODE_BOOTING:
- break;
- case SYS_MODE_IDLE:
- setBatteryAnimation(gun_index, system_mode);
- break;
- case SYS_MODE_AUTHORIZING:
- break;
- case SYS_MODE_PREPARING:
- // DEFAULT TIMER, ICON AND STATUS OF ANIMATION. ( BS / HLC ) MODE
- if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
- {
- setDisplayValue(ICON_CONNECTION_PRECHARGING, CONNECTION_QUESTION_MARK_1);
- setDisplayValue(ICON_BATTERY_PRECHARGING, BATTERY_CAPACITY_EMPTY);
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- }
- else
- {
- setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_1);
- GUN_PLUGING_LEVEL_STATUS = GUN_PLUGING_LEVEL_0;
- ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
- }
- break;
- case SYS_MODE_CHARGING:
- // DEFAULT TIMER, ICON AND STATUS OF ANIMATION
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- break;
- case SYS_MODE_TERMINATING:
- // DEFAULT TIMER, ICON AND STATUS OF ANIMATION
- setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
- ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
- CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_0;
- BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
- break;
- case SYS_MODE_COMPLETE:
- break;
- case SYS_MODE_ALARM:
- break;
- case SYS_MODE_FAULT:
- break;
- case SYS_MODE_MAINTAIN:
- break;
- case SYS_MODE_UPDATE:
- break;
- case SYS_MODE_RESERVATION:
- break;
- case SYS_MODE_BOOKING:
- break;
- case SYS_MODE_DEBUG:
- break;
- default:
- break;
- }
- }
- //=======================================
- // Setting receipt icon
- //=======================================
- void setReceiptIcon(uint8_t gun_index)
- {
- // DISPLAY FOR QR CODE RECEIPT
- if(strstr((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL, "phihong") && (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == ON))
- {
- setDisplayValue(ICON_THE_CHARGE_COMPLETE, DISAPPEAR);
- setDisplayValue(ICON_CONNECTION_COMPLETE, APPEAR);
- setQRCodeReceipt(gun_index);
- }
- else
- {
- setDisplayValue(ICON_THE_CHARGE_COMPLETE, APPEAR);
- setDisplayValue(ICON_CONNECTION_COMPLETE, APPEAR);
- setQRCodeReceipt(gun_index);
- }
- }
- //=======================================
- // 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;
- }
- //=======================================
- // Download image
- //=======================================
- int downloadBMP(uint8_t picIdx, char *filename)
- {
- int result = PASS;
- BMP *bmp;
- struct stat fileSt;
- uint32_t pageSize = 0xf0;
- uint32_t pixelSize;
- uint32_t transferedByte=0;
- uint16_t bufferRamAddr = 0x8000;
- uint32_t dataLen = 0;
- uint32_t startAddr=0;
- // Reset LCD
- uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) != PASS)
- {
- DEBUG_INFO("LCD reset fail.\n");
- }
- sleep(1);
- // Get image file size
- stat(filename, &fileSt);
- bmp = bopen(filename);
- uint8_t buf[bmp->width*bmp->height*2];
- DEBUG_INFO("Target address: %d\n", picIdx);
- DEBUG_INFO("Image filename: %s\n", filename);
- DEBUG_INFO("Image width: %d height: %d\n", bmp->width, bmp->height);
- DEBUG_INFO("Image data size: %d\n", ARRAY_SIZE(buf));
- // Get bmp pixel data and convert to 16 bit color
- for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
- {
- for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
- {
- uint8_t r, g, b;
- get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
- buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
- buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
- }
- }
- bclose(bmp);
- // Transfer pixel to screen page
- pixelSize = ARRAY_SIZE(buf);
- for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
- {
- //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
- //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
- uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
- if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
- {
- // Data transfer
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, (bufferRamAddr+(dataLen>>1)), &buf[(idxSrcData*pageSize)], pageSize) != PASS)
- {
- DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
- }
- transferedByte += pageSize;
- dataLen += pageSize;
- }
- else
- {
- // Last data transfer
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, (bufferRamAddr+(dataLen>>1)), &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))) != PASS)
- {
- DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
- }
- transferedByte += (pixelSize-(idxSrcData*pageSize));
- dataLen += (pixelSize-(idxSrcData*pageSize));
- }
- // Move data from ram to flash
- if((dataLen >= (pageSize*10)) || (idxSrcData == (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1)-1))
- {
- display_cmd[3] = ((dataLen>>1) >> 8) & 0xff; // Data length high byte
- display_cmd[4] = ((dataLen>>1) >> 0) & 0xff; // Data length low byte
- display_cmd[5] = (((startAddr)>>1) >> 16) & 0xff; // Screen on ram address 1st byte
- display_cmd[6] = (((startAddr)>>1) >> 8) & 0xff; // Screen on ram address 2nd byte
- display_cmd[7] = (((startAddr)>>1) >> 0) & 0xff; // Screen on ram address 3th byte
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) != PASS)
- {
- DEBUG_INFO("Write data to display buffer 0x%04X fail.\n", transferedByte);
- }
- startAddr += dataLen;
- dataLen = 0;
- }
- }
- // Save image to target address
- uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
- {
- DEBUG_INFO("Save image fail.\n");
- }
- DEBUG_INFO("Save image success.\n");
- sleep(1);
- return result;
- }
- //=======================================
- // Download image
- //=======================================
- int downloadBIN(uint8_t targetAddr, char *filename)
- {
- int result = PASS;
- int fd;
- struct stat fileSt;
- uint32_t pageSize = 128;
- uint32_t blocklSize = 32768;
- uint32_t transferedByte=0;
- uint16_t bufferRamAddr = 0x8000;
- // Reset LCD
- uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) != PASS)
- {
- DEBUG_INFO("LCD reset fail.\n");
- }
- sleep(1);
- // Get image file size
- stat(filename, &fileSt);
- uint8_t buf[(fileSt.st_size%32768==0?(fileSt.st_size/32768)*32768:(fileSt.st_size/32768)+1)*32768];
- DEBUG_INFO("Target address: %d\n", targetAddr);
- DEBUG_INFO("Bin filename: %s\n", filename);
- DEBUG_INFO("Bin data size: %d\n", fileSt.st_size);
- fd = open(filename, O_RDWR);
- if (fd < 0)
- {
- DEBUG_WARN("Bin can not be open.\n");
- result = FAIL;
- }
- else
- {
- // Read data from bin file
- memset(buf, 0x00, ARRAY_SIZE(buf));
- read(fd, buf, ARRAY_SIZE(buf));
- close(fd);
- for(uint8_t idxBinSrc=0;idxBinSrc<(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1);idxBinSrc++)
- {
- // Transfer data to ram
- for(uint16_t idxSrcData=0;idxSrcData<(((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1);idxSrcData++)
- {
- //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxBinSrc*blocklSize)+(idxSrcData*pageSize));
- //DEBUG_INFO(" Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
- if((idxSrcData+1) != (((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1))
- {
- // Data transfer
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], pageSize) != PASS)
- {
- DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
- }
- transferedByte += pageSize;
- }
- else
- {
- // Last data transfer
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], (blocklSize-(idxSrcData*pageSize)))!= PASS)
- {
- DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
- }
- transferedByte += (blocklSize-(idxSrcData*pageSize));
- }
- }
- // Move data from ram to flash
- 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};
- while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xaa, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
- {
- DEBUG_INFO("Save bin file to 0x%04X fail.\n", ((targetAddr*8)+idxBinSrc));
- }
- DEBUG_INFO("Save bin file on 0x%04X success.\n", ((targetAddr*8)+idxBinSrc));
- sleep(1);
- }
- }
- return result;
- }
- //=======================================
- // LCD upgrade
- //=======================================
- int lcdUpgrade(char *forlder)
- {
- int result = PASS;
- DIR *dir;
- struct dirent *file;
- struct stat fileSt;
- if ((dir = opendir (forlder)) != NULL)
- {
- /* print all the files and directories within directory */
- while ((file = readdir (dir)) != NULL)
- {
- if((strlen(file->d_name)>2))
- {
- int targetAddr;
- stat(file->d_name, &fileSt);
- if(sscanf(file->d_name, "%d", &targetAddr) == 1)
- {
- char targetFile[384];
- sprintf(targetFile, "/mnt/lcd/%s", file->d_name);
- if(strstr(file->d_name, ".bmp") != NULL)
- {
- downloadBMP(targetAddr, targetFile);
- }
- else
- {
- downloadBIN(targetAddr, targetFile);
- }
- }
- else
- {
- DEBUG_WARN("%s can not parse target address.\n", file->d_name);
- }
- }
- else
- {
- if(strlen(file->d_name) >= 3)
- {
- DEBUG_ERROR("File name error.\n");
- result = FAIL;
- }
- else
- {
- DEBUG_INFO("Searching file.\n");
- }
- }
- sleep(1);
- }
- closedir (dir);
- }
- else
- {
- DEBUG_ERROR("%s does not valid.\n", forlder);
- result = FAIL;
- }
- return result;
- }
- //=======================================
- // 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(ShmCharger->isUpgradeLcmReq)
- {
- ShmCharger->isUpgradeLcmSuccess = ((lcdUpgrade("/mnt/lcd") == PASS) ? YES : NO);
- ShmCharger->isUpgradeLcmReq = OFF;
- }
- else
- {
- if(previousMode != ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus)
- {
- previousMode = ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus;
- }
- if(ShmCharger->isAuthrizing || ShmCharger->isGetAuthResult)
- {
- if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) >= TIME_AUTH_RESULT_TIME)
- ShmCharger->isGetAuthResult = FALSE;
- if(DiffTimebWithNow(startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]) < TIME_AUTH_RESULT_TIME)
- page_authorizing(ShmCharger->gun_selectd);
- else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus == SYS_MODE_IDLE) && (ShmCharger->gun_info[ShmCharger->gun_selectd].resultAuthorization == VALIDATED_RFID))
- page_preparing(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- }
- else
- {
- ftime(&startTime[ShmCharger->gun_selectd][TMR_IDX_SHOW_AUTH_RESULT]);
- 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();
- page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
- 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);
- page_footer();
- }
- usleep(100000);
- }
- return FAIL;
- }
|