12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include <stdbool.h>
- #include <dirent.h>
- #include <signal.h>
- #include "../Config.h"
- #include "main.h"
- #include "../common.h"
- #include "../timeout.h"
- #include "../Log/log.h"
- #include "../DataBase/DataBase.h"
- #include "../Define/define.h"
- #include "../ShareMemory/shmMem.h"
- #include "../SelectGun/SelectGun.h"
- //------------------------------------------------------------------------------
- static struct SysInfoData *pSysInfo = NULL;
- static struct SysConfigData *pSysConfig = NULL;
- static struct WARNING_CODE_INFO *pSysWarning = NULL;
- static struct AlarmCodeData *pAlarmCode = NULL;
- static struct FaultCodeData *pFaultCode = NULL;
- static struct InfoCodeData *pInfoCode = NULL;
- static struct PsuData *ShmPsuData = NULL;
- static struct CHAdeMOData *ShmCHAdeMOData = NULL;
- static struct GBTData *ShmGBTData = NULL;
- static struct CcsData *ShmCcsData = NULL;
- static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
- static struct FanModuleData *ShmFanModuleData = NULL;
- static struct RelayModuleData *ShmRelayModuleData = NULL;
- static struct LedModuleData *ShmLedModuleData = NULL;
- static struct OCPP16Data *ShmOCPP16Data = NULL;
- static DcCommonInfo *ShmDcCommonData = NULL;
- static struct ChargingInfoData *pDcChargingInfo = NULL;
- static struct ChargingInfoData *pAcChargingInfo = NULL;
- static struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- static SelectGunInfo *ShmSelectGunInfo = NULL; //Jerry add
- static EvBoardErrMsg gEvBoardErr = {0};
- static ChillerTempErr gChillerTempErr = {0};
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- // for initial index to check EV board type is correct
- uint8_t bd0_1_status = 0;
- uint8_t bd0_2_status = 0;
- uint8_t bd1_1_status = 0;
- uint8_t bd1_2_status = 0;
- char *fwVersion = "V2.01.00.0000.00"; // Phihong version
- char* DebugVersion = "v2.01.00"; // Software debug version
- //sqlite3 *localDb;
- bool isDb_ready;
- //------------------------------------------------------------------------------
- void ClearDetectPluginFlag();
- long long DiffTimebWithNow(struct timeb ST);
- uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
- void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
- unsigned long GetTimeoutValue(struct timeval _sour_time);
- void GetClockTime(struct timespec *_now_time, void *null);
- unsigned long GetClockTimeoutValue(struct timespec _start_time);
- void gpio_set_value(unsigned int gpio, unsigned int value);
- void InformOcppErrOccur(uint8_t codeType);
- void RecordAlarmCode(uint8_t gunIndex, char *code);
- void ReleaseAlarmCode(uint8_t gunIndex);
- void ResetChargerAlarmCode(uint8_t gunIndex, char *code);
- void AdjustChargerCurrent(void);
- void UpdateErrorCodeToOcpp(uint8_t index);
- //------------------------------------------------------------------------------
- //Primary.c
- extern void ChkPrimaryStatus(void);
- //RFID.c
- extern void CreateRfidFork(void);
- extern void ScannerCardProcess(void);
- extern bool RfidStopCharging(void);
- extern bool GetIsCardScan(void);
- extern void SetIsCardScan(bool value);
- //SelfTest.c
- extern void SelfTestRun(void);
- //UpgradeFW.c
- /*extern void CheckFwUpdateFunction(void);*/
- //Ethernet.c
- extern void InitEthernet(void);
- extern void GetMacAddress(void);
- //WatchDog.c
- extern void CreateWatchdog(void);
- extern void TryCloseWatchdog(void);
- extern void TryFeedWatchdog(void);
- //ZipFile.c
- extern void zipLogFiles(void);
- //------------------------------------------------------------------------------
- //--- share memory value ---
- //------------------------------------------------------------------------------
- static void changeLcmPage(uint8_t index)
- {
- pSysInfo->SystemPage = index;
- }
- static uint8_t getCurLcmPage(void)
- {
- return pSysInfo->SystemPage;
- }
- static void systemPageRestoreInit(void)
- {
- pSysInfo->SystemPage = _PAGE_IDLE;
- }
- //------------------------------------------------------------------------------
- void destroySelGun(uint8_t curGun)
- {
- uint8_t i = 0;
- uint8_t totalGun = pSysConfig->TotalConnectorCount;
- //for status timeout
- if (curGun == DESTROY_ALL_SEL) {
- ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
- ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
- log_info("destroy all gun = %d, %d",
- ShmSelectGunInfo->SelGunInfo.LeftGun,
- ShmSelectGunInfo->SelGunInfo.RightGun);
- for (i = 0; i < totalGun; i++) {
- StopGunInfoTimeoutDet(i);
- memset(&ShmSelectGunInfo->PricesInfo[i], 0, sizeof(PricesInfo));
- }
- pSysInfo->CurGunSelected = 0;
- strcpy((char *)pSysConfig->UserId, "");
- //changeLcmPage(_LCM_VIEW);
- return;
- }
- //for charging timeout or complete
- if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
- if (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
- ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR) {
- changeLcmPage(_PAGE_SELECT_GUN);
- }
- ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
- StopGunInfoTimeoutDet(LEFT_GUN_NUM);
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
- ClearAuthorizedFlag();
- }
- log_info("destroy left gun, cur page = %d", getCurLcmPage());
- if (getCurLcmPage() == pSysInfo->SystemPage) {
- log_info("clear left balance");
- memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
- ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
- }
- }
- if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
- if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
- ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
- changeLcmPage(_PAGE_SELECT_GUN);
- }
- ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
- StopGunInfoTimeoutDet(RIGHT_GUN_NUM);
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
- ClearAuthorizedFlag();
- }
- log_info("destroy right gun, cur page = %d", getCurLcmPage());
- if (getCurLcmPage() == pSysInfo->SystemPage) {
- log_info("clear right balance");
- memset(&ShmSelectGunInfo->PricesInfo[curGun], 0, sizeof(PricesInfo));
- ShmSelectGunInfo->PricesInfo[curGun].Balance = FAIL_BALANCE_PRICES;
- }
- }
- }
- static int waitRightGunPlugIt(uint8_t curGun)
- {
- if ((curGun == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
- return PASS;
- }
- return FAIL;
- }
- static int waitLeftGunPlugIt(uint8_t curGun)
- {
- if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
- return PASS;
- }
- return FAIL;
- }
- void setSelGunWaitToAuthor(uint8_t curSel)
- {
- if (curSel == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM) {
- ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_ATHOR;
- log_info("setSelGunWaitToAuthor left");
- StopGunInfoTimeoutDet(curSel);
- } else if (curSel == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM) {
- ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_ATHOR;
- log_info("setSelGunWaitToAuthor right");
- StopGunInfoTimeoutDet(curSel);
- }
- }
- int getConfirmSelectedGun(uint8_t curSel)
- {
- if (((curSel == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun >= SEL_GUN_CONFIRM)) ||
- ((curSel == RIGHT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.RightGun >= SEL_GUN_CONFIRM))) {
- return PASS;
- }
- return FAIL;
- }
- void confirmSelGun(uint8_t selGun)
- {
- if (selGun == LEFT_GUN_NUM) {
- ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
- //printf("confirmSelGun left");
- } else if (selGun == RIGHT_GUN_NUM) {
- ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
- //printf("confirmSelGun right");
- }
- //changeLcmPage(_PAGE_PLUGIN);
- //StartGunInfoTimeoutDet(selGun, Timeout_SelectGun);
- //StartSystemTimeoutDet(Timeout_ReturnViewPage);
- }
- static void GetFirmwareVersion(void)
- {
- // Get CSU root file system version
- sprintf((char *)pSysInfo->CsuRootFsFwRev, fwVersion);
- uint8_t count = 0, chademo = 0, ccs = 0, gb = 0;
- for (uint8_t idx = 0; idx < 3; idx++) {
- if (pSysConfig->ModelName[7 + idx] == 'J') {
- chademo++;
- count++;
- } else if (pSysConfig->ModelName[7 + idx] == 'G') {
- gb++;
- count++;
- } else if (pSysConfig->ModelName[7 + idx] == 'U' ||
- pSysConfig->ModelName[7 + idx] == 'V' ||
- pSysConfig->ModelName[7 + idx] == 'E') {
- ccs++;
- count++;
- }
- }
- if (count == 1) {
- if (chademo > 0) {
- pSysInfo->CsuRootFsFwRev[7] = '1';
- } else if (ccs > 0) {
- pSysInfo->CsuRootFsFwRev[7] = '2';
- } else if (gb > 0) {
- pSysInfo->CsuRootFsFwRev[7] = '3';
- }
- } else {
- if (chademo > 0 && ccs > 0) {
- pSysInfo->CsuRootFsFwRev[7] = '4';
- } else if (chademo > 0 && gb > 0) {
- pSysInfo->CsuRootFsFwRev[7] = '5';
- } else if (ccs > 0 && gb > 0) {
- pSysInfo->CsuRootFsFwRev[7] = '6';
- }
- }
- // Get network option from model name
- switch (pSysConfig->ModelName[10]) {
- case 'B':
- case 'U':
- //Blue tooth
- pSysInfo->CsuRootFsFwRev[9] = '3';
- break;
- case 'W':
- // WIFI
- pSysInfo->CsuRootFsFwRev[9] = '1';
- break;
- case 'T':
- // 3G/4G
- pSysInfo->CsuRootFsFwRev[9] = '2';
- break;
- case 'D': //DS60-120 add
- pSysInfo->CsuRootFsFwRev[9] = '5';
- break;
- default:
- // LAN
- pSysInfo->CsuRootFsFwRev[9] = '0';
- break;
- }
- // Get rating power from model name
- memcpy(&pSysInfo->CsuRootFsFwRev[10], &pSysConfig->ModelName[4], 0x03);
- // Get IEC or UL
- char _buf[3] = {0};
- memcpy(_buf, &pSysConfig->ModelName[2], 2);
- if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL) {
- pSysInfo->ChargerType = _CHARGER_TYPE_IEC;
- log_info("IEC model");
- } else if (strcmp(_buf, "WU") == EQUAL) {
- pSysInfo->ChargerType = _CHARGER_TYPE_UL;
- log_info("UL model");
- }
- }
- static void checkGunOTPState(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- //水冷機溫度檢測
- if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
- if (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP) {
- if (pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) {
- if (((gunIndex == 0) &&
- ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
- ||
- ((gunIndex == 1) &&
- ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
- ) {
- RecordAlarmCode(gunIndex, "012323");
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
- }
- else
- {
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
- }
- } else if (pDcChargingInfo->ChillerTemp != 0 &&
- pDcChargingInfo->ChillerTemp < GUN_OTP_RECOVERY) {
- //ResetChargerAlarmCode(gunIndex, "012323");
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
- }
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
- } else {
- // 沒接上 Sensor or 異常
- //RecordAlarmCode(gunIndex, "011038");
- //ResetChargerAlarmCode(gunIndex, "012323");
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
- if (((gunIndex == 0) &&
- ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
- ||
- ((gunIndex == 1) &&
- ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
- ) {
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
- }
- else
- {
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
- }
- }
- if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES)
- {
- RecordAlarmCode(gunIndex, "011037");
- }
- }
- switch (pDcChargingInfo->Type) {
- case _Type_Chademo:
- if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
- if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
- RecordAlarmCode(gunIndex, "012229");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
- } else if (pDcChargingInfo->ConnectorTemp != 0 &&
- pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
- //ResetChargerAlarmCode(gunIndex, "012229");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- }
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
- } else {
- // 沒接上 Sensor or 異常
- //RecordAlarmCode(gunIndex, "011018");
- //ResetChargerAlarmCode(gunIndex, "012229");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
- if ((gunIndex == 0) &&
- (strncmp((char *)&pSysConfig->ModelName[7], "J", 1) == 0)) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
- } else if ((gunIndex == 1) &&
- ((strncmp((char *)&pSysConfig->ModelName[9], "J", 1) == 0) )) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
- }
- }
- break;
- case _Type_CCS_2:
- // CCS 不管甚麼輸出都會有槍溫偵測!!~
- if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
- //ResetChargerAlarmCode(gunIndex, "011019");
- if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
- RecordAlarmCode(gunIndex, "012230");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
- } else if (pDcChargingInfo->ConnectorTemp != 0 &&
- pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
- //ResetChargerAlarmCode(gunIndex, "012230");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
- }
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
- //ResetChargerAlarmCode(gunIndex, "011019");
- } else {
- // 沒接上 Sensor or 異常
- //RecordAlarmCode(gunIndex, "011019");
- //ResetChargerAlarmCode(gunIndex, "012230");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
- }
- break;
- case _Type_GB:
- if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
- if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
- RecordAlarmCode(gunIndex, "012231");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
- } else if (pDcChargingInfo->ConnectorTemp != 0 &&
- pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
- //ResetChargerAlarmCode(gunIndex, "012231");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
- }
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
- } else {
- // 沒接上 Sensor or 異常
- //RecordAlarmCode(gunIndex, "011020");
- //ResetChargerAlarmCode(gunIndex, "012231");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
- }
- break;
- }
- }
- static void collectError(uint8_t gunIndex)
- {
- gEvBoardErr.GunErrMessage |= ShmDcCommonData->ConnectErrList[gunIndex].GunErrMessage;
- gChillerTempErr.TempErrMsg |= ShmDcCommonData->ChillerTempErr[gunIndex].TempErrMsg;
- }
- static void checkGBTAlarmState(uint8_t gunType)
- {
- // GFD Trip
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
- pAlarmCode->AlarmEvents.bits.GbGfdTrip = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.GbGfdTrip = NO;
- }
- // UVP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
- pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.GbtOutputUVPFail = NO;
- }
- // OTP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
- pAlarmCode->AlarmEvents.bits.GbConnectorOTP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.GbConnectorOTP = NO;
- }
- // OVP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
- pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
- }
- // GFD Warning
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
- pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.GbGroundfaultWarning = NO;
- }
- // Relay Welding
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
- pFaultCode->FaultEvents.bits.GbOutputRelayWelding = YES;
- } else {
- pFaultCode->FaultEvents.bits.GbOutputRelayWelding = NO;
- }
- // Relay Driving
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
- pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = YES;
- } else {
- pFaultCode->FaultEvents.bits.GbOutputRelayDrivingFault = NO;
- }
- // Connect temp Sensor broken
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
- pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = YES;
- } else {
- pFaultCode->FaultEvents.bits.GbConnectorTempSensorBroken = NO;
- }
- }
- static void checkCCSAlarmState(uint8_t gunType)
- {
- // GFD Trip
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
- pAlarmCode->AlarmEvents.bits.CcsGfdTrip = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.CcsGfdTrip = NO;
- }
- // UVP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
- pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.CcsOutputUVPFail = NO;
- }
- // OTP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
- pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.CcsConnectorOTP = NO;
- }
- // OVP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
- pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
- }
- // GFD Warning
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
- pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.CcsGroundfaultWarning = NO;
- }
- // Relay Welding
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
- pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = YES;
- } else {
- pFaultCode->FaultEvents.bits.CcsOutputRelayWelding = NO;
- }
- // Relay Driving
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
- pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
- } else {
- pFaultCode->FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
- }
- // Connect temp Sensor broken
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
- pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
- } else {
- pFaultCode->FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
- }
- }
- static void checkChaDeMoAlarmState(uint8_t gunType)
- {
- // GFD Trip
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 0)) {
- pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.ChademoGfdTrip = NO;
- }
- // UVP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 1)) {
- pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.ChademoOutputUVPFail = NO;
- }
- // OTP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 2)) {
- pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.ChademoConnectorOTP = NO;
- }
- // OVP
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 3)) {
- pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
- }
- // GFD Warning
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 4)) {
- pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.ChademoGroundWarning = NO;
- }
- // Relay Welding
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 5)) {
- pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = YES;
- } else {
- pFaultCode->FaultEvents.bits.ChademoOutputRelayWelding = NO;
- }
- // Relay Driving
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 6)) {
- pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
- } else {
- pFaultCode->FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
- }
- // Connect temp Sensor broken
- if (DetectBitValue(gEvBoardErr.GunErrMessage >> (8 * gunType), 7)) {
- pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
- } else {
- pFaultCode->FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
- }
- }
- static void checkChillerAlarmState(void)
- {
- if (DetectBitValue(gChillerTempErr.TempErrMsg, 0)) {
- pAlarmCode->AlarmEvents.bits.SystemChillerOTP = YES;
- } else {
- pAlarmCode->AlarmEvents.bits.SystemChillerOTP = NO;
- }
- if (DetectBitValue(gChillerTempErr.TempErrMsg, 1)) {
- pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = YES;
- } else {
- pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
- }
- }
- static void checkEvBoardAlarmState(uint8_t gunType)
- {
- switch (gunType) {
- case _Type_Chademo:
- checkChaDeMoAlarmState(gunType);
- break;
- case _Type_CCS_2:
- checkCCSAlarmState(gunType);
- break;
- case _Type_GB:
- checkGBTAlarmState(gunType);
- break;
- }
- }
- unsigned long GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
- }
- void GetClockTime(struct timespec *_now_time, void *null)
- {
- clock_gettime(CLOCK_MONOTONIC, _now_time);
- }
- // return value unit: 1us
- unsigned long GetClockTimeoutValue(struct timespec _start_time)
- {
- struct timespec ts_end;
- unsigned long ret = 0;
- clock_gettime(CLOCK_MONOTONIC, &ts_end);
- ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
- return ret;
- }
- 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;
- return (StopTime - StartTime);
- }
- bool CheckTimeOut(struct timeb ST)
- {
- struct timeb ET;
- unsigned int StartTime, StopTime;
- ftime(&ET);
- StartTime = (unsigned int) ST.time;
- StopTime = (unsigned int) ET.time;
- return (StopTime > StartTime) ? YES : NO;
- }
- void setChargerMode(uint8_t gunIndex, uint8_t mode)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- pDcChargingInfo->SystemStatus = mode;
- }
- 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);
- }
- //==========================================
- // Log
- //==========================================
- void CheckFwSlotStatusLog(void)
- {
- if (bd0_1_status == 0 && bd0_2_status == 1) {
- log_info("Connector 1 : Chademo");
- } else if (bd0_1_status == 1 && bd0_2_status == 0) {
- log_info("Connector 1 : CCS");
- } else if (bd0_1_status == 1 && bd0_2_status == 1) {
- log_info("Connector 1 : GB");
- }
- if (bd1_1_status == 0 && bd1_2_status == 1) {
- log_info("Connector 2 : Chademo");
- } else if (bd1_1_status == 1 && bd1_2_status == 0) {
- log_info("Connector 2 : CCS");
- } else if (bd1_1_status == 1 && bd1_2_status == 1) {
- log_info("Connector 2 : GB");
- }
- }
- void CheckHwSlotStatusLog(uint8_t index)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- log_info("Hw check : Connector %d, Type : Chademo, Evboard_id = %d ",
- index, pDcChargingInfo->Evboard_id);
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- log_info("Hw check : Connector %d, Type : CCS, Evboard_id = %d ",
- index, pDcChargingInfo->Evboard_id);
- } else if (pDcChargingInfo->Type == _Type_GB) {
- log_info("Hw check : Connector %d, Type : GB, Evboard_id = %d ",
- index, pDcChargingInfo->Evboard_id);
- }
- }
- //=================================
- // LCM Page
- //=================================
- void ChangeLcmByIndex(uint8_t page_index)
- {
- if (pSysWarning->Level != WARN_LV_ER
- ) {
- pSysInfo->PageIndex = page_index;
- //log_info("LCM index:%d",pSysInfo->PageIndex);
- }
- }
- //======================================================
- // Peripheral initial
- //======================================================
- void InitGPIO()
- {
- /*****************0~3, 4 bank, bank x 32+ num*********************/
- /***************************************************************/
- /*************** GPIO 0 ***************************************/
- /***************************************************************/
- /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
- /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
- /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/
- system("echo 26 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio26/direction");
- system("echo 1 > /sys/class/gpio/gpio26/value");
- /* GPMC_AD11 => GPIO0_27 *//*IO BD1_2*/
- system("echo 27 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio27/direction");
- /* RMII1_REF_CLK => GPIO0_29 *//*USB 0 OCP detection*/
- system("echo 29 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio29/direction");
- /*XDMA_EVENT_INTR0 => GPIO0_19 *//*AM_RFID_RST*/
- system("echo 19 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio19/direction");
- system("echo 1 > /sys/class/gpio/gpio19/value");
- /*XDMA_EVENT_INTR1 => GPIO0_20 *//*AM_RFID_ICC*/
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
- /***************************************************************/
- /*************** GPIO 1 ***************************************/
- /***************************************************************/
- /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
- /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
- /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/
- system("echo 46 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio46/direction");
- system("echo 0 > /sys/class/gpio/gpio46/value");
- /* GPMC_AD15 => GPIO1_15 *//*IO BD2_2*/
- system("echo 47 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio47/direction");
- /***************************************************************/
- /*************** GPIO 2 ***************************************/
- /***************************************************************/
- /*LCD_AC_BIAS_EN => GPIO2_25*//*RS-485 for module DE control*/
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 1 > /sys/class/gpio/gpio89/value");
- /*LCD_HSYNC => GPIO2_23*//*RS-485 for module RE control*/
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio87/direction");
- system("echo 0 > /sys/class/gpio/gpio87/value");
- /*LCD_PCLK => GPIO2_24*//*CCS communication board 1 proximity*/
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
- /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio86/direction");
- /***************************************************************/
- /*************** GPIO 3 ***************************************/
- /***************************************************************/
- /*MCASP0_FSX => GPIO3_15*//*Emergency Stop button detect*/
- system("echo 111 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio111/direction");
- /*MCASP0_ACLKR => GPIO3_18*//*USB1 OCP detect*/
- system("echo 114 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio114/direction");
- /*MCASP0_AHCLKR => GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
- system("echo 113 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio113/direction");
- /*MCASP0_ACLKX => GPIO3_14*//*Ethernet PHY reset*/
- system("echo 110 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio110/direction");
- system("echo 0 > /sys/class/gpio/gpio110/value");
- /* MCASP0_FSR => GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
- system("echo 115 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio115/direction");
- system("echo 0 > /sys/class/gpio/gpio115/value");
- /* MCASP0_AXR0 => GPIO3_16 *//*CSU board function OK indicator.*/
- system("echo 112 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio112/direction");
- system("echo 1 > /sys/class/gpio/gpio112/value");
- /* MCASP0_AXR1 => GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
- system("echo 116 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio116/direction");
- system("echo 0 > /sys/class/gpio/gpio116/value");
- log_info("Initial GPIO OK");
- return ;
- }
- int LoadSysConfigAndInfo()
- {
- int fd, wrd;
- unsigned char *buf;
- unsigned int ChkSum, ChkSumOrg;
- if ((buf = malloc(MtdBlockSize)) == NULL) {
- log_error("malloc buffer NG,rebooting..");
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- //================================================
- // Load configuration from mtdblock10
- //================================================
- system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if (fd < 0) {
- free(buf);
- log_error("open mtdblock10 NG,rebooting..");
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- free(buf);
- log_error("read SysConfigData data NG,rebooting..");
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- memcpy(&pSysConfig->ModelName, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), ARRAY_SIZE(pSysConfig->ModelName));
- memcpy(&pSysConfig->SerialNumber, buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), ARRAY_SIZE(pSysConfig->SerialNumber));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if (ChkSum != ChkSumOrg) {
- log_error("Primary SysConfigData checksum NG, read backup");
- system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if (fd < 0) {
- free(buf);
- log_error("open mtdblock11 (backup) NG,rebooting..");
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- free(buf);
- log_error("read backup SysConfigData data NG,rebooting..");
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if (ChkSum != ChkSumOrg) {
- log_warn("backup SysConfigData checksum NG, read Factory default");
- system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if (fd < 0) {
- log_error("open mtdblock12 (Factory default) NG,rebooting..");
- free(buf);
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- wrd = read(fd, buf, MtdBlockSize);
- close(fd);
- if (wrd < MtdBlockSize) {
- log_error("read factory default SysConfigData data NG,rebooting..");
- free(buf);
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for (wrd = ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++) {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev)), &pSysConfig->ModelName, ARRAY_SIZE(pSysConfig->ModelName));
- memcpy(buf + (ARRAY_SIZE(pSysConfig->CsuBootLoadFwRev) + ARRAY_SIZE(pSysConfig->ModelName) + ARRAY_SIZE(pSysConfig->AcModelName)), &pSysConfig->SerialNumber, ARRAY_SIZE(pSysConfig->SerialNumber));
- if (ChkSum != ChkSumOrg) {
- log_warn("factory default SysConfigData checksum NG, restore factory default");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy(pSysConfig, buf, sizeof(struct SysConfigData));
- free(buf);
- system("rm -f /mnt/EvseConfig.bin");
- // SysConfig in flash is empty (0xffffffff)
- if ((strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) ||
- (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) ||
- (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) ||
- (pSysConfig->Eth0Interface.EthDhcpClient == 0xff)) {
- if (strlen((char *)pSysConfig->ModelName) > ARRAY_SIZE(pSysConfig->ModelName)) {
- memset(pSysConfig->ModelName, 0x00, ARRAY_SIZE(pSysConfig->ModelName));
- }
- if (strlen((char *)pSysConfig->SerialNumber) > ARRAY_SIZE(pSysConfig->SerialNumber)) {
- memset(pSysConfig->SerialNumber, 0x00, ARRAY_SIZE(pSysConfig->SerialNumber));
- }
- if (strlen((char *)pSysConfig->SystemId) > ARRAY_SIZE(pSysConfig->SystemId)) {
- memset(pSysConfig->SystemId, 0x00, ARRAY_SIZE(pSysConfig->SystemId));
- }
- if (pSysConfig->Eth0Interface.EthDhcpClient == 0xff) {
- log_info("Ethernet dhcp config is null.");
- }
- if (strlen((char *)pSysConfig->ModelName) == 0x00) {
- log_info("Model name over length.");
- }
- if (strlen((char *)pSysConfig->SerialNumber) == 0x00) {
- log_info("Model serial number over length.");
- }
- if (strlen((char *)pSysConfig->SystemId) == 0x00) {
- log_info("SystemId over length.");
- }
- system("cd /root;./FactoryConfig -m");
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- }
- log_info("Load SysConfigData OK");
- return PASS;
- }
- int Initialization(void)
- {
- uint8_t count = 0;
- uint8_t pinOut[2] = {116, 115};
- // 初始化卡號驗證的 Flag
- ClearAuthorizedFlag();
- // 初始化插槍驗證的 Flag
- ClearDetectPluginFlag();
- for (count = 0; count < pSysConfig->TotalConnectorCount; count++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
- pDcChargingInfo->RemoteStartFlag = NO;
- if (pDcChargingInfo->Type == _Type_Chademo) {
- gpio_set_value(pinOut[count], 0x00);
- ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- gpio_set_value(pinOut[count], 0x00);
- ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = NO;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- //if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) { //DS60-120 remove
- if (pSysConfig->TotalConnectorCount == 1) {
- gpio_set_value(pinOut[1], 0x01);
- } else {
- gpio_set_value(pinOut[count], 0x01);
- }
- ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = NO;
- //}
- }
- strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
- }
- for (count = 0; count < pSysConfig->AcConnectorCount; count++) {
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
- pAcChargingInfo->RemoteStartFlag = NO;
- if (pAcChargingInfo->Type == _Type_AC) {
- pAcChargingInfo->SelfTest_Comp = NO;
- strcpy((char *)ShmOCPP16Data->StatusNotification[count + pSysConfig->TotalConnectorCount].ErrorCode, "NoError");
- }
- }
- return PASS;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo();
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- return result;
- }
- //顯示自檢錯誤原因,觸發對應的flag
- bool DisplaySelfTestFailReason()
- {
- bool result = false;
- uint8_t index = 0;
- // RB、FB、407、EV 小板中有些板子無回應
- if (ShmRelayModuleData->SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.RelayboardStestFail = true;
- }
- if (ShmFanModuleData->SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.FanboardStestFail = true;
- }
- if (ShmPrimaryMcuData->SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.PrimaryStestFail = true;
- }
- if (ShmLedModuleData->SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.LedboardStestFail = true;
- }
- for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.ChademoboardStestFail = true;
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.GbtboardStestFail = true;
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
- if (ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.CCSboardStestFail = true;
- }
- }
- }
- }
- for (index = 0; index < pSysConfig->AcConnectorCount; index++) {
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(index);
- // 先借 GBT 顯示
- if (pAcChargingInfo->SelfTest_Comp == NO) {
- pAlarmCode->AlarmEvents.bits.AcConnectorStestFail = true;
- }
- }
- if (pSysInfo->AcContactorStatus == NO) {
- #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox &&!defined DD360UCar
- // AC Contact 未搭上
- pAlarmCode->AlarmEvents.bits.AcContactStestFail = true;
- result = true;
- #endif // !defined DD360 && !defined DD360Audi && !defined DD360ComBox
- }
- //else if (pAlarmCode->AlarmEvents.bits.PsuDipSwitchStestFail == YES) { //DS60-120 add
- // result = true;
- //}
- else if (ShmPsuData->SystemAvailablePower <= 0 &&
- ShmPsuData->SystemAvailableCurrent <= 0) {
- // PSU 通訊問題
- pAlarmCode->AlarmEvents.bits.PsuModuleStestFail = true;
- result = true;
- }
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- int isEvBoardStopChargeFlag(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- //printf("StopChargeFlag = %d", chargingInfo[gunIndex]->StopChargeFlag);
- return pDcChargingInfo->StopChargeFlag;
- }
- bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- return pDcChargingInfo->NormalStopChargeFlag;
- }
- //===============================================
- // 掃描插槍狀況
- //===============================================
- void ClearDetectPluginFlag(void)
- {
- uint8_t gunIndex = 0;
- pSysInfo->WaitForPlugit = NO;
- //DS60-120 add
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- /*
- if (pDcChargingInfo->RemoteStartFlag == YES) {
- pDcChargingInfo->RemoteStartFlag = NO;
- }
- */
- }
- if (pSysInfo->OrderCharging != NO_DEFINE) {
- pSysInfo->OrderCharging = NO_DEFINE;
- }
- }
- void DetectPluginStart()
- {
- pSysInfo->WaitForPlugit = YES;
- }
- bool isDetectPlugin()
- {
- if (pSysInfo->WaitForPlugit == YES) {
- return true;
- }
- return false;
- }
- //===============================================
- // Common Detect Chk - Chademo
- //===============================================
- bool isEvGunLocked_chademo(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
- }
- bool isEvContactorWelding_chademo(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 3);
- }
- bool isEvStopReq_chademo(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- return DetectBitValue(ShmCHAdeMOData->ev[pDcChargingInfo->type_index].EvDetection, 4);
- }
- bool isEvStopCharging_chademo(uint8_t gunIndex)
- {
- if (isEvGunLocked_chademo(gunIndex) == NO) {
- // 無鎖槍 = 停止
- log_info("gun locked none (%d) ", gunIndex);
- return YES;
- }
- return NO;
- }
- uint8_t isPrechargeStatus_chademo(uint8_t gunIndex)
- {
- uint8_t result = 0x00;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- result = ShmCHAdeMOData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - GB
- //===============================================
- bool isEvGunLocked_gb(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
- }
- bool isEvStopCharging_gb(uint8_t gunIndex)
- {
- if (isEvGunLocked_gb(gunIndex) == NO) {
- // 無鎖槍 = 停止
- log_info("gun locked none. ");
- return YES;
- }
- return NO;
- }
- uint8_t isPrechargeStatus_gb(uint8_t gunIndex)
- {
- uint8_t result = 0x00;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- result = ShmGBTData->ev[pDcChargingInfo->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - CCS
- //===============================================
- bool isEvGunLocked_ccs(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- return (DetectBitValue(pDcChargingInfo->GunLocked , 0) == 0) ? NO : YES;
- }
- uint8_t isPrechargeStatus_ccs(uint8_t gunIndex)
- {
- uint8_t result = 0x00;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121) {
- result = ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].PresentMsgFlowStatus;
- }
- return result;
- }
- bool isEvStopCharging_ccs(uint8_t gunIndex)
- {
- if (isEvGunLocked_ccs(gunIndex) == NO) {
- // 無鎖槍 = 停止
- log_info("gun locked none. ");
- return YES;
- }
- return NO;
- }
- //===============================================
- // Callback
- //===============================================
- void DisplayChargingInfo()
- {
- uint8_t i = 0;
- log_info("*********** DisplayChargingInfo *********** ");
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (pDcChargingInfo->SystemStatus != S_IDLE &&
- pDcChargingInfo->SystemStatus != S_RESERVATION) {
- ChangeGunSelectByIndex(i);
- return;
- }
- }
- if (pSysConfig->AcConnectorCount > 0 &&
- pSysInfo->CurGunSelectedByAc == NO_DEFINE)
- {
- pAcChargingInfo = (struct ChargingInfoData*)GetAcChargingInfoData(0);
- if (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
- pAcChargingInfo->SystemStatus <= S_COMPLETE)
- {
- pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
- }
- }
- usleep(50000);
- systemPageRestoreInit();
- }
- void _AutoReturnTimeout(void)
- {
- log_info("*********** _AutoReturnTimeout(%d) *********** ", pSysInfo->PageIndex);
- if (pSysInfo->PageIndex == _PAGE_PRECHARGE) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- pDcChargingInfo->SystemStatus = S_ALARM;
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_PLUGOUT;
- //pSysInfo->SystemPage = _PAGE_PAYING;
- //StartGunInfoTimeoutDet(pSysInfo->CurGunSelected,Timeout_FinalCost);
- ClearDetectPluginFlag();
- }
- }
- void _SelfTestTimeout(void)
- {
- if (pSysInfo->BootingStatus != BOOT_COMPLETE) {
- for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- setChargerMode(gunIndex, MODE_ALARM);
- }
- }
- ShmPsuData->Work_Step = _NO_WORKING;
- pSysInfo->SelfTestSeq = _STEST_FAIL;
- log_info("Self test timeout. ");
- }
- void _AuthorizedTimeout(void)
- {
- //if (IsAuthorizingMode()) {
- log_info("*********** _AuthorizedTimeout *********** ");
- StopSystemTimeoutDet();
- //isCardScan = false;
- SetIsCardScan(false);
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
- strcpy((char *)pSysConfig->UserId, "");
- ClearAuthorizedFlag();
- // StartSystemTimeoutDet(Timeout_ReturnViewPage);
- //}
- }
- void _DetectPlugInTimeout(uint8_t gunIndex)
- {
- int i;
- log_info("*********** _DetectPlugInTimeout *********** ");
- strcpy((char *)pSysConfig->UserId, "");
- //StopSystemTimeoutDet();
- StopGunInfoTimeoutDet(gunIndex);
- ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
- ShmDcCommonData->PreAuth_Result = 0;
- for(i=0;i<=30;i++) {
- if(ShmDcCommonData->PreAuth_Result != 0)
- break;
- sleep(1);
- }
- ShmDcCommonData->PreAuth_Result = 0;
- if (pSysInfo->CurGunSelected == gunIndex)
- pSysInfo->SystemPage = _PAGE_IDLE;
- ClearDetectPluginFlag();
- strcpy((char *)pSysConfig->UserId, "");
- setChargerMode(gunIndex, S_IDLE);
- //systemPageRestoreInit();
- }
- void _DetectEvChargingEnableTimeout(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (!isEvGunLocked_chademo(gunIndex)) {
- log_info("*********** _DetectEvChargingEnableTimeout (chademo) ***********");
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (!isEvGunLocked_ccs(gunIndex)) {
- log_info("*********** _DetectEvChargingEnableTimeout (gb) ***********");
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (!isEvGunLocked_ccs(gunIndex)) {
- log_info("*********** _DetectEvChargingEnableTimeout (ccs) ***********");
- }
- }
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- ChargingTerminalProcess(gunIndex);
- _AutoReturnTimeout();
- }
- void _DetectEvseChargingEnableTimeout(uint8_t gunIndex)
- {
- log_info("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********");
- setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- _AutoReturnTimeout();
- }
- void _PrepareTimeout(uint8_t gunIndex)
- {
- log_info("*********** _PrepareTimeout ***********");
- setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
- pAlarmCode->AlarmEvents.bits.PsuNoResource = YES;
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- _AutoReturnTimeout();
- }
- void _CcsPrechargeTimeout(uint8_t gunIndex)
- {
- log_info("*********** _CcsPrechargeTimeout ***********");
- setChargerMode(pSysInfo->CurGunSelected, S_TERMINATING);
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- }
- void _LinkErrorTimeout(uint8_t gunIndex)
- {
- log_info("*********** _LinkErrorTimeout ***********");
- setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- }
- //===============================================
- // 取得卡號與卡號驗證
- //===============================================
- void AuthorizingStart(void)
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
- pSysInfo->AuthorizeFlag = YES;
- }
- void ClearAuthorizedFlag(void)
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
- pSysInfo->AuthorizeFlag = NO;
- }
- bool isAuthorizedComplete(void)
- {
- if (pSysInfo->AuthorizeFlag == YES) {
- return false;
- }
- return true;
- }
- bool IsAuthorizingMode()
- {
- if (pSysInfo->AuthorizeFlag == NO) {
- return false;
- }
- return true;
- }
- //===============================================
- // 紀錄 Alarm Code
- //===============================================
- void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (strcmp(code, "012234") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
- } else if (strcmp(code, "012235") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
- } else if (strcmp(code, "012236") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
- } else if (strcmp(code, "012288") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
- } else if (strcmp(code, "012289") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
- } else if (strcmp(code, "012290") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
- } else if (strcmp(code, "012229") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
- } else if (strcmp(code, "012230") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
- } else if (strcmp(code, "012231") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
- } else if (strcmp(code, "011011") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
- } else if (strcmp(code, "011013") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
- } else if (strcmp(code, "011015") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
- } else if (strcmp(code, "011012") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
- } else if (strcmp(code, "011014") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
- } else if (strcmp(code, "011016") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
- } else if (strcmp(code, "011018") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
- } else if (strcmp(code, "011019") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
- } else if (strcmp(code, "011020") == EQUAL) {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
- } else if (strcmp(code, "012323") == EQUAL) {
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
- } else if (strcmp(code, "011038") == EQUAL) {
- ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
- }
- if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012229", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012230", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012231", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011011", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011013", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011015", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011012", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011014", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011016", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011018", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011019", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011020", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
- strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL) {
- strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
- }
- }
- void RecordAlarmCode(uint8_t gunIndex, char *code)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
- }
- if (pDcChargingInfo->StopChargeFlag == NO)
- {
- pDcChargingInfo->StopChargeFlag = YES;
- }
- }
- }
- void ReleaseAlarmCode(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- //if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
- // return;
- //}
- switch (pDcChargingInfo->Type) {
- case _Type_Chademo:
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
- break;
- case _Type_CCS_2:
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
- break;
- case _Type_GB:
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
- break;
- }
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "", 6);
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(uint8_t gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void ChargingAlarmProcess(uint8_t gunIndex)
- {
- UpdateErrorCodeToOcpp(gunIndex);
- setChargerMode(gunIndex, MODE_ALARM);
- }
- void AcChargingTerminalProcess(void)
- {
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
- pAcChargingInfo->SystemStatus = MODE_TERMINATING;
- }
- void StopChargingProcessByString(uint8_t level)
- {
- if (level > pSysWarning->Level) {
- pSysWarning->Level = level;
- }
- }
- void ReleaseChargingProcessByString(uint8_t level)
- {
- if (level >= pSysWarning->Level) {
- pSysWarning->Level = WARN_LV_NL;
- }
- }
- // 一般錯誤停止充電處理函式
- void BoardErrOccurByString(uint8_t index, char *code)
- {
- uint8_t level = 1;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if ((pDcChargingInfo->SystemStatus > S_IDLE &&
- pDcChargingInfo->SystemStatus < S_TERMINATING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- if (strncmp(code, "023730", 6) == EQUAL &&
- pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == NO
- ) {
- pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingTerminalProcess(index);
- }
- StopChargingProcessByString(level);
- }
- void ReleaseBoardErrOccurByString(uint8_t index, char *code)
- {
- bool isTrigger = false;
- uint8_t level = 1;
- if (strncmp(code, "023730", 6) == 0 &&
- pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop == YES) {
- isTrigger = true;
- pInfoCode->InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
- }
- if (isTrigger) {
- ReleaseChargingProcessByString(level);
- }
- }
- // 急停狀況的停止充電處理函式
- void EmcOccureByString(char *code)
- {
- uint8_t level = 2;
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- //DS60-120 remove
- if (strncmp(code, "012251", 6) == EQUAL ||
- strncmp(code, "012252", 6) == EQUAL ||
- strncmp(code, "012238", 6) == EQUAL ||
- strncmp(code, "042251", 6) == EQUAL ||
- strncmp(code, "042252", 6) == EQUAL ||
- strncmp(code, "012304", 6) == EQUAL ||
- strncmp(code, "042327", 6) == EQUAL ||
- strncmp(code, "042328", 6) == EQUAL ||
- strncmp(code, "042200", 6) == EQUAL ||
- strncmp(code, "042201", 6) == EQUAL ||
- strncmp(code, "042202", 6) == EQUAL ||
- strncmp(code, "042267", 6) == EQUAL) {
- for (uint8_t gun = 0; gun < pSysConfig->TotalConnectorCount; gun++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
- //strncpy((char *)ShmOCPP16Data->StatusNotification[gun].VendorErrorCode, code, 6);
- if ((pDcChargingInfo->SystemStatus > S_IDLE &&
- pDcChargingInfo->SystemStatus < S_TERMINATING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- //ChargingTerminalProcess(gun);
- if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
- }
- ChargingAlarmProcess(gun);
- }
- }
- StopChargingProcessByString(level);
- InformOcppErrOccur(4);
- }
- }
- void ReleaseEmsOccureByString(uint8_t index, char *code)
- {
- bool isTrigger = false;
- uint8_t level = 2;
- if (strncmp(code, "042251", 6) == 0 ) {
- isTrigger = true;
- } else if (strncmp(code, "012251", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.EmergencyStopTrip = NO;
- } else if (strncmp(code, "012252", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.DoorOpen = NO;
- } else if (strncmp(code, "012237", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.SpdTrip == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.SpdTrip = NO;
- } else if (strncmp(code, "012238", 6) == 0 &&
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
- isTrigger = true;
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- if (isTrigger) {
- ReleaseChargingProcessByString(level);
- InformOcppErrOccur(6);
- }
- }
- static void checkOvpState(uint8_t gunIndex, uint8_t gunType)
- {
- switch(gunType) {
- case _Type_Chademo:
- if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP == YES)
- RecordAlarmCode(gunIndex, "012217");
- break;
- case _Type_CCS_2:
- if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP == YES)
- RecordAlarmCode(gunIndex, "012219");
- break;
- case _Type_GB:
- if(ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP == YES)
- RecordAlarmCode(gunIndex, "012221");
- break;
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckErrorOccurStatus(uint8_t index)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- // RB
- if (pSysConfig->PhaseLossPolicy == YES) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
- if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
- pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
- StopChargingProcessByString(2);
- InformOcppErrOccur(13);
- }
- //DS60-120 add -----
- if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputUVP == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012203", 6);
- } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputUVP == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012204", 6);
- } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputUVP == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012205", 6);
- }
- }
- //log_info("1 CheckErrorOccurStatus");
- pDcChargingInfo->StopChargeFlag = YES;
- //------------------------------------------------------------------
- } else {
- if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
- pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- } else {
- if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP) {
- pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES ||
- pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
- if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE) {
- pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- InformOcppErrOccur(14);
- }
- //DS60-120 -----
- if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
- if (pAlarmCode->AlarmEvents.bits.SystemL1InputOVP == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012200", 6);
- } else if (pAlarmCode->AlarmEvents.bits.SystemL2InputOVP == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012201", 6);
- } else if (pAlarmCode->AlarmEvents.bits.SystemL3InputOVP == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012202", 6);
- }
- }
- //log_info("2 CheckErrorOccurStatus");
- pDcChargingInfo->StopChargeFlag = YES;
- //----------------------------------------------------------------------
- } else {
- if (pSysWarning->ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP) {
- pSysWarning->ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- checkOvpState(index, pDcChargingInfo->Type);
- //--------------------------------------------------------------------------
- if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == 0) {
- //Primary
- if (pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012251", 6);
- } else if (pAlarmCode->AlarmEvents.bits.DoorOpen == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012252", 6);
- } else if (pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012238", 6);
- } else if (pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES) {
- memcpy(pDcChargingInfo->ConnectorAlarmCode, "012304", 6);
- }
- //Chiller temperature
- //else if (pAlarmCode->AlarmEvents.bits.SystemChillerOTP == YES) {
- // memcpy(pDcChargingInfo->ConnectorAlarmCode, "012323", 6);
- //} else if (pFaultCode->FaultEvents.bits.ChillerTempSensorBroken == YES) {
- // memcpy(pDcChargingInfo->ConnectorAlarmCode, "011038", 6);
- //}
- }
- /*
- if (pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES ||
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES ||
- pAlarmCode->AlarmEvents.bits.DoorOpen == YES ||
- pSysWarning->ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
- pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == YES ||
- pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES ||
- //Power cabinet alarm status
- ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES
- ) {
- if ((pDcChargingInfo->SystemStatus > S_IDLE &&
- pDcChargingInfo->SystemStatus < S_COMPLETE) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1 ))
- ChargingAlarmProcess(index);
- pSysWarning->Level = WARN_LV_ER;
- }*/
- }
- //===============================================
- // 確認 GPIO 狀態
- //===============================================
- void gpio_set_value(unsigned int gpio, unsigned int value)
- {
- int fd;
- char buf[MAX_BUF];
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_WRONLY);
- if (fd < 0) {
- perror("gpio/set-value");
- return;
- }
- if (value) {
- write(fd, "1", 2);
- } else {
- write(fd, "0", 2);
- }
- close(fd);
- }
- int gpio_get_value(unsigned int gpio, unsigned int *value)
- {
- int fd;
- char buf[MAX_BUF];
- char ch;
- snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
- fd = open(buf, O_RDONLY);
- if (fd < 0) {
- perror("gpio/get-value");
- return fd;
- }
- read(fd, &ch, 1);
- if (ch != '0') {
- *value = 1;
- } else {
- *value = 0;
- }
- close(fd);
- return 0;
- }
- void CheckGunTypeFromHw()
- {
- uint8_t i = 0;
- int pinIn[4] = {22, 23, 44, 45};
- unsigned int gpioValue = 0;
- uint8_t tmp[2] = {0};
- log_info("ModelName = %s", pSysConfig->ModelName);
- for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- switch (pinIn[i]) {
- //right slot
- case 22:
- bd1_1_status = gpioValue;
- break;
- case 23:
- bd1_2_status = gpioValue;
- break;
- //left slot
- case 44:
- bd0_1_status = gpioValue;
- break;
- case 45:
- bd0_2_status = gpioValue;
- break;
- }
- }
- //BD1(Left-CCS-CND1-SMR2-左槍), BD2(Right-CHADEMO-CND2-SMR1-右槍), CCS: 10 , CHAdeMO: 01 , GBT: 11
- //CcsChargingData [0至1] 分別為 Right至Left
- //model name 槍順序左至右分別為Right至Left
- tmp[1] = (bd0_1_status << 4 | bd0_2_status);
- tmp[0] = (bd1_1_status << 4 | bd1_2_status);
- for (i = 0; i < 2; i++) {
- switch (tmp[i]) {
- case 0x01:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CHAdeMO");
- break;
- case 0x10:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "CCS");
- break;
- case 0x11:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "GBT");
- break;
- case 0x00:
- log_info("BD%d(%s) = %s ", i + 1, i == 0 ? "Left" : "Right", "None");
- break;
- }
- }
- }
- void CheckGpioInStatus()
- {
- int i = 0;
- int pinIn[2] = { 27, 47 };//{IO BD1_2, IO BD2_2}
- unsigned int gpioValue = 0;
- for (i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- if (gpioValue == 0x01) {
- switch (pinIn[i]) {
- // 小板緊急停止
- case 47:
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (pDcChargingInfo->slotsIndex == 1) {
- if (pDcChargingInfo->Type == _Type_Chademo) {
- BoardErrOccurByString(i, "023730");
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- BoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- break;
- case 27:
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (pDcChargingInfo->slotsIndex == 3) {
- if (pDcChargingInfo->Type == _Type_Chademo) {
- BoardErrOccurByString(i, "023730");
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- BoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- break;
- }
- } else {
- switch (pinIn[i]) {
- // 小板解除緊急停止
- case 47:
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (pDcChargingInfo->slotsIndex == 1) {
- if (pDcChargingInfo->Type == _Type_Chademo) {
- ReleaseBoardErrOccurByString(i, "023730");
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- ReleaseBoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- break;
- case 27:
- for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if (pDcChargingInfo->slotsIndex == 3) {
- if (pDcChargingInfo->Type == _Type_Chademo) {
- ReleaseBoardErrOccurByString(i, "023730");
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- ReleaseBoardErrOccurByString(i, "013627");
- }
- break;
- }
- }
- break;
- }
- }
- }
- }
- //===============================================
- // Main process
- //===============================================
- // 檢查 uint8_t 中某個 Bit 的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit)
- {
- uint8_t mask_table[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- // 設定 Byte 中某個 Bit的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- // value : 修改的值為 0 or 1
- void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value)
- {
- if (value == 1) {
- *_byte |= (1 << _bit);
- } else if (value == 0) {
- *_byte ^= (1 << _bit);
- }
- }
- uint8_t isModeChange(uint8_t gunIndex)
- {
- uint8_t result = NO;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pDcChargingInfo->SystemStatus == pDcChargingInfo->PreviousSystemStatus) {
- return result;
- }
- pDcChargingInfo->PreviousSystemStatus = pDcChargingInfo->SystemStatus;
- ShmDcCommonData->SystemModeChange[gunIndex] = YES; //for Module_EvRxComm print temperature message
- return YES;
- }
- static int checkSlotGpioMappingGunType(uint8_t gunIndex, uint8_t gunType)
- {
- uint8_t slot1 = 0, slot2 = 0;
- if (gunIndex == 0) {
- slot1 = bd0_1_status;
- slot2 = bd0_2_status;
- } else if (gunIndex == 1) {
- slot1 = bd1_1_status;
- slot2 = bd1_2_status;
- }
- log_info("slot %d gpio1 = %d, gpio2 = %d, type = %d",
- gunIndex,
- slot1,
- slot2,
- gunType);
- switch (gunType) {
- case _Type_Chademo:
- if (slot1 != NO && slot2 != YES) {
- return FAIL;
- }
- break;
- case _Type_CCS_2:
- if (slot1 != YES && slot2 != NO) {
- return FAIL;
- }
- break;
- case _Type_GB:
- if (slot1 != YES && slot2 != YES) {
- return FAIL;
- }
- break;
- }
- return PASS;
- }
- bool CheckConnectorTypeStatus(void)
- {
- bool result = true;
- uint8_t gunIndex = 0;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct ChargingInfoData *pDcChargingInfo = NULL;
- if (!MappingGunChargingInfo("CSU Task")) {
- log_error("CheckConnectorTypeStatus MappingGunChargingInfo failed");
- return false;
- }
- // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (checkSlotGpioMappingGunType(gunIndex, pDcChargingInfo->Type) == FAIL) {
- return false;
- }
- pDcChargingInfo->SystemStatus = S_BOOTING;
- switch (gunIndex) {
- case 0:
- if (pSysConfig->TotalConnectorCount == 1) {
- if ((bd0_1_status == YES || bd0_2_status == YES) &&
- (bd1_1_status == NO && bd1_2_status == NO)) {
- pDcChargingInfo->Evboard_id = 0x01;
- }
- if ((bd0_1_status == NO && bd0_2_status == NO) &&
- (bd1_1_status == YES || bd1_2_status == YES)
- ) {
- pDcChargingInfo->Evboard_id = 0x02;
- }
- break;
- }
- pDcChargingInfo->Evboard_id = 0x01;
- break;
- case 1:
- pDcChargingInfo->Evboard_id = 0x02;
- break;
- }
- CheckHwSlotStatusLog(gunIndex);
- if (pDcChargingInfo->Evboard_id == 0x00) {
- return false;
- }
- }
- AdjustChargerCurrent();
- return result;
- }
- int SpawnTask(void)
- {
- if(SIMULATION)
- system("/root/simulation &");
- sleep(2);
- system("/root/Module_EventLogging &");
- system("/root/Module_PrimaryComm &");
- system("/root/Module_EvComm &");
- system("/root/Module_LcmControl &");
- system("/root/Module_InternalComm &");
- system("/root/Module_ProduceUtils &");
- system("/root/Module_UpdateFW &");
- system("/root/Module_DoComm &");
- return PASS;
- }
- void KillTask(void)
- {
- //ChangeLcmByIndex(_LCM_ERROR);
- ChangeLcmByIndex(_PAGE_MAINTAIN);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_UpdateFW");
- system("killall Module_ChkSysTask");
- //system("killall Module_DoComm");
- return ;
- }
- void KillTaskExceptPrimary(void)
- {
- //ChangeLcmByIndex(_LCM_ERROR);
- ChangeLcmByIndex(_PAGE_MAINTAIN);
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- return;
- }
- void KillAllTask(void)
- {
- //ChangeLcmByIndex(_LCM_ERROR);
- ChangeLcmByIndex(_PAGE_MAINTAIN);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_UpdateFW");
- system("killall Module_ChkSysTask");
- system("killall Module_DoComm");
- return ;
- }
- void StartSystemTimeoutDet(uint8_t flag)
- {
- if (pSysInfo->SystemTimeoutFlag != flag) {
- GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
- }
- pSysInfo->SystemTimeoutFlag = flag;
- }
- void StopSystemTimeoutDet(void)
- {
- GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
- pSysInfo->SystemTimeoutFlag = Timeout_None;
- }
- void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (gunIndex < pSysConfig->TotalConnectorCount) {
- if (pDcChargingInfo->TimeoutFlag != flag) {
- gettimeofday(&pDcChargingInfo->TimeoutTimer, NULL);
- }
- pDcChargingInfo->TimeoutFlag = flag;
- }
- }
- void StopGunInfoTimeoutDet(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (gunIndex < pSysConfig->TotalConnectorCount) {
- pDcChargingInfo->TimeoutFlag = Timeout_None;
- }
- }
- void CheckConnectionTimeout(void)
- {
- if (ShmSelectGunInfo->RemoteSetup.ConnectionTimeout != 0) { //Jerry add
- _connectionTimeout = ShmSelectGunInfo->RemoteSetup.ConnectionTimeout;
- } else {
- _connectionTimeout = CONN_PLUG_TIMEOUT;
- }
- return;
- }
- void _evccidlinktimeout(uint8_t gunIndex)
- {
- log_info("Getting EVCCID Timeout");
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- pDcChargingInfo->isEVCCIDVerify = true;
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(pSysInfo->CurGunSelected);
- systemPageRestoreInit();
- }
- void CreateTimeoutFork(void)
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid == 0) {
- gettimeofday(&_cmdSubPriority_time, NULL);
- CheckConnectionTimeout();
- //log_info("Timeout Fork Child's PID is %d", getpid());
- while (1) {
- if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000) {
- CheckConnectionTimeout();
- gettimeofday(&_cmdSubPriority_time, NULL);
- }
- //if (pSysInfo->SystemTimeoutFlag != 0)
- //log_info("Timeout ***********SystemTimeoutFlag = %d(%d) ********",pSysInfo->SystemTimeoutFlag,
- // GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL);
- // 系統
- switch (pSysInfo->SystemTimeoutFlag) {
- case Timeout_SelftestChk:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
- _SelfTestTimeout();
- StopSystemTimeoutDet();
- destroySelGun(DESTROY_ALL_SEL); //jerry add
- }
- break;
- case Timeout_ReturnViewPage:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_VIEWPAGE_TIMEOUT) {
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_IDLE;
- }
- break;
- case Timeout_Authorizing:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
- //log_error("Authorizing Timeout");
- _AuthorizedTimeout();
- if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
- ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
- pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
- log_error("Author timeout restart DoComm");
- }
- }
- break;
- case Timeout_WaitBalance:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= BALANCE_TIMEOUT) {
- log_error("Wait Balance timeout");
- _AuthorizedTimeout();
- if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
- ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
- pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
- log_error("Author timeout restart DoComm");
- system("killall Module_DoComm");
- }
- }
- break;
- case Timeout_VerifyFail:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
- /*if (pSysInfo->SystemPage ==_LCM_START_AUTHORIZE_FAIL ) {
- StopSystemTimeoutDet();
- _AutoReturnTimeout();
- //destroySelGun(pSysInfo->CurGunSelected);
- if (ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] == YES) { //DoComm no ask cabinet balance
- ShmSelectGunInfo->AuthorStateFromCabinet[pSysInfo->CurGunSelected] = NO;
- pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = ABNORMAL;
- log_error("Author timeout restart DoComm");
- system("killall Module_DoComm");
- //sleep(1);
- //system("/root/Module_DoComm &");
- }
- } else*/ if (pSysInfo->SystemPage ==_PAGE_AUTHORIZE_FAIL ) {
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- setChargerMode(pSysInfo->CurGunSelected, S_IDLE);
- }
- }
- break;
- /*
- case Timeout_WaitPlug:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
- _DetectPlugInTimeout();
- destroySelGun(pSysInfo->CurGunSelected);
- }
- break;
- */
- /*
- case Timeout_ReturnToChargingGunDet:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
- if (getCurLcmPage() != _LCM_VIEW &&
- getCurLcmPage() != _LCM_DETAIL_VIEW ) {
- destroySelGun(pSysInfo->CurGunSelected); //jerry add
- }
- DisplayChargingInfo();
- StopSystemTimeoutDet();
- }
- break;
- */
- case Timeout_AuthorizingForStop:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
- strcpy((char *)pSysConfig->UserId, "");
- ClearAuthorizedFlag();
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- }
- break;
- case Timeout_ScanCard:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_SCANCARD_TIMEOUT) {
- strcpy((char *)pSysConfig->UserId, "");
- ClearAuthorizedFlag();
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- }
- break;
- case Timeout_Terminating:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TERMINATING_TIMEOUT) {
- StopSystemTimeoutDet();
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- log_info("Terminating timeout");
- setChargerMode(pSysInfo->CurGunSelected, S_COMPLETE);
- }
- break;
- case Timeout_AddLine:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_ADDLINE_TIMEOUT) {
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- }
- break;
- case Timeout_DonateComfirm:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_DONATECOMFIRM_TIMEOUT) {
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- }
- break;
- case Timeout_SelectPayMode:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_SELECTPAY_TIMEOUT) {
- StopSystemTimeoutDet();
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- }
- break;
- case Timeout_Sensing:
- if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= TCC_SENSING_TIMEOUT) {
- StopSystemTimeoutDet();
- log_info("Sensing timeout");
- pSysInfo->SystemPage = _PAGE_AUTHORIZE_FAIL;
- ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
- }
- break;
- }
- // 各槍
- for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- /*
- if (pDcChargingInfo->TimeoutFlag != 0)
- log_info("Timeout ***********GunTimeoutFlag = %d(%d) ********",pDcChargingInfo->TimeoutFlag,
- GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL);
- */
- switch (pDcChargingInfo->TimeoutFlag) {
- case Timeout_WaitPlug:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
- _DetectPlugInTimeout(gunIndex);
- destroySelGun(gunIndex);
- }
- break;
- case Timeout_EVCCID_Link:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= EVCCID_LINK_TIMEOUT) {
- _evccidlinktimeout(gunIndex);
- }
- break;
- case Timeout_LinkError:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= LINKERROR_TIMEOUT) {
- _LinkErrorTimeout(gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex);
- }
- break;
- case Timeout_Preparing:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT) {
- _PrepareTimeout(gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex); //jerry add
- }
- break;
- case Timeout_EvChargingDet:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT) {
- _DetectEvChargingEnableTimeout(gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex); //jerry add
- }
- break;
- case Timeout_EvseChargingDet:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT) {
- _DetectEvseChargingEnableTimeout(gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex); //jerry add
- }
- break;
- case Timeout_EvseCompleteDet:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT) {
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex); //jerry add
- }
- break;
- case Timeout_ForCcsPrechargeDet:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT) {
- _CcsPrechargeTimeout(gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex); //jerry add
- }
- break;
- case Timeout_PlugOutGun:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= PLUGOUTGUN_TIMEOUT) {
- setChargerMode(gunIndex, MODE_IDLE);
- destroySelGun(gunIndex); //Jerry add
- StopGunInfoTimeoutDet(gunIndex);
- systemPageRestoreInit();
- }
- break;
- case Timeout_FinalCost:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_FINALCOST_TIMEOUT) {
- StopGunInfoTimeoutDet(gunIndex);
- if (ShmDcCommonData->finalcost_flag[gunIndex] == FALSE) {
- ShmDcCommonData->finalcost[gunIndex] = pDcChargingInfo->PresentChargedEnergy * ShmDcCommonData->ChargingRate;
- ShmDcCommonData->finalcost_flag[gunIndex] = TRUE;
- }
- }
- break;
- case Timeout_LineReigster:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= TCC_LINEREGISTER_TIMEOUT) {
- StopGunInfoTimeoutDet(gunIndex);
- pSysInfo->SystemPage = _PAGE_SELECT_PAY;
- ShmDcCommonData->donate_flag[gunIndex] = TRUE;
- }
- break;
- /*
- case Timeout_SelectGun: //Jerry add
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= SEL_GUN_TIMEOUT) {
- log_info("Timeout_SelectGun");
- StopGunInfoTimeoutDet(gunIndex);
- destroySelGun(gunIndex); //jerry add
- }
- break;
- */
- /*
- case Timeout_DetailView:
- if (GetTimeoutValue(pDcChargingInfo->TimeoutTimer) / uSEC_VAL >= DETAILVIEW_TIMEOUT) {
- StopGunInfoTimeoutDet(gunIndex);
- pSysInfo->SystemPage = _LCM_VIEW;
- }
- break;*/
- }
- }
- sleep(1);
- }
- }
- }
- void CheckFactoryConfigFunction(void)
- {
- char Buf[256] = {0};
- if (pSysInfo->FactoryConfiguration) {
- sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
- pSysConfig->ModelName,
- pSysConfig->SerialNumber);
- system(Buf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- //===============================================
- // Check reservation date is expired
- //===============================================
- int isReservationExpired(uint8_t gunIndex)
- {
- int result = NO;
- struct tm expiredDate;
- struct timeb expiredTime;
- if (sscanf((char *) ShmOCPP16Data->ReserveNow[gunIndex].ExpiryDate,
- "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
- &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
- &expiredDate.tm_min, &expiredDate.tm_sec) == 6) {
- expiredDate.tm_year -= 1900;
- expiredDate.tm_mon -= 1;
- expiredTime.time = mktime(&expiredDate);
- if (!CheckTimeOut(expiredTime)) {
- result = YES;
- }
- }
- return result;
- }
- //===============================================
- // OCPP
- //===============================================
- void CheckOcppStatus(void)
- {
- bool canReset = true;
- //bool canHardReset = true; //DS60-120 add
- if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES) {
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
- }
- if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES) {
- if (pSysWarning->Level != WARN_LV_ER) {
- for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- if (pDcChargingInfo->SystemStatus != S_IDLE &&
- pDcChargingInfo->SystemStatus != S_RESERVATION &&
- pDcChargingInfo->SystemStatus != S_MAINTAIN) {
- canReset = false;
- if (pDcChargingInfo->SystemStatus >= S_REASSIGN &&
- pDcChargingInfo->SystemStatus < S_TERMINATING) {
- //canHardReset = false;
- ChargingTerminalProcess(_index);
- //restartFlag = 1;
- }
- }
- }
- }
- if (canReset) {
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL) {
- log_error("****** Hard Reboot ****** ");
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- } else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL) {
- log_error("****** Soft Reboot ****** ");
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("killall OcppBackend &");
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- void OcppStopTransation(uint8_t gunIndex)
- {
- uint8_t _OcppGunIndex = gunIndex;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (pSysConfig->AcConnectorCount == 1 && gunIndex == 1) {
- _OcppGunIndex = 2;
- }
- if (strcmp((char *)pDcChargingInfo->StartUserId, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- } else {
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)pDcChargingInfo->StartUserId);
- }
- log_info("IdTag = %s ", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
- }
- bool OcppRemoteStop(uint8_t gunIndex)
- {
- uint8_t acDirIndex = pSysConfig->AcConnectorCount;
- // 有 AC 槍的話
- if (acDirIndex > 0 && gunIndex > 0) {
- gunIndex += acDirIndex;
- }
- bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
- ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
- }
- return result;
- }
- bool WifiScheduleStop(uint8_t gunIndex)
- {
- bool result = false;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- result = pDcChargingInfo->schedule.isTriggerStop;
- pDcChargingInfo->schedule.isTriggerStop = NO;
- return result;
- }
- void OcppRemoteStartChk()
- {
- if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
- } else if (!isDetectPlugin()) {
- // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
- uint8_t acDirIndex = pSysConfig->AcConnectorCount;
- for (uint8_t ac_index = 0; ac_index < pSysConfig->AcConnectorCount; ac_index++) {
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(ac_index);
- if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES) {
- if (pAcChargingInfo->SystemStatus == S_IDLE ||
- pAcChargingInfo->SystemStatus == S_RESERVATION) {
- ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
- pAcChargingInfo->RemoteStartFlag = YES;
- pSysInfo->OrderCharging = YES;
- //pSysInfo->OrderCharging = DEFAULT_AC_INDEX;
- ShmOCPP16Data->CsMsg.bits[pSysConfig->TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- return;
- }
- ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
- }
- }
- uint8_t threeGunIndex = 0;
- uint8_t dcIndex = 0;
- bool isGunUsingStatus = false;
- bool _remotestarting = false;
- for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- // 如果有 AC 槍,且 DC 槍也有兩把
- if (acDirIndex == 1 && _index == 1) {
- threeGunIndex = 1;
- }
- if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES) {
- dcIndex = _index;
- }
- if (pDcChargingInfo->SystemStatus != S_IDLE) {
- isGunUsingStatus = true;
- }
- if (pDcChargingInfo->RemoteStartFlag == YES) {
- //_remotestarting = true;
- }
- }
- // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
- if (isGunUsingStatus && pSysInfo->IsAlternatvieConf) {
- if (dcIndex == 0) {
- threeGunIndex = 0;
- }
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- return;
- }
- if (dcIndex == 0) {
- threeGunIndex = 0;
- }
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(dcIndex);
- if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES &&
- !_remotestarting ) {
- if (pDcChargingInfo->SystemStatus == S_IDLE ||
- pDcChargingInfo->SystemStatus == S_AUTHORIZING ||
- pDcChargingInfo->SystemStatus == S_RESERVATION) {
- pDcChargingInfo->RemoteStartFlag = YES;
- pSysInfo->OrderCharging = YES;
- //pDcChargingInfo->SystemStatus = S_AUTHORIZING;
- //pSysInfo->OrderCharging = gunIndex;
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- setSelGunWaitToAuthor(dcIndex);
- log_info("Ocpp Remote Start Pass");
- }
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- }
- }
- }
- void ChkOcppStatus(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pDcChargingInfo->SystemStatus == S_IDLE &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES) {
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
- if (isReservationExpired(gunIndex)) {
- log_error("***************ChkOcppStatus : OcppReservedStatus******************** ");
- pDcChargingInfo->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
- pDcChargingInfo->SystemStatus = S_RESERVATION;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
- }
- if (pDcChargingInfo->SystemStatus == S_RESERVATION &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES) {
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
- if (isReservationExpired(gunIndex)) {
- log_error("***************ChkOcppStatus : Cancel OcppReservedStatus******************** ");
- pDcChargingInfo->ReservationId = 0;
- pDcChargingInfo->SystemStatus = S_IDLE;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
- }
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES) {
- log_error("***************ChkOcppStatus : OcppChangeAvailability******************** ");
- ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
- if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL) {
- if (isDb_ready) {
- DB_Update_Operactive(gunIndex, true);
- }
- pDcChargingInfo->IsAvailable = YES;
- if (pDcChargingInfo->SystemStatus == S_IDLE ||
- pDcChargingInfo->SystemStatus == S_RESERVATION ||
- pDcChargingInfo->SystemStatus == S_MAINTAIN) {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- } else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL) {
- if (isDb_ready) {
- DB_Update_Operactive(gunIndex, false);
- }
- pDcChargingInfo->IsAvailable = NO;
- if (pDcChargingInfo->SystemStatus == S_IDLE ||
- pDcChargingInfo->SystemStatus == S_RESERVATION ||
- pDcChargingInfo->SystemStatus == S_MAINTAIN) {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- }
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES) {
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
- if (pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK && // DS60-120 add ||
- pDcChargingInfo->SystemStatus <= S_CHARGING) {
- // 充電中,需停止充電
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
- ChargingTerminalProcess(gunIndex);
- }
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
- }
- }
- bool CheckBackendChargingTimeout(uint8_t gunIndex)
- {
- bool result = false;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
- if (pSysConfig->MaxChargingDuration > 0) {
- if (pDcChargingInfo->PresentChargedDuration > (pSysConfig->MaxChargingDuration * 60)) {
- result = true;
- }
- }
- }
- return result;
- }
- bool CheckBackendChargingEnergy(uint8_t gunIndex)
- {
- bool result = false;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
- if (pSysConfig->MaxChargingEnergy > 0) {
- if (pDcChargingInfo->PresentChargedEnergy > pSysConfig->MaxChargingEnergy) {
- result = true;
- }
- }
- }
- return result;
- }
- void InformOcppErrOccur(uint8_t codeType)
- {
- char _error[25];
- switch (codeType) {
- case 4:
- strcpy(_error, "InternalError");
- break;
- case 6:
- strcpy(_error, "NoError");
- break;
- case 7:
- strcpy(_error, "OtherError");
- break;
- case 13:
- strcpy(_error, "UnderVoltage");
- break;
- case 14:
- strcpy(_error, "OverVoltage");
- break;
- }
- for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, _error);
- }
- }
- //===============================================
- // Config process
- //===============================================
- /*
- void AddPlugInTimes(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- pSysConfig->ChademoPlugInTimes += 1;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- pSysConfig->Ccs2PlugInTimes += 1;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- pSysConfig->GbPlugInTimes += 1;
- }
- }*/
- void ChangeStartOrStopDateTime(uint8_t isStart, uint8_t gunIndex)
- {
- char cmdBuf[32];
- struct timeb csuTime;
- struct tm *tmCSU;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- if (isStart) {
- strcpy((char *)pDcChargingInfo->StartDateTime, cmdBuf);
- } else {
- strcpy((char *)pDcChargingInfo->StopDateTime, cmdBuf);
- }
- }
- void ChangeGunSelectByIndex(uint8_t sel)
- {
- pSysInfo->CurGunSelected = sel;
- pSysInfo->CurGunSelectedByAc = NO_DEFINE;
- }
- void CheckIsAlternatvieByModelName()
- {
- if (pSysConfig->ModelName[1] == 'W') { //DS60-120
- // 壁掛
- pSysInfo->IsAlternatvieConf = YES;
- } else {
- pSysInfo->IsAlternatvieConf = NO;
- }
- }
- void StopProcessingLoop()
- {
- for (;;) {
- CheckFactoryConfigFunction();
- //CheckFwUpdateFunction();
- if (pSysWarning->Level == WARN_LV_ER) {
- ChkPrimaryStatus();
- if (pSysWarning->Level == WARN_LV_NL) {
- log_info("Soft reboot for retry self-tets (Primary). ");
- KillAllTask();
- sleep(3);
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- sleep(1);
- TryFeedWatchdog();
- }
- }
- bool IsConnectorWholeIdle()
- {
- bool result = true;
- for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
- if (pDcChargingInfo->SystemStatus != S_IDLE &&
- pDcChargingInfo->SystemStatus != S_RESERVATION) {
- result = false;
- break;
- }
- }
- for (uint8_t count = 0; count < pSysConfig->AcConnectorCount; count++) {
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
- if (pAcChargingInfo->SystemStatus != S_IDLE &&
- pAcChargingInfo->IsErrorOccur == NO) {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!pSysInfo->AcContactorStatus) {
- pAlarmCode->AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- int GetStartScheduleTime(uint8_t *time)
- {
- int result = -1;
- struct tm tmScheduleStart;
- struct timeb tbScheduleStart;
- if ((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6)) {
- tmScheduleStart.tm_year -= 1900;
- tmScheduleStart.tm_mon -= 1;
- tbScheduleStart.time = mktime(&tmScheduleStart);
- tbScheduleStart.millitm = 0;
- result = DiffTimebWithNow(tbScheduleStart) / 1000;
- }
- return result;
- }
- void CheckSmartChargeProfile(uint8_t _index)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == YES) {
- // Get Charging Profile
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES //DS60-120 add
- ) {
- int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
- uint8_t _startCount = NO_DEFINE;
- uint8_t _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
- for (uint8_t _count = 0; _count < _maxCount; _count++) {
- // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
- if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod) {
- if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR) {
- _startCount = _count;
- }
- }
- }
- log_info("_startCount = %d ", _startCount);
- if (_startCount < _maxCount) {
- //DS60-120 add
- log_info("Profile Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
- pDcChargingInfo->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
- if (pDcChargingInfo->EvBatterytargetVoltage > 0 && pDcChargingInfo->PresentChargingVoltage > 0) {
- pDcChargingInfo->ChargingProfileCurrent = (pDcChargingInfo->ChargingProfilePower / pDcChargingInfo->PresentChargingVoltage) * 10;
- } else {
- pDcChargingInfo->ChargingProfileCurrent = 0;
- }
- } else {
- pDcChargingInfo->ChargingProfilePower = -1;
- pDcChargingInfo->ChargingProfileCurrent = -1;
- }
- } else {
- pDcChargingInfo->ChargingProfilePower = -1;
- pDcChargingInfo->ChargingProfileCurrent = -1;
- }
- log_info("ChargingProfilePower = %f ", pDcChargingInfo->ChargingProfilePower);
- log_info("ChargingProfileCurrent = %f ", pDcChargingInfo->ChargingProfileCurrent);
- }
- }
- void ChargingProfileFlat(uint8_t _index)
- {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO) {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO) {
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
- }
- }
- }
- /*
- void CheckReturnToChargingConn()
- {
- if ((pSysConfig->TotalConnectorCount + pSysConfig->AcConnectorCount) > 1 &&
- pSysInfo->PageIndex != _LCM_START_AUTHORIZING &&
- pSysInfo->PageIndex != _LCM_START_AUTHORIZE_FAIL &&
- pSysInfo->PageIndex != _LCM_WAIT_PLUGIN) {
- bool isReturnTimeout = false;
- for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
- // 如果選的 DC 槍在充電~ 則 DC 槍不改變
- if (count == pSysInfo->CurGunSelected) {
- if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
- pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
- ) {
- isReturnTimeout = false;
- break;
- }
- } else if (count != pSysInfo->CurGunSelected) {
- if ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
- pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)
- ) {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- // AC 槍
- if (!isReturnTimeout && pSysConfig->AcConnectorCount > 0) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
- // 沒有選中 AC,且 AC 在充電中
- if (pSysInfo->CurGunSelectedByAc == NO_DEFINE &&
- (pAcChargingInfo->SystemStatus >= S_PREPARNING &&
- pAcChargingInfo->SystemStatus <= S_COMPLETE)) {
- // 當前 DC 充電槍在 idle 狀態
- if (pDcChargingInfo->SystemStatus == S_IDLE ||
- pDcChargingInfo->SystemStatus == S_RESERVATION) {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- } else if (pSysInfo->CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ((pDcChargingInfo->SystemStatus >= S_REASSIGN_CHECK &&
- pDcChargingInfo->SystemStatus <= S_COMPLETE) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))) {
- // 當前 DC 充電槍在 idle 狀態
- if (pAcChargingInfo->SystemStatus == S_IDLE ||
- pAcChargingInfo->SystemStatus == S_RESERVATION) {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- if (!isReturnTimeout) {
- StopSystemTimeoutDet();
- }
- }
- }
- bool GetStartChargingByAlterMode(uint8_t _gun)
- {
- bool result = true;
- if (pSysConfig->TotalConnectorCount == 2 &&
- pSysInfo->IsAlternatvieConf == YES) {
- for (uint8_t _select = 0; _select < pSysConfig->TotalConnectorCount; _select++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_select);
- if (_select != _gun) {
- if (pDcChargingInfo->SystemStatus != S_IDLE &&
- pDcChargingInfo->SystemStatus != S_RESERVATION) {
- result = false;
- break;
- }
- }
- }
- }
- return result;
- }
- */
- void TheEndCharging(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- ftime(&endChargingTime[gunIndex]);
- if (pDcChargingInfo->PresentChargedDuration != 0) {
- pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
- }
- pDcChargingInfo->isRemoteStart = NO;
- StopGunInfoTimeoutDet(gunIndex);
- //StartGunInfoTimeoutDet(gunIndex, Timeout_EvseCompleteDet);
- ChangeStartOrStopDateTime(NO, gunIndex);
- DB_Insert_Record(gunIndex);
- }
- void UpdateErrorCodeToOcpp(uint8_t index)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- //log_info("%d = ConnectorAlarmCode = %s", index, pDcChargingInfo->ConnectorAlarmCode);
- //log_info("%d = EvConnAlarmCode = %s", index, pDcChargingInfo->EvConnAlarmCode);
- if (strcmp((char *)pDcChargingInfo->ConnectorAlarmCode, "") != EQUAL) {
- //if (strlen((char *)pDcChargingInfo->ConnectorAlarmCode) == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "InternalError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->ConnectorAlarmCode);
- } else if (strcmp((char *)pDcChargingInfo->EvConnAlarmCode, "") != EQUAL) {
- //} else if (strlen((char *)pDcChargingInfo->EvConnAlarmCode) == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].ErrorCode, "OtherError");
- strcpy((char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode, (char *)pDcChargingInfo->EvConnAlarmCode);
- }
- //log_info("Gun %d = VendorErrorCode = %s", index, (char *)ShmOCPP16Data->StatusNotification[index].VendorErrorCode);
- }
- void AdjustChargerCurrent()
- {
- pSysConfig->RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
- // 設定的電流~ 如超過可輸出的電流,則 bypass
- if (pSysConfig->RatingCurrent < pSysConfig->MaxChargingCurrent ||
- pSysConfig->RatingCurrent == 0) {
- pSysConfig->MaxChargingCurrent = 0;
- }
- log_info("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
- ShmPsuData->SystemAvailablePower / 10,
- ShmPsuData->SystemAvailableCurrent / 10
- );
- log_info("Config : ChargingPower = %d, ChargingCurrent = %d",
- pSysConfig->MaxChargingPower,
- pSysConfig->MaxChargingCurrent
- );
- }
- void ResetDetAlarmStatus(uint8_t gun)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gun);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP == YES) {
- pAlarmCode->AlarmEvents.bits.SystemChademoOutputOVP = NO;
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP == YES) {
- pAlarmCode->AlarmEvents.bits.SystemGbOutputOVP = NO;
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP == YES) {
- pAlarmCode->AlarmEvents.bits.SystemCcsOutputOVP = NO;
- }
- }
- }
- #if 0
- static void autoStartCharging(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if ( (pSysInfo->SystemPage >= _LCM_START_AUTHORIZING && pSysInfo->SystemPage <= _LCM_LINK_ERROR) ||
- pDcChargingInfo->isEVCCIDVerify && strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL) {
- return;
- }
- if ((pDcChargingInfo->ConnectorPlugIn == YES) &&
- (pDcChargingInfo->SystemStatus == S_IDLE )
- ) {
- if(!pSysConfig->AuthorisationMode) {
- if (pSysConfig->isAuthrizeByEVCCID && !pDcChargingInfo->isEVCCIDVerify &&
- pDcChargingInfo->Type == _Type_CCS_2) {
- // LCM show linking pic. & timeout 2 min
- if( pSysInfo->CurGunSelected == gunIndex ) {
- systemPageRestoreInit();
- pSysInfo->SystemPage = _LCM_PRECHARGE;
- }
- StartGunInfoTimeoutDet(gunIndex,Timeout_EVCCID_Link);
- // Getting EVCCID
- if( strcmp( (char *)pDcChargingInfo->EVCCID, "" ) != EQUAL ) {
- log_info("Authorizing EVCCID");
- StopSystemTimeoutDet();
- strcpy((char *)pSysConfig->UserId, (char *)pDcChargingInfo->EVCCID);
- ChangeGunSelectByIndex(gunIndex);
- confirmSelGun(gunIndex);
- pDcChargingInfo->isEVCCIDVerify = true;
- pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
- log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
- setChargerMode(gunIndex, MODE_AUTHORIZING);
- }
- } else
- return;
- } else {
- strcpy((char *)&pSysConfig->UserId, "AutoStartCharging");
- ChangeGunSelectByIndex(gunIndex);
- confirmSelGun(gunIndex);
- pSysInfo->SystemPage = _LCM_START_AUTHORIZING;
- setChargerMode(gunIndex, MODE_AUTHORIZING);
- log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
- }
- }
- }
- #endif
- static bool PrecheckIsPass(uint8_t gunIndex)
- {
- bool result = true;
- // relay welding or driving 是反向
- result = !ShmDcCommonData->GunRelayWeldingOccur[gunIndex];
- return result;
- }
- static void ReviewCriticalAlarm(void)
- {
- if (
- pAlarmCode->AlarmEvents.bits.EmergencyStopTrip == YES ||
- pAlarmCode->AlarmEvents.bits.MainPowerBreakerTrip == YES ||
- pAlarmCode->AlarmEvents.bits.DoorOpen == YES ||
- pSysWarning->ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
- pAlarmCode->AlarmEvents.bits.PsuFailureAlarm == YES ||
- pAlarmCode->AlarmEvents.bits.DisconnectedFromDo == YES ||
- //Power cabinet alarm status
- ShmDcCommonData->PowerAlarmState.StatusBit.EmergencyStop == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.DoorOpen == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.DcInputUVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL1InputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL2InputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.SystemL3InputOVP == YES ||
- ShmDcCommonData->PowerAlarmState.StatusBit.PsuFailure == YES ||
- ShmSelectGunInfo->EthDevStatus.Backend == 0 ||
- ShmSelectGunInfo->EthDevStatus.Backend == 2
- ) {
- pSysWarning->Level = WARN_LV_ER;
- } else {
- pSysWarning->Level = WARN_LV_NL;
- }
- }
- static void CheckRelayWeldingOrDrivingFault(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- // relay welding fault then stop the charging process.
- uint8_t faultCode = RELAY_STATUS_ERROR_NONE;
- //static uint8_t drivingCount = 0;
- if (gunIndex == 0) {
- if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->CheckRelayStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- } else if (gunIndex == 1) {
- if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- } else if (ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->CheckRelayStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- if (pSysConfig->TotalConnectorCount >= 2 &&
- !pSysInfo->IsAlternatvieConf) {
- // 橋接
- if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
- ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING) {
- faultCode = RELAY_STATUS_ERROR_WELDING;
- } else if (ShmDcCommonData->CheckRelayStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
- ShmDcCommonData->CheckRelayStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING) {
- faultCode = RELAY_STATUS_ERROR_DRIVING;
- }
- }
- if (faultCode == RELAY_STATUS_ERROR_WELDING) {
- // welding
- if (pDcChargingInfo->Type == _Type_Chademo) {
- RecordAlarmCode(gunIndex, "011011");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- RecordAlarmCode(gunIndex, "011015");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- RecordAlarmCode(gunIndex, "011013");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
- }
- ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = YES;
- //EmcOccureByString("");
- } else if (faultCode == RELAY_STATUS_ERROR_DRIVING) {
- //if (drivingCount++ != 2) {
- // return;
- //}
- // driving
- if (pDcChargingInfo->Type == _Type_Chademo) {
- RecordAlarmCode(gunIndex, "011012");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
- } else if (pDcChargingInfo->Type == _Type_GB) {
- RecordAlarmCode(gunIndex, "011016");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- RecordAlarmCode(gunIndex, "011014");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
- }
- ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = YES;
- //EmcOccureByString("");
- } else {
- ShmDcCommonData->GunRelayWeldingOccur[gunIndex] = NO;
- ShmDcCommonData->GunRelayDrivingOccur[gunIndex] = NO;
- //drivingCount = 0;
- }
- }
- static void isChargingAverageState(void)
- {
- if (pSysInfo->MainChargingMode != _MAIN_CHARGING_MODE_AVER) {
- pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
- return;
- }
- // 均充 -> 最大充
- if (pSysInfo->BridgeRelayStatus == NO) {
- if (pSysInfo->ReAssignedFlag == _REASSIGNED_NONE) {
- log_info("=============Smart Charging============= Step 11 ");
- pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
- }
- } else if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
- pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
- log_info("=============Smart Charging============= Step 14 ");
- pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
- } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
- pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- bool Taskconutstring(char *src, char *taskname)
- {
- bool result = false;
- if (src == NULL || strlen(src) == 0)
- return result;
- if (strstr(src, taskname) != NULL &&
- strstr(src, "grep") == NULL &&
- strstr(src, "[") == NULL)
- {
- result = true;
- }
- return result;
- }
- int GetProcessCount(char *procName)
- {
- int result = 0;
- FILE *fp;
- char cmd[256];
- char buf[256];
- sprintf(cmd, "ps -ef |grep %s", procName);
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (Taskconutstring(buf, procName))
- result++;
- }
- }
- pclose(fp);
- return result;
- }
- void CheckTaskAlive()
- {
- pid_t Pid = fork();
- if ( Pid == 0 ) {
- //log_info("CheckTaskAlive fork Child's PID is %d", getpid());
- while(1) {
- sleep(3);
- unsigned char count = GetProcessCount("Module_ChkSysTask");
- if( count != 1 ) {
- system("pkill Module_ChkSysTask");
- sleep(10);
- log_info("Create Check System Task");
- system("/root/Module_ChkSysTask &");
- }
- }
- return;
- }
- log_info("Create Check Systam fork:%d",Pid);
- return;
- }
- /**
- * [checkPileEndGfdResult 確認充電樁GFD狀態]
- * @Author Jerry
- * @DateTime 2021-07-01
- * @param gunIndex [當前的槍]
- * @param gunType [槍的類型]
- * @param sysStatus [槍的系統狀態]
- */
- static void checkPileEndGfdResult(uint8_t gunIndex, uint8_t gunType, uint8_t sysStatus)
- {
- switch (gunType) {
- case _Type_Chademo:
- // 檢查樁端的 GFD 結果
- if (sysStatus == S_PREPARING_FOR_EVSE &&
- isPrechargeStatus_chademo(gunIndex) >= 6 ) {
- // 當前操作的槍號,進入 Charging
- setChargerMode(gunIndex, MODE_CHARGING);
- }
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gunIndex, "012234");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
- } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- //RecordAlarmCode(gunIndex, "012296");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
- }
- else {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
- }
- break;
- case _Type_GB:
- // 檢查樁端的 GFD 結果
- //if (isPrechargeStatus_gb(gunIndex) > 5 && isPrechargeStatus_gb(gunIndex) < 9) {
- if (sysStatus == S_PREPARING_FOR_EVSE &&
- isPrechargeStatus_gb(gunIndex) >= 6) {
- setChargerMode(gunIndex, MODE_CHARGING);
- }
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gunIndex, "012236");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
- } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- //RecordAlarmCode(gunIndex, "012298");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
- }
- else {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
- }
- break;
- case _Type_CCS_2:
- // 檢查樁端的 GFD 結果
- if (sysStatus == S_PREPARING_FOR_EVSE &&
- (pDcChargingInfo->GroundFaultStatus == GFD_PASS ||
- pDcChargingInfo->GroundFaultStatus == GFD_WARNING)
- ) {
- setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP0);
- }
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gunIndex, "012235");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
- } else if (pDcChargingInfo->GroundFaultStatus == GFD_WARNING) {
- // GFD 警告
- RecordAlarmCode(gunIndex, "012297");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
- }
- else {
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
- }
- break;
- }
- }
- static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
- {
- uint8_t evBoardStopState = 0;
- if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
- // 板端要求停止 (錯誤)
- if (sysStatus != S_CCS_PRECHARGE_ST0 &&
- sysStatus != S_CCS_PRECHARGE_ST1) {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
- }
- }
- if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
- log_info("EV Board Stop Charging with some error");
- ChargingAlarmProcess(gunIndex);
- } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
- log_info("Power Cabient Stop Charging");
- ChargingTerminalProcess(gunIndex);
- }
- } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
- // 板端要求停止 (正常)
- if (sysStatus != S_CCS_PRECHARGE_ST0 &&
- sysStatus != S_CCS_PRECHARGE_ST1) {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
- }
- }
- log_info("EV Board Normal Stop Charging");
- ChargingTerminalProcess(gunIndex);
- } else if (OcppRemoteStop(gunIndex) == YES ||
- WifiScheduleStop(gunIndex)) {
- // 後臺要求停止
- log_info("OCPP Stop Charging");
- ChargingTerminalProcess(gunIndex);
- }
- }
- static void checkOCPPReqStop(uint8_t gunIndex)
- {
- if (OcppRemoteStop(gunIndex) == YES ||
- WifiScheduleStop(gunIndex) ||
- CheckBackendChargingTimeout(gunIndex) ||
- CheckBackendChargingEnergy(gunIndex) ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
- // 後臺要求停止
- ChargingTerminalProcess(gunIndex);
- }
- }
- void ResetIdleData(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
- ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
- pDcChargingInfo->PresentChargedDuration = 0;
- pDcChargingInfo->RemainChargingDuration = 0;
- pDcChargingInfo->PresentChargingVoltage = 0;//DS60-120 add
- pDcChargingInfo->PresentChargingCurrent = 0;//DS60-120 add
- pDcChargingInfo->RemoteStartFlag = NO;
- pDcChargingInfo->Replug_flag = FALSE;
- strcpy((char *)pDcChargingInfo->StartDateTime, "");
- strcpy((char *)pDcChargingInfo->StopDateTime, "");
- strcpy((char *)pDcChargingInfo->StartUserId, "");
- strcpy((char *)pSysConfig->UserId, "");
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "");
- ClearDetectPluginFlag();
- //Jerry add
- memset(&ShmSelectGunInfo->PricesInfo[gunIndex], 0, sizeof(PricesInfo));
- memset(&ShmDcCommonData->pCreditCard[gunIndex], 0, sizeof(TransInfo));
- memset(&ShmDcCommonData->TransactionInfo[gunIndex], 0, sizeof(RecordTransactionInfo));
- ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
- ShmDcCommonData->finalcost[gunIndex] = 0;
- ShmDcCommonData->AuthPass_flag[gunIndex] = FALSE;
- ShmDcCommonData->PayPass_flag[gunIndex] = FALSE;
- ShmDcCommonData->GetCardNo[gunIndex] = FALSE;
- ShmSelectGunInfo->PricesInfo[gunIndex].Balance = FAIL_BALANCE_PRICES;
- destroySelGun(gunIndex);
- ResetDetAlarmStatus(gunIndex); //recovery OVP status code
- if (ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] == YES) {
- ShmSelectGunInfo->AuthorStateFromCabinet[gunIndex] = NO;
- }
- //strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].VendorErrorCode, "");
- ReleaseAlarmCode(gunIndex);
- if (pSysInfo->SystemPage != _PAGE_SELECT_GUN && pSysInfo->SystemPage != _PAGE_SELECT_PAY)
- pSysInfo->SystemPage = _PAGE_IDLE;
- }
- void CheckErrorCode(uint8_t gunIndex)
- {
- struct ChargingInfoData *pSelectedDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
- if (gunIndex == pSysInfo->CurGunSelected) {
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- } else if (pSelectedDcChargingInfo->SystemStatus != S_IDLE &&
- pSelectedDcChargingInfo->SystemStatus != S_RESERVATION &&
- pSelectedDcChargingInfo->SystemStatus != S_MAINTAIN &&
- pSelectedDcChargingInfo->SystemStatus != S_FAULT) {
- if (pSelectedDcChargingInfo->SystemStatus == S_CHARGING) {
- if(ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == FALSE)
- pSysInfo->SystemPage = _PAGE_PAYING;
- else
- pSysInfo->SystemPage = _PAGE_COMPLETE;
- } else {
- systemPageRestoreInit();
- }
- }
- ClearDetectPluginFlag();
- if (pDcChargingInfo->SystemStatus != S_FAULT)
- {
- UpdateErrorCodeToOcpp(gunIndex);
- setChargerMode(gunIndex, MODE_FAULT);
- }
- }
- void AuthorizeStopCharging(uint8_t gunIndex)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- checkOCPPReqStop(gunIndex);
- //RfidStopCharging();
- }
- void showversion()
- {
- uint8_t index = 0;
- log_info("\t=========== Dispenser info =========== ");
- log_info("\tSW Version = %s", fwVersion);
- log_info("\tDebug Version = %s",DebugVersion);
- log_info("\tModelName = %s", pSysConfig->ModelName);
- log_info("\tRelay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
- log_info("\tFan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
- log_info("\tPrimary FW Rev = %s", pSysInfo->CsuPrimFwRev);
- log_info("\tLCM HW Rev = %s", pSysInfo->LcmHwRev);
- log_info("\tLED FW Rev = %s", pSysInfo->LedModuleFwRev);
- for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
- if (pDcChargingInfo->Type == _Type_Chademo) {
- log_info("\tCHAdeMO[%d] FW Rev = %s",
- pDcChargingInfo->type_index,
- ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
- } else if (pDcChargingInfo->Type == _Type_GB) {
- log_info("\tGBT[%d] FW Rev = %s",
- pDcChargingInfo->type_index,
- ShmGBTData->evse[pDcChargingInfo->type_index].version);
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- log_info("\tCCS[%d] FW Rev = %s",
- pDcChargingInfo->type_index,
- ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
- }
- }
- log_info("\t==================================== ");
- }
- int main(void)
- {
- bool isModelNameMatch = true;
- uint8_t _ocppProfileChkFlag;
- uint8_t gunIndex = 0;
- if (CreateAllCsuShareMemory() == FAIL) {
- log_error("create share memory error");
- return FAIL;
- }
- ClearAllShmMemParameter();
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
- pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
- pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
- ShmPsuData = (struct PsuData *)GetShmPsuData();
- ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
- ShmGBTData = (struct GBTData *)GetShmGBTData();
- ShmCcsData = (struct CcsData *)GetShmCcsData();
- ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
- ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
- ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
- ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
- ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
- ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-
- ShmSysConfigAndInfo = (struct SysConfigAndInfo *)GetShmSysConfigAndInfo();
- ShmStatusCodeData = (struct StatusCodeData *)GetShmStatusCodeData();
- log_info(" ********************************************************");
- log_info(" ****************** FileSystem Boot up *****************");
- log_info(" ********************************************************");
- log_info(" ****************** Project:DD360Tcci *****************");
- log_info(" ********************************************************");
- int is_plugout[2];
- if (!InitialSystemDefaultConfig()) {
- log_error("InitialSystemDefaultConfig NG ");
- //StopProcessingLoop();
- sleep(5);
- system("reboot -f");
- }
- CheckGunTypeFromHw();
- CheckIsAlternatvieByModelName();
- InitialShareMemoryInfo();
- GetFirmwareVersion();
- if (!CheckConnectorTypeStatus()) {
- isModelNameMatch = false;
- }
- Initialization();
- SpawnTask();
- log_info("Spawned all Task");
- if (!isModelNameMatch) {
- pAlarmCode->AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- //ChangeLcmByIndex(_LCM_ERROR);
- ChangeLcmByIndex(_PAGE_MAINTAIN);
- // Module Name 與硬體對應不正確
- log_error("Module Name & HW info none match. ");
- sleep(3);
- KillAllTask();
- StopProcessingLoop();
- }
- CreateTimeoutFork();
- log_info("Start self test... ");
- SelfTestRun();
- StopSystemTimeoutDet();
- log_info("Self test finished : SelfTestSeq = %d, Work_Step = %d ",
- pSysInfo->SelfTestSeq,
- ShmPsuData->Work_Step);
- if (pSysInfo->SelfTestSeq == _STEST_FAIL ||
- ShmPsuData->Work_Step == _NO_WORKING ||
- pInfoCode->InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES //DS60-120 add
- ) {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- ChangeLcmByIndex(_PAGE_MAINTAIN);
- } else {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- }
- // Local DB
- if (DB_Open() != PASS) {
- log_info("DB_Open fail. ");
- isDb_ready = false;
- } else {
- isDb_ready = true;
- for (int _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
- pDcChargingInfo->IsAvailable = DB_Get_Operactive(_index);
- }
- DB_Reboot_Record();
- }
- log_info("===== Create DB End ===== ");
- ChangeLcmByIndex(_PAGE_SELECT_GUN);
- sleep(1);
- //***** 須新增的偵測 *****//
- // 1. Thernal - 控制風扇轉速
- // 2. ouput fuse - 控制風扇轉速
- CreateRfidFork();
- // Main loop
- showversion();
- CheckFwSlotStatusLog();
- //AdjustChargerCurrent();
- gettimeofday(&_cmdMainPriority_time, NULL);
- GunIndexInfo *pGunIndexInfo = (GunIndexInfo *)GetGunIndexInfo();
- CheckTaskAlive();
- CreateWatchdog();
- for (;;) {
- CheckOcppStatus();
- ChkPrimaryStatus();
- if ((IsConnectorWholeIdle() ||
- //(pSysInfo->PageIndex == _LCM_ERROR)) &&
- (pSysInfo->PageIndex == _PAGE_MAINTAIN)) &&
- (pSysInfo->SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
- ) {
- CheckFactoryConfigFunction();
- //CheckFwUpdateFunction();
- }
- // OCPP 邏輯
- OcppRemoteStartChk();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- ClearAlarmCodeWhenAcOff();
- if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000) {
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
- pDcChargingInfo->SystemStatus <= S_CHARGING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- if (pDcChargingInfo->SystemStatus == S_CHARGING &&
- _ocppProfileChkFlag == 12) {
- ChargingProfileFlat(gunIndex);
- _ocppProfileChkFlag = 0;
- } else if (pDcChargingInfo->SystemStatus != S_CHARGING) {
- ChargingProfileFlat(gunIndex);
- _ocppProfileChkFlag = 0;
- } else {
- _ocppProfileChkFlag++;
- }
- }
- checkGunOTPState(gunIndex); //check gun OTP
- }
- gettimeofday(&_cmdMainPriority_time, NULL);
- }
- gEvBoardErr.GunErrMessage = 0; //清除系統執行中的錯誤訊息
- gChillerTempErr.TempErrMsg = 0;//清除系統執行中的錯誤訊息
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- // 重新收集各槍的錯誤狀態
- collectError(gunIndex);
- checkEvBoardAlarmState(pDcChargingInfo->Type);
- }
- checkChillerAlarmState();
- // 確認當前錯誤 Level = 2 ?
- ReviewCriticalAlarm();
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- CheckGpioInStatus();
- CheckErrorOccurStatus(gunIndex);
- // 確認 Relay Welding or Driving Fault
- CheckRelayWeldingOrDrivingFault(gunIndex);
- ChkOcppStatus(gunIndex);
- if ((pDcChargingInfo->SystemStatus >= S_PREPARING_FOR_EVSE &&
- pDcChargingInfo->SystemStatus <= S_CHARGING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
- pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- CheckSmartChargeProfile(gunIndex);
- }
- switch (pDcChargingInfo->SystemStatus) {
- case S_IDLE:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_IDLE(%x) ============================= ", gunIndex);
- ResetIdleData(gunIndex);
- is_plugout[gunIndex] = FALSE;
- }
- isChargingAverageState();
- // For RemoteStart Using
- if (pDcChargingInfo->RemoteStartFlag == YES && pDcChargingInfo->IsAvailable) {
- log_info("-------- IDLE Remote Start(%d) --------", gunIndex);
- ChangeGunSelectByIndex(gunIndex);
- setChargerMode(gunIndex, MODE_AUTHORIZING);
- break;
- }
- // 讀卡邏輯
- ScannerCardProcess();
- if (pSysInfo->SystemPage == _PAGE_SELECT_GUN) {
- ShmDcCommonData->LineStatus[gunIndex] = 0;
- StopGunInfoTimeoutDet(gunIndex);
- StartSystemTimeoutDet(Timeout_ReturnViewPage);
- }
- if (pSysInfo->CurGunSelected == gunIndex){
- if(pSysInfo->SystemPage ==_PAGE_BILL) {
- StartSystemTimeoutDet(Timeout_AddLine);
- if (ShmDcCommonData->LineStatus[gunIndex] == 1 || ShmDcCommonData->LineStatus[gunIndex] == 2 )
- pSysInfo->SystemPage =_PAGE_ADD_FRIEND;
- } else if(pSysInfo->SystemPage ==_PAGE_ADD_FRIEND) {
- StopSystemTimeoutDet();
- StartGunInfoTimeoutDet(gunIndex, Timeout_LineReigster);
- if (ShmDcCommonData->LineStatus[gunIndex] == 3) {
- pSysInfo->SystemPage =_PAGE_SELECT_PAY;
- ShmDcCommonData->donate_flag[gunIndex] = FALSE;
- }
- if (ShmDcCommonData->LineStatus[gunIndex] == 4 ) {
- pSysInfo->SystemPage =_PAGE_SELECT_PAY;
- ShmDcCommonData->donate_flag[gunIndex] = TRUE;
- }
- }
- }
- goto CheckStatus;
- break;
- case S_RESERVATION:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_RESERVATION(%x) ============================= ", gunIndex);
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
- }
- if (!isReservationExpired(gunIndex)) {
- pDcChargingInfo->SystemStatus = S_IDLE;
- }
- goto CheckStatus;
- break;
- case S_FAULT:
- if (isModeChange(gunIndex)) {
- if(pDcChargingInfo->SystemStatus == S_FAULT) {
- log_info("============================= S_FAULT(%x) ============================= ", gunIndex);
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- }
- }
- CheckStatus:
- if (pDcChargingInfo->IsAvailable == NO) {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- break;
- }
- // Refresh Error Status
- if (pSysWarning->Level == WARN_LV_ER) {
- CheckErrorCode(gunIndex);
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- continue;
- }
- if (PrecheckIsPass(gunIndex) == false) {
- log_error("Relay welding");
- setChargerMode(gunIndex, MODE_FAULT);
- if (gunIndex == pSysInfo->CurGunSelected) {
- //pSysInfo->SystemPage = _LCM_ERROR;
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- }
- break;
- }
- if (pDcChargingInfo->SystemStatus == S_FAULT) {
- systemPageRestoreInit();
- setChargerMode(gunIndex, MODE_IDLE);
- }
- break;
- case S_AUTHORIZING:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_AUTHORIZING(%x) ============================= ", gunIndex);
- StartSystemTimeoutDet(Timeout_AuthorizingForStop);
- }
- ScannerCardProcess();
- // 隨插即充
- //autoStartCharging(gunIndex);
- if (pSysInfo->SystemPage == _PAGE_PLUGIN) {
- pDcChargingInfo->Replug_flag = TRUE;
- StopSystemTimeoutDet();
- StartGunInfoTimeoutDet(gunIndex,Timeout_WaitPlug);
- }
- if (pSysInfo->SystemPage == _PAGE_PLUGOUT) {
- StartSystemTimeoutDet(Timeout_VerifyFail);
- }
- if (isDetectPlugin()) {
- // 卡號驗證成功後,等待充電槍插入充電車
- if (pDcChargingInfo->RemoteStartFlag == YES) {
- if (pDcChargingInfo->ConnectorPlugIn == YES &&
- pDcChargingInfo->IsAvailable ) {
- log_info("-------- S_AUTHORIZING Remote Start(%d) --------", gunIndex);
- pDcChargingInfo->RemoteStartFlag = NO;
- pDcChargingInfo->isRemoteStart = YES; //DS60-120
- ChangeGunSelectByIndex(gunIndex);
- //AddPlugInTimes(gunIndex);
- setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
- strcpy((char *)pDcChargingInfo->StartUserId, "");
- ClearDetectPluginFlag();
- continue;
- }
- } else if (pSysInfo->OrderCharging == NO_DEFINE) {
- if (pDcChargingInfo->ConnectorPlugIn == YES &&
- pDcChargingInfo->IsAvailable &&
- pDcChargingInfo->SystemStatus == S_AUTHORIZING &&
- ShmDcCommonData->AuthPass_flag[pSysInfo->CurGunSelected] == TRUE &&
- //waitSelectGunPlugIt(gunIndex)
- (waitRightGunPlugIt(gunIndex) == PASS ||
- waitLeftGunPlugIt(gunIndex) == PASS)
- ) {
- log_info("-------- RFID/Auto Start(%d) --------", gunIndex);
- ChangeGunSelectByIndex(gunIndex);
- //AddPlugInTimes(gunIndex);
- pDcChargingInfo->isRemoteStart = NO;
- strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
- log_info("index = %d, CardNumber = %s ",
- gunIndex,
- pDcChargingInfo->StartUserId);
- strcpy((char *)pSysConfig->UserId, "");
- // 當前操作的槍號,進入 Preparing
- setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- if (!GetIsCardScan() && pSysInfo->CurGunSelected == gunIndex &&
- pSysInfo->SystemPage != _PAGE_AUTHORIZE_FAIL &&
- pSysInfo->SystemPage != _PAGE_SENSING) {
- pSysInfo->SystemPage = _PAGE_PLUGIN;
- }
- }
- break;
- case S_REASSIGN_CHECK: {
- if (isModeChange(gunIndex)) {
- log_info("============================= S_REASSIGN_CHECK(%x) ============================= ", gunIndex);
- if (pSysInfo->OrderCharging != NO_DEFINE) {
- pSysInfo->OrderCharging = NO_DEFINE;
- pDcChargingInfo->_SaftyDetect = FALSE;
- pDcChargingInfo->Replug_flag = TRUE;
- }
- StopSystemTimeoutDet();
- StopGunInfoTimeoutDet(gunIndex);
- gettimeofday(&pDcChargingInfo->PreChargeTimer, NULL);
- }
- setChargerMode(gunIndex, S_PREPARNING);
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_PRECHARGE;
- }
- }
- break;
- case S_PREPARNING:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_PREPARNING(%x) ============================= ", gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- StartGunInfoTimeoutDet(gunIndex, Timeout_Preparing);
- }
- if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
- ShmPsuData->SystemAvailablePower > 10 &&
- GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
- setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
- }
- checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_PRECHARGE;
- }
- break;
- case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- if (isModeChange(gunIndex)) {
- log_info("============================= S_PREPARING_FOR_EV(%x) ============================= ", gunIndex);
- log_info("Waitting for Gun locked.");
- StopGunInfoTimeoutDet(gunIndex);
- StartGunInfoTimeoutDet(gunIndex, Timeout_EvChargingDet);
- }
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (isEvGunLocked_chademo(gunIndex) == YES) {
- log_info("Gun Locked");
- setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (isEvGunLocked_gb(gunIndex) == YES) {
- log_info("Gun Locked");
- setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (isEvGunLocked_ccs(gunIndex) == YES) {
- log_info("Gun Locked");
- setChargerMode(gunIndex, MODE_PREPARE_FOR_EVSE);
- }
- }
- checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_PRECHARGE;
- }
- break;
- case S_PREPARING_FOR_EVSE: // Ground fault test, 等待 Relay Board 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- if (isModeChange(gunIndex)) {
- log_info("============================= S_PREPARING_FOR_EVSE(%x) ============================= ", gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- StartGunInfoTimeoutDet(gunIndex, Timeout_EvseChargingDet);
- }
- checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
- checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_PRECHARGE;
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- if (isModeChange(gunIndex)) {
- log_info("============================= CCS Precharge Processing 1(%x) ============================= ", gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- StartGunInfoTimeoutDet(gunIndex, Timeout_ForCcsPrechargeDet);
- }
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gunIndex, "012235");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
- }
- checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
- // 等待 EV 小板 (CCS) 通知可以開始 Precharge
- // 切換 D+ Relay to Precharge Relay
- if (isPrechargeStatus_ccs(gunIndex) == 39 ||
- isPrechargeStatus_ccs(gunIndex) == 40) {
- if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
- pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
- //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
- {
- //log_info("Send precharge ready 1..........%x, status = %d ",
- // gunIndex,
- // isPrechargeStatus_ccs(gunIndex));
- if (isPrechargeStatus_ccs(gunIndex) == 39) {
- log_info("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) ",
- gunIndex,
- isPrechargeStatus_ccs(gunIndex));
- } else if (isPrechargeStatus_ccs(gunIndex) == 40) {
- log_info("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) ",
- gunIndex,
- isPrechargeStatus_ccs(gunIndex));
- }
- pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
- }
- } else if (isPrechargeStatus_ccs(gunIndex) == 45 ||
- isPrechargeStatus_ccs(gunIndex) == 46
- ) {
- setChargerMode(gunIndex, MODE_CCS_PRECHARGE_STEP1);
- }
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_PRECHARGE;
- }
- break;
- case S_CCS_PRECHARGE_ST1:
- if (isModeChange(gunIndex)) {
- log_info("============================= CCS Precharge Processing 2(%x) ============================= ", gunIndex);
- }
- if (pDcChargingInfo->GroundFaultStatus == GFD_FAIL) {
- // GFD 錯誤停止
- RecordAlarmCode(gunIndex, "012235");
- ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
- }
- checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
- // 等待小板通知進入充電
- // 切換 D+ Relay to Precharge Relay
- if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
- pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
- pSysInfo->CurGunSelected = gunIndex;
- setChargerMode(gunIndex, MODE_CHARGING);
- }
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_PRECHARGE;
- }
- break;
- case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- if (isModeChange(gunIndex)) {
- log_info("============================= S_CHARGING(%x) ============================= ", gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- ftime(&startChargingTime[gunIndex]);
- strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
- ChangeStartOrStopDateTime(YES, gunIndex);
- pDcChargingInfo->Replug_flag = FALSE;
- ShmDcCommonData->finalcost_flag[gunIndex] = FALSE;
- ShmDcCommonData->StopCharge[gunIndex] = FALSE;
- }
- if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
- ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf = NO;
- }
- ftime(&endChargingTime[gunIndex]);
- pDcChargingInfo->PresentChargedDuration = DiffTimeb(startChargingTime[gunIndex], endChargingTime[gunIndex]);
- checkPileEndGfdResult(gunIndex, pDcChargingInfo->Type, pDcChargingInfo->SystemStatus);
- checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
- // Check Stop Charging
- AuthorizeStopCharging(gunIndex);
- if (pSysInfo->SystemPage == _PAGE_STOP_CONFIRM_LEFT ||
- pSysInfo->SystemPage == _PAGE_STOP_CONFIRM_RIGHT)
- break;
- // LCM => Charging
- if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_IDLE &&
- pSysInfo->SystemPage != _PAGE_SELECT_GUN) {
- pSysInfo->SystemPage = _PAGE_CHARGING;
- }
- break;
- case S_TERMINATING:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_TERMINATING(%x) ============================= ", gunIndex);
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
- }
- StopGunInfoTimeoutDet(gunIndex);
- StartSystemTimeoutDet(Timeout_Terminating);
- pSysInfo->CurGunSelected = gunIndex;
- }
- // For Precharging timeout
- if (pDcChargingInfo->Type == _Type_Chademo) {
- if (isEvStopCharging_chademo(gunIndex) == YES ||
- isPrechargeStatus_chademo(gunIndex) <= 0) {
- setChargerMode(gunIndex, MODE_COMPLETE);
- }
- } else if (pDcChargingInfo->Type == _Type_GB) {
- if (isEvStopCharging_gb(gunIndex) == YES ||
- isPrechargeStatus_gb(gunIndex) <= 0) {
- setChargerMode(gunIndex, MODE_COMPLETE);
- }
- } else if (pDcChargingInfo->Type == _Type_CCS_2) {
- if (isEvStopCharging_ccs(gunIndex) == YES &&
- (isPrechargeStatus_ccs(gunIndex) >= 53 ||
- isPrechargeStatus_ccs(gunIndex) == 0 ||
- isPrechargeStatus_ccs(gunIndex) == 13 ||
- isPrechargeStatus_ccs(gunIndex) == 14)
- ) {
- setChargerMode(gunIndex, MODE_COMPLETE);
- }
- }
- //if (pSysInfo->SystemPage == _LCM_ERROR) {
- if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
- break;
- }
- if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING) {
- if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
- pSysInfo->SystemPage = _PAGE_COMPLETE;
- else
- pSysInfo->SystemPage = _PAGE_PAYFAIL;
- }
- break;
- case S_COMPLETE:
- if (isModeChange(gunIndex)) {
- log_info ("============================= S_COMPLETE(%x) ============================= ", gunIndex);
- if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
- OcppStopTransation(gunIndex);
- }
- TheEndCharging(gunIndex);
- StopSystemTimeoutDet();
- }
- //if (pSysInfo->SystemPage == _LCM_ERROR) {
- if (pSysInfo->SystemPage == _PAGE_MAINTAIN) {
- break;
- }
- if (pSysInfo->CurGunSelected == gunIndex && is_plugout[gunIndex] == TRUE) {
- pSysInfo->SystemPage = _PAGE_EXIT;
- break;
- }
- if (pDcChargingInfo->ConnectorPlugIn == NO) {
- is_plugout[gunIndex] = TRUE;
- StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_EXIT;
- break;
- }
- }
- if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING) {
- if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
- pSysInfo->SystemPage = _PAGE_COMPLETE;
- else
- pSysInfo->SystemPage = _PAGE_PAYFAIL;
- }
- break;
- case S_ALARM:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_ALARM(%x) ============================= ", gunIndex);
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Local");
- }
- UpdateErrorCodeToOcpp(gunIndex);
- if (strcmp((char *)pDcChargingInfo->StartDateTime, "") != EQUAL) {
- OcppStopTransation(gunIndex);
- }
- TheEndCharging(gunIndex);
- StopGunInfoTimeoutDet(gunIndex);
- if (pDcChargingInfo->Replug_flag == TRUE) {
- ShmDcCommonData->PreAuth_Config = _CREDITCARD_CANCEL;
- ShmDcCommonData->PreAuth_Result = 0;
- } else {
- if(ShmDcCommonData->PayFinish[gunIndex] == FALSE) {
- pSysInfo->SystemPage = _PAGE_PAYING;
- }
- ShmDcCommonData->StopCharge[gunIndex] = TRUE;
- }
- }
- if (pSysWarning->Level == WARN_LV_ER) {
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- continue;
- }
- if (pSysInfo->CurGunSelected == gunIndex && is_plugout[gunIndex] == TRUE) {
- pSysInfo->SystemPage = _PAGE_EXIT;
- break;
- }
- if (pDcChargingInfo->ConnectorPlugIn == NO) {
- is_plugout[gunIndex] = TRUE;
- if (pDcChargingInfo->Replug_flag == TRUE) {
- pSysInfo->SystemPage = _PAGE_SELECT_GUN;
- pDcChargingInfo->SystemStatus = S_IDLE;
- }
- else {
- StartGunInfoTimeoutDet(gunIndex, Timeout_PlugOutGun);
- pSysInfo->SystemPage = _PAGE_EXIT;
- }
- break;
- }
- //if (pSysInfo->SystemPage == _PAGE_PAYING)
- // break;
- if (pSysInfo->CurGunSelected == gunIndex && pSysInfo->SystemPage != _PAGE_PAYING) {
- if (pDcChargingInfo->Replug_flag == TRUE)
- pSysInfo->SystemPage = _PAGE_PLUGOUT;
- else {
- if (ShmDcCommonData->PayPass_flag[pSysInfo->CurGunSelected] == TRUE)
- pSysInfo->SystemPage = _PAGE_COMPLETE;
- else
- pSysInfo->SystemPage = _PAGE_PAYFAIL;
- }
- }
- break;
- case S_MAINTAIN:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_MAINTAIN(%x) ============================= ", gunIndex);
- if (pSysInfo->FirmwareUpdate == YES) {
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- continue;
- }
- if (pSysInfo->CurGunSelected == gunIndex) {
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- }
- if (pDcChargingInfo->IsAvailable == NO )
- break;
- if (pSysWarning->Level != WARN_LV_ER) {
- if (!DisplaySelfTestFailReason()) { //DS60-120 add
- log_info("Soft reboot for retry self-tets. ");
- sleep(3);
- system("killall OcppBackend &");
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- sleep(3);
- if (pSysWarning->Level == WARN_LV_ER) { //DS60-120 add
- KillTaskExceptPrimary();
- } else {
- KillTask();
- }
- if (pSysInfo->SelfTestSeq == _STEST_FAIL)
- StopProcessingLoop();
- }
- break;
- case S_UPDATE:
- if (isModeChange(gunIndex)) {
- log_info("============================= S_UPDATE ============================= ");
- }
- if (pSysInfo->FirmwareUpdate == YES) {
- pSysInfo->SystemPage = _PAGE_MAINTAIN;
- continue;
- } else {
- }
- break;
- }//switch
- }//for
- //if (pSysInfo->SystemPage != _LCM_VIEW)
- //ChangeLcmByIndex(pSysInfo->SystemPage);
- TryFeedWatchdog();
- usleep(WHILE_LOOP_TIME);
- }
- return FAIL;
- }
|