123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751 |
- #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 "../../define.h"
- #include "Config.h"
- #include <stdbool.h>
- #include <dirent.h>
- #include "timeout.h"
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define PASS 1
- #define FAIL -1
- #define BUFFER_SIZE 128
- #define YES 1
- #define NO 0
- #define NORMAL 0
- #define ABNORMAL 1
- #define EQUAL 0
- #define BTN_RELEASE 0
- #define BTN_PRESS 1
- #define MAX_BUF 64
- #define MtdBlockSize 0x600000
- #define SYSFS_GPIO_DIR "/sys/class/gpio"
- #define UPGRADE_FAN 0x02
- #define UPGRADE_RB 0x03
- #define UPGRADE_PRI 0x04
- #define UPGRADE_AC 0x05
- #define UPGRADE_LED 0x06
- #define SYSTEM_MIN_VOL 150
- #define MIN_OUTPUT_CUR 0
- #define AC_OUTPUT_VOL 220
- #define NO_DEFINE 255
- #define DEFAULT_AC_INDEX 2
- #define PSU_MIN_CUR 100
- #define DB_FILE "/Storage/ChargeLog/localCgargingRecord.db"
- #define uSEC_VAL 1000000
- #define SELFTEST_TIMEOUT 45
- #define AUTHORIZE_TIMEOUT 15
- #define AUTHORIZE_COMP_TIMEOUT 3
- #define AUTHORIZE_FAIL_TIMEOUT 3
- #define AUTHORIZE_STOP_TIMEOUT 30
- #define RETURN_TO_CHARGING_PAGE 30
- #define GUN_PREPARE_TIMEOUT 30
- #define GUN_EV_WAIT_TIMEOUT 120
- #define GUN_EVSE_WAIT_TIMEOUT 60
- #define GUN_COMP_WAIT_TIMEOUT 10
- #define GUN_PRECHARGING_TIMEOUT 60
- char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
- unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
- int whileLoopTime = 10000; // 10 ms
- int wtdFd = -1;
- byte _authorizeIndex = NO_DEFINE;
- bool IsAuthorizingMode();
- void ClearAuthorizedFlag();
- bool isDetectPlugin();
- void ClearDetectPluginFlag();
- int mystrcmp(unsigned char *p1, unsigned char *p2);
- long long DiffTimebWithNow(struct timeb ST);
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
- void ChargingTerminalProcess(byte gunIndex);
- void ChkPrimaryStatus();
- void StartSystemTimeoutDet(unsigned char flag);
- void StopSystemTimeoutDet();
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
- void StopGunInfoTimeoutDet(unsigned char gunIndex);
- int StoreLogMsg_1(const char *fmt, ...);
- unsigned long GetTimeoutValue(struct timeval _sour_time);
- void gpio_set_value(unsigned int gpio, unsigned int value);
- void PRINTF_FUNC(char *string, ...);
- void ChangeGunSelectByIndex(byte sel);
- void InformOcppErrOccur(byte codeType);
- void RecordAlarmCode(byte gunIndex, char *code);
- void RecordWarningCode(byte gunIndex, char *code);
- void ReleaseWarningCodeByString(byte gunIndex, char *code);
- void ReleaseAlarmCode(byte gunIndex);
- int DB_Open(sqlite3 *db);
- int DB_Insert_Record(sqlite3 *db, int gun_index);
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
- void InitialDHCP();
- int GetStartScheduleTime(unsigned char *time);
- #define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- #define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct PsuData *ShmPsuData;
- struct CHAdeMOData *ShmCHAdeMOData;
- struct GBTData *ShmGBTData;
- struct CcsData *ShmCcsData;
- struct PrimaryMcuData *ShmPrimaryMcuData;
- struct FanModuleData *ShmFanModuleData;
- struct RelayModuleData *ShmRelayModuleData;
- struct LedModuleData *ShmLedModuleData;
- struct OCPP16Data *ShmOCPP16Data;
- struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- struct timeb startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- struct timeb endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- // for initial index to check EV board type is correct
- byte _gunIndex = 0;
- byte _acgunIndex = 0;
- byte _chademoIndex = 0;
- byte _ccsIndex = 0;
- byte _gb_Index = 0;
- byte _ac_Index = 0;
- byte bd0_1_status = 0;
- byte bd0_2_status = 0;
- byte bd1_1_status = 0;
- byte bd1_2_status = 0;
- bool isCardScan = false;
- bool isModelNameMatch = true;
- int rfidFd = -1;
- char* rfidPortName = "/dev/ttyS2";
- char* fwVersion = "V0.18.00.0000.00";
- sqlite3 *localDb;
- bool isDb_ready;
- //================================================
- // initial can-bus
- //================================================
- int InitCanBus()
- {
- int s0,nbytes;
- struct timeval tv;
- struct ifreq ifr0;
- struct sockaddr_can addr0;
- system("/sbin/ip link set can0 down");
- system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
- system("/sbin/ip link set can0 up");
- s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
- tv.tv_sec = 0;
- tv.tv_usec = 10000;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
- #endif
- }
- strcpy(ifr0.ifr_name, "can0" );
- ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
- addr0.can_family = AF_CAN;
- addr0.can_ifindex = ifr0.ifr_ifindex;
- bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
- return s0;
- }
- //================================================
- // initial uart port
- //================================================
- char *_priPortName = "/dev/ttyS1";
- char *_485PortName = "/dev/ttyS5";
- int InitComPort(byte target)
- {
- int fd;
- struct termios tios;
- if(target == UPGRADE_PRI)
- fd = open(_priPortName, O_RDWR);
- else if (target == UPGRADE_FAN || target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED)
- fd = open(_485PortName, O_RDWR);
- if(fd<=0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("open 407 Communication port NG \n");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN]=0;
- tios.c_cc[VTIME]=(unsigned char)1;
- tios.c_lflag=0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- //=================================
- // Common routine
- //=================================
- void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
- {
- strncpy(dest, src + start, cnt);
- dest[cnt] = 0;
- }
- int InitWatchDog()
- {
- int fd;
- system("/usr/bin/fuser -k /dev/watchdog");
- sleep(1);
- system("echo V > /dev/watchdog");
- sleep(1);
- fd=open("/dev/watchdog", O_RDWR);
- if(fd<=0)
- {
- DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
- }
- return fd;
- }
- int StoreLogMsg_1(const char *fmt, ...)
- {
- char Buf[4096+256];
- char buffer[4096];
- va_list args;
- struct timeb SeqEndTime;
- struct tm *tm;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf,0,sizeof(Buf));
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm=localtime(&SeqEndTime.time);
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
- {
- sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
- tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
- printf("%s \n", Buf);
- }
- else
- {
- sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
- buffer,
- tm->tm_year+1900,tm->tm_mon+1);
- system(Buf);
- }
- return rc;
- }
- 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;
- }
- int mystrcmp(unsigned char *p1, unsigned char *p2)
- {
- while(*p1==*p2)
- {
- if(*p1=='\0' || *p2=='\0')
- break;
- p1++;
- p2++;
- }
- if(*p1=='\0' && *p2=='\0')
- return(PASS);
- else
- return(FAIL);
- }
- 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(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- void PRINTF_FUNC(char *string, ...)
- {
- va_list args;
- char buffer[4096];
- va_start(args, string);
- vsnprintf(buffer, sizeof(buffer), string, args);
- va_end(args);
- DEBUG_INFO_MSG("%s \n", buffer);
- }
- 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);
- }
- //==========================================
- // Check interface status
- //==========================================
- int isInterfaceUp(const char *interface)
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- strcpy(cmd, "ifconfig");
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, interface) > 0)
- {
- result = PASS;
- }
- }
- }
- pclose(fp);
- return result;
- }
- //=================================
- // Create all share memory
- //=================================
- int CreateShareMemory()
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
- #endif
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
- #endif
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
- #endif
- return 0;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
- #endif
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
- //creat ShmPsuData
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
- #endif
- return 0;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
- #endif
- return 0;
- }
- memset(ShmPsuData, 0, sizeof(struct PsuData));
- if(CHAdeMO_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
- #endif
- return 0;
- }
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
- #endif
- return 0;
- }
- memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
- }
- if(GB_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmGBTData NG \n");
- #endif
- return 0;
- }
- else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmGBTData NG \n");
- #endif
- return 0;
- }
- memset(ShmGBTData, 0, sizeof(struct GBTData));
- }
- //creat ShmCcsData
- if(CCS_QUANTITY > 0)
- {
- if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
- #endif
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
- #endif
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
- //creat ShmPrimaryMcuData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
- #endif
- return 0;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
- #endif
- return 0;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
- //creat ShmFanModuleData
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
- #endif
- return 0;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
- #endif
- return 0;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmLedModuleData NG \n");
- #endif
- return 0;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmLedModuleData NG \n");
- #endif
- return 0;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
- #endif
- return 0;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
- #endif
- return 0;
- }
- // memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- return 1;
- }
- //=================================
- // LCM Page
- //=================================
- void ChangeLcmByIndex(byte page_index)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
- page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
- {
- ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
- }
- }
- //======================================================
- // 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");
- /* (C14) EMU0.gpio3[7] */ /*CP open/short feature enable/disable, pull low for default enable*/
- system("echo 103 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio103/direction");
- system("echo 0 > /sys/class/gpio/gpio103/value");
- /* (B14) EMU1.gpio3[8] */ /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
- system("echo 104 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio104/direction");
- system("echo 0 > /sys/class/gpio/gpio104/value");
- #ifdef SystemLogMessage
- DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK");
- #endif
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd,wrd;
- unsigned char *buf;
- unsigned int ChkSum,ChkSumOrg;
- if((buf=malloc(MtdBlockSize))==NULL)
- {
- DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, MtdBlockSize);
- //================================================
- // Load configuration from mtdblock10
- //================================================
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.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);
- DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum=0;
- for(wrd=0;wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.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);
- DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum=0;
- for(wrd=0;wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
- fd = open("/dev/mtdblock12", O_RDWR);
- if (fd < 0)
- {
- free(buf);
- DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.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);
- DEBUG_ERROR_MSG("read factory default SysConfigData data NG,rebooting..\r\n");
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum=0;
- for(wrd=0;wrd<MtdBlockSize-4;wrd++)
- {
- ChkSum+=buf[wrd];
- }
- memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
- if(ChkSum!=ChkSumOrg)
- {
- DEBUG_ERROR_MSG("factory default SysConfigData checksum NG, restore factory default\r\n");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
- free(buf);
- DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
- return PASS;
- }
- int isRouteFail()
- {
- int result = YES;
- FILE *fp;
- char buf[512];
- fp = popen("route -n", "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "eth0") != NULL)
- result = NO;
- }
- }
- pclose(fp);
- return result;
- }
- int isReachableInternet()
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- char tmp[512];
- // if (ShmOCPP16Data->OcppConnStatus == PASS)
- // {
- // result = PASS;
- // }
- // else
- {
- strcpy(cmd, "ifconfig eth0");
- fp = popen(cmd, "r");
- if (fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strstr(buf, "inet addr:") > 0)
- {
- sscanf(buf, "%*s%s", tmp);
- substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
- if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL)
- {
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
- }
- }
- }
- }
- pclose(fp);
- memset(buf, 0x00, sizeof(buf));
- for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
- {
- sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "transmitted") > 0)
- {
- //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
- if(strstr(buf,"100%") != NULL)
- {
- }
- else
- {
- result = PASS;
- }
- //DEBUG_INFO("%s",buf);
- //DEBUG_INFO("%s\n",tmp);
- }
- }
- }
- pclose(fp);
- }
- }
- return result;
- }
- void InitEthernet()
- {
- char tmpbuf[256];
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
- system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
- sleep(2);
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
- system(tmpbuf);
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"route add default gw %s eth0 ",
- ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
- system(tmpbuf);
- //system("ifconfig lo up");
- // /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
- //Init Eth1 for administrator tool
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
- ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
- system(tmpbuf);
- //Run DHCP client if enabled
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("echo nameserver 8.8.8.8 > /etc/resolv.conf"); //Google DNS server
- system("echo nameserver 180.76.76.76 > /etc/resolv.conf"); //Baidu DNS server
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //Upgrade system id to /etc/hostname
- sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- pid_t pid = fork();
- uint8_t cnt_pingDNS_Fail;
- if(pid == 0)
- {
- for(;;)
- {
- if (isRouteFail())
- {
- PRINTF_FUNC("eth0 not in route, restart eht0. \n");
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- InitialDHCP();
- }
- }
- if(isReachableInternet() == PASS)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= NO;
- cnt_pingDNS_Fail = 0;
- }
- else
- {
- if(++cnt_pingDNS_Fail > 3)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = YES;
- }
- }
- bool ethResult = YES;
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet)
- ethResult = NO;
- else
- {
- system("/sbin/ifmetric eth0 0");
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric mlan0 1");
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric ppp0 2");
- }
- if (!ethResult &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = !ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi;
- if (ethResult)
- {
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric mlan0 0");
- }
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = !ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi;
- if (ethResult)
- {
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- system("/sbin/ifmetric mlan0 2");
- if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- system("/sbin/ifmetric eth0 1");
- system("/sbin/ifmetric ppp0 0");
- }
- }
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- sleep(5);
- }
- }
- #ifdef SystemLogMessage
- DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK. \n");
- #endif
- }
- int InitialRfidPort()
- {
- int uartO2 = open(rfidPortName, O_RDWR);
- struct termios tios;
- if (uartO2 != FAIL)
- {
- ioctl (uartO2, TCGETS, &tios);
- tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN] = 0;
- tios.c_cc[VTIME] = (unsigned char) 1;
- tios.c_lflag = 0;
- tcflush(uartO2, TCIFLUSH);
- ioctl(uartO2, TCSETS, &tios);
- }
- if (uartO2 < 0)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
- }
- return uartO2;
- }
- void GetMacAddress()
- {
- for (byte index = 0; index < 2; index++)
- {
- int fd;
- struct ifreq ifr;
- char tarEth[5];
- char Mac[18];
- sprintf(tarEth,"eth%d",index);
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- ifr.ifr_addr.sa_family = AF_INET;
- strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
- ioctl(fd, SIOCGIFHWADDR, &ifr);
- close(fd);
- sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
- ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
- ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
- if (index == 0)
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
- else
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
- }
- }
- void GetFirmwareVersion()
- {
- // Get CSU root file system version
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- byte count = 0, chademo = 0, ccs = 0, gb = 0;
- for(uint8_t idx=0;idx<3;idx++)
- {
- if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J')
- {
- chademo++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
- {
- gb++;
- count++;
- }
- else if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
- ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E')
- {
- ccs++;
- count++;
- }
- }
- if (count == 1)
- {
- if (chademo > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
- else if (ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
- else if (gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
- }
- else
- {
- if (chademo > 0 && ccs > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
- else if (chademo > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
- else if (ccs > 0 && gb > 0)
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
- }
- // Get network option from model name
- switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
- {
- case 'B':
- case 'U':
- //Blue tooth
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
- break;
- case 'W':
- // WIFI
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
- break;
- case 'T':
- // 3G/4G
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
- break;
- default:
- // LAN
- ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
- break;
- }
- // Get rating power from model name
- memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
- // Get IEC or UL
- char _buf[3] = {0};
- memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
- if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
- else if (strcmp(_buf, "WU") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
- sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
- ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
- ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
- ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
- ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
- sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
- memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
- sprintf(cmd, "/bin/uname -r");
- fp = popen(cmd, "r");
- if(fp == NULL)
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
- else
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
- }
- }
- // 雙槍 CCS + Chademo
- GetFirmwareVersion();
- //sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
- ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
- ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
- ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
- ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
- memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
- memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
- ShmPrimaryMcuData->SelfTest_Comp = NO;
- ShmRelayModuleData->SelfTest_Comp = NO;
- ShmFanModuleData->SelfTest_Comp = NO;
- ShmLedModuleData->SelfTest_Comp = NO;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- ShmFanModuleData->TestFanSpeed = 0;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- char EvsePower[2];
- EvsePower[2] = '\0';
- unsigned short buf_pow = 0;
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
- {
- strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
- if (strcmp(EvsePower, "15") == EQUAL)
- buf_pow = 150;
- else if (strcmp(EvsePower, "30") == EQUAL)
- buf_pow = 30;
- else if (strcmp(EvsePower, "60") == EQUAL)
- buf_pow = 60;
- else if (strcmp(EvsePower, "12") == EQUAL)
- buf_pow = 120;
- else if (strcmp(EvsePower, "18") == EQUAL)
- buf_pow = 180;
- else if (strcmp(EvsePower, "36") == EQUAL)
- buf_pow = 360;
- ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
- if(ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow)
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
- }
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- }
- int Initialization()
- {
- // 初始化卡號驗證的 Flag
- ClearAuthorizedFlag();
- // 初始化插槍驗證的 Flag
- ClearDetectPluginFlag();
- // UART 2 for Rfid
- rfidFd = InitialRfidPort();
- int pinOut[2] = { 116, 115 };
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- chargingInfo[count]->RemoteStartFlag = NO;
- if (chargingInfo[count]->Type == _Type_Chademo)
- {
- gpio_set_value(pinOut[count], 0x00);
- ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- else if (chargingInfo[count]->Type == _Type_GB)
- {
- gpio_set_value(pinOut[count], 0x00);
- ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- else if (chargingInfo[count]->Type == _Type_CCS_2)
- {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- gpio_set_value(pinOut[1], 0x01);
- else
- gpio_set_value(pinOut[count], 0x01);
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
- }
- }
- strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
- {
- ac_chargingInfo[count]->RemoteStartFlag = NO;
- if (ac_chargingInfo[count]->Type == _Type_AC)
- {
- ac_chargingInfo[count]->SelfTest_Comp = NO;
- strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
- }
- }
- PRINTF_FUNC("Initialization OK \n");
- return PASS;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- // system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
- // sleep(3);
- // system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
- // sleep(1);
- // system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
- return result;
- }
- bool DisplaySelfTestFailReason()
- {
- bool result = false;
- // RB、FB、407、EV 小板中有些板子無回應
- if (ShmRelayModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; result = true; }
- if (ShmFanModuleData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; result = true; }
- if (ShmPrimaryMcuData->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; result = true; }
- // if (ShmLedModuleData->SelfTest_Comp == NO)
- // { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES; }
- if (ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
- { result = true; }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; result = true; }
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = YES; result = true; }
- }
- else if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; result = true; }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
- {
- // 先借 GBT 顯示
- if (ac_chargingInfo[index]->SelfTest_Comp == NO)
- { ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = YES; result = true; }
- }
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
- {
- // AC Contact 未搭上
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
- result = true;
- }
- else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0)
- {
- // PSU 通訊問題
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
- result = true;
- }
- return result;
- }
- void SelfTestRun()
- {
- bool evInitFlag = false;
- StartSystemTimeoutDet(Timeout_SelftestChk);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
- while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE ||
- GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL <= 20)
- {
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- return;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
- {
- if (ShmPsuData->Work_Step == _NO_WORKING ||
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- return;
- }
- switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
- {
- case _STEST_VERSION:
- {
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
- {
- //PRINTF_FUNC("RB pass \n");
- ShmRelayModuleData->SelfTest_Comp = YES;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
- ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
- {
- //PRINTF_FUNC("Fan pass \n");
- ShmFanModuleData->SelfTest_Comp = YES;
- }
- if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
- ShmPrimaryMcuData->version[0] != '\0')
- {
- //PRINTF_FUNC("407 pass \n");
- ShmPrimaryMcuData->SelfTest_Comp = YES;
- }
- // EV 小板
- if (!evInitFlag)
- {
- evInitFlag = YES;
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
- {
- //PRINTF_FUNC("chademo pass \n");
- ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- }
- else
- {
- //PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
- ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
- {
- //PRINTF_FUNC("GBT pass \n");
- ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- }
- else
- {
- //PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- else if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
- {
- //PRINTF_FUNC("ccs fw = %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
- ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
- }
- else
- {
- //PRINTF_FUNC("ccs fw lose...... %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
- evInitFlag = NO;
- }
- }
- }
- }
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
- {
- if (ac_chargingInfo[index]->Type == _Type_AC)
- {
- if (strlen((char *)ac_chargingInfo[index]->version) != 0 ||
- ac_chargingInfo[index]->version[0] != '\0')
- {
- ac_chargingInfo[index]->SelfTest_Comp = YES;
- }
- else
- {
- evInitFlag = NO;
- }
- }
- }
- }
- if (ShmFanModuleData->SelfTest_Comp &&
- ShmRelayModuleData->SelfTest_Comp &&
- ShmPrimaryMcuData->SelfTest_Comp &&
- evInitFlag)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
- }
- }
- break;
- case _STEST_AC_CONTACTOR:
- {
- //ShmPsuData->Work_Step = _TEST_COMPLETE;
- // 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
- PRINTF_FUNC("Communication board pass. \n");
- }
- }
- break;
- case _STEST_PSU_DETECT:
- {
- if (ShmPsuData->Work_Step >= GET_SYS_CAP)
- {
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
- }
- }
- break;
- case _STEST_PSU_CAP:
- {
- // 此測試是要確認當前總輸出能力
- // 如果沒有 PSU 模組請 bypass
- if (ShmPsuData->Work_Step == BOOTING_COMPLETE)
- {
- sleep(1);
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
- ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
- }
- }
- break;
- }
- }
- else
- break;
- usleep(100000);
- }
- }
- int SpawnTask()
- {
- 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_PsuComm &");
- system("/root/Module_ProduceUtils &");
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- system("/root/OcppBackend &");
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- system("/root/Module_4g &");
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- system("/root/Module_Wifi &");
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- system("/root/Module_4g &");
- system("/root/Module_Wifi &");
- }
- return PASS;
- }
- int StoreUsrConfigData(struct SysConfigData *UsrData)
- {
- int result = PASS;
- int fd,wrd;
- unsigned int i,Chk;
- unsigned char *ptr, *BufTmp;
- Chk=0;
- ptr=(unsigned char *)UsrData;
- if((BufTmp = malloc(MtdBlockSize)) != NULL)
- {
- memset(BufTmp, 0, MtdBlockSize);
- memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
- for(i=0; i<MtdBlockSize-4; i++)
- Chk+=*(ptr+i);
- memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
- fd = open("/dev/mtdblock10", O_RDWR);
- if (fd > 0)
- {
- wrd=write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd >= MtdBlockSize)
- {
- fd = open("/dev/mtdblock11", O_RDWR);
- if (fd > 0)
- {
- wrd=write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
- result = FAIL;
- }
- }
- else
- {
- DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
- result = FAIL;
- }
- if(BufTmp != NULL)
- free(BufTmp);
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- bool isEvBoardStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->StopChargeFlag;
- }
- //===============================================
- // 掃描插槍狀況
- //===============================================
- void ClearDetectPluginFlag()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- if (chargingInfo[gun_index]->RemoteStartFlag == YES)
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- }
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- }
- void DetectPluginStart()
- {
- ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
- }
- bool isDetectPlugin()
- {
- if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
- return YES;
- return NO;
- }
- //===============================================
- // Common Detect Chk - Chademo
- //===============================================
- bool isEvGunLocked_chademo(byte gunIndex)
- {
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
- }
- bool isEvContactorWelding_chademo(byte gunIndex)
- {
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
- }
- bool isEvStopReq_chademo(byte gunIndex)
- {
- return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
- }
- bool isEvStopCharging_chademo(byte gunIndex)
- {
- if (isEvGunLocked_chademo(gunIndex) == NO)
- {
- // 無鎖槍 = 停止
- PRINTF_FUNC("gun locked none (%d) \n", gunIndex);
- return YES;
- }
- return NO;
- }
- byte isPrechargeStatus_chademo(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - GB
- //===============================================
- bool isEvGunLocked_gb(byte gunIndex)
- {
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
- }
- bool isEvStopCharging_gb(byte gunIndex)
- {
- if (isEvGunLocked_gb(gunIndex) == NO)
- {
- // 無鎖槍 = 停止
- PRINTF_FUNC("gun locked none. \n");
- return YES;
- }
- return NO;
- }
- byte isPrechargeStatus_gb(byte gunIndex)
- {
- byte result = 0x00;
- result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- return result;
- }
- //===============================================
- // Common Detect Chk - CCS
- //===============================================
- bool isEvGunLocked_ccs(byte gunIndex)
- {
- return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
- }
- byte isPrechargeStatus_ccs(byte gunIndex)
- {
- byte result = 0x00;
- if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
- {
- result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
- }
- return result;
- }
- bool isEvStopCharging_ccs(byte gunIndex)
- {
- if (isEvGunLocked_ccs(gunIndex) == NO)
- {
- // 無鎖槍 = 停止
- PRINTF_FUNC("gun locked none. \n");
- return YES;
- }
- return NO;
- }
- //===============================================
- // Callback
- //===============================================
- void DisplayChargingInfo()
- {
- PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
- for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->SystemStatus != S_IDLE &&
- chargingInfo[i]->SystemStatus != S_RESERVATION)
- {
- ChangeGunSelectByIndex(i);
- return;
- }
- }
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- }
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _AutoReturnTimeout()
- {
- PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
- {
- ClearDetectPluginFlag();
- }
- else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
- {
- DetectPluginStart();
- }
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _SelfTestTimeout()
- {
- if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_ALARM);
- }
- }
- ShmPsuData->Work_Step = _NO_WORKING;
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
- PRINTF_FUNC("Self test timeout. \n");
- }
- void _AuthorizedTimeout()
- {
- if(IsAuthorizingMode())
- {
- PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
- isCardScan = false;
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- //ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- }
- }
- void _DetectPlugInTimeout()
- {
- PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearDetectPluginFlag();
- usleep(50000);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- }
- void _DetectEvChargingEnableTimeout(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- if(!isEvGunLocked_chademo(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- if(!isEvGunLocked_ccs(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- if(!isEvGunLocked_ccs(gunIndex))
- {
- PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
- }
- }
- ChargingTerminalProcess(gunIndex);
- _AutoReturnTimeout();
- }
- void _DetectEvseChargingEnableTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
- //if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- _AutoReturnTimeout();
- }
- }
- void _PrepareTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
- setChargerMode(gunIndex, MODE_IDLE);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- _AutoReturnTimeout();
- }
- void _CcsPrechargeTimeout(byte gunIndex)
- {
- PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
- setChargerMode(gunIndex, MODE_IDLE);
- }
- //===============================================
- // 取得卡號與卡號驗證
- //===============================================
- bool canStartCharging()
- {
- char buf2[16] = "";
- memset(buf2, 0, ARRAY_SIZE(buf2));
- for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++)
- {
- sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
- }
- sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
- //printf("ExpiryDate = %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
- //printf("ParentIdTag = %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
- int _time = GetStartScheduleTime(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
- // 因為無法得知實際的長度,所以只能用搜尋的方式
- if(strcmp(buf2, "Accepted") == EQUAL && _time < -5)
- return true;
- else
- {
- }
- return false;
- }
- void AuthorizingStart()
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
- }
- void ClearAuthorizedFlag()
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
- ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
- }
- bool isAuthorizedComplete()
- {
- if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == NO)
- return false;
- return true;
- }
- bool IsAuthorizingMode()
- {
- if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
- return false;
- return true;
- }
- //===============================================
- // 紀錄 Alarm Code
- //===============================================
- void RecordAlarmCode(byte gunIndex, char *code)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
- if (strcmp(code, "012234") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
- if (strcmp(code, "012235") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
- if (strcmp(code, "012236") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
- if (strcmp(code, "012288") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
- if (strcmp(code, "012289") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
- if (strcmp(code, "012290") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
- }
- void RecordWarningCode(byte gunIndex, char *code)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
- if (strcmp(code, "012296") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
- if (strcmp(code, "012297") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
- if (strcmp(code, "012298") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
- }
- void ReleaseAlarmCode(byte gunIndex)
- {
- bool isCleanCheck = false;
- char code[7];
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
- {
- memcpy(code, "012234", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- }
- else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES)
- {
- memcpy(code, "012289", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- }
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES)
- {
- ReleaseWarningCodeByString(gunIndex, "012296");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
- {
- memcpy(code, "012236", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- }
- else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES)
- {
- memcpy(code, "012290", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- }
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES)
- {
- ReleaseWarningCodeByString(gunIndex, "012298");
- }
- }
- else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
- {
- memcpy(code, "012235", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- }
- else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES)
- {
- memcpy(code, "012288", 6);
- memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
- isCleanCheck = true;
- }
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES)
- {
- ReleaseWarningCodeByString(gunIndex, "012297");
- }
- }
- if (isCleanCheck)
- {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- {
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL)
- {
- if (strncmp(code, "012234", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
- if (strncmp(code, "012289", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
- if (strncmp(code, "012236", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
- if (strncmp(code, "012290", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
- if (strncmp(code, "012235", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
- if (strncmp(code, "012288", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
- }
- }
- }
- }
- }
- void ReleaseWarningCodeByString(byte gunIndex, char *code)
- {
- bool isCleanCheck = false;
- if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
- isCleanCheck = true;
- }
- else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
- isCleanCheck = true;
- }
- else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES)
- {
- memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
- isCleanCheck = true;
- }
- if (isCleanCheck)
- {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- {
- if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL)
- {
- if (strncmp(code, "012296", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
- if (strncmp(code, "012297", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
- if (strncmp(code, "012298", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
- }
- }
- }
- }
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void AcChargingTerminalProcess()
- {
- ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
- }
- void StopChargingProcessByString(byte level)
- {
- if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
- {
- ShmSysConfigAndInfo->SysWarningInfo.Level = level;
- }
- }
- void ReleaseChargingProcessByString(byte level)
- {
- if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
- ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
- }
- // 一般錯誤停止充電處理函式
- void BoardErrOccurByString(byte index, char *code)
- {
- byte level = 1;
- if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
- }
- ChargingTerminalProcess(index);
- }
- StopChargingProcessByString(level);
- }
- // 急停狀況的停止充電處理函式
- void EmcOccureByString(char *code)
- {
- byte level = 2;
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- if (strncmp(code, "012251", 6) == EQUAL || strncmp(code, "012252", 6) == EQUAL ||
- strncmp(code, "012238", 6) == EQUAL)
- {
- for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
- {
- if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
- (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- ChargingTerminalProcess(gun);
- }
- }
- StopChargingProcessByString(level);
- InformOcppErrOccur(4);
- }
- }
- void ReleaseBoardErrOccurByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 1;
- if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
- }
- if (isTrigger)
- {
- ReleaseChargingProcessByString(level);
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 2;
- if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- }
- else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- }
- else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- if (isTrigger)
- {
- ReleaseChargingProcessByString(level);
- InformOcppErrOccur(6);
- }
- }
- //===============================================
- // 確認硬體 (按鈕) 狀態
- //===============================================
- bool leftBtnPush = false;
- bool rightBtnPush = false;
- void ChkPrimaryStatus()
- {
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- EmcOccureByString("012251");
- }
- else
- ReleaseEmsOccureByString(0, "012251");
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- EmcOccureByString("012238");
- }
- else
- ReleaseEmsOccureByString(0, "012238");
- if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
- }
- else
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccureByString("012252");
- }
- else
- ReleaseEmsOccureByString(0, "012252");
- if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
- {
- if(!leftBtnPush)
- {
- leftBtnPush = true;
- PRINTF_FUNC("left btn down............................... \n");
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- switch(ac_chargingInfo[0]->SystemStatus)
- {
- case S_IDLE:
- {
- if(isDetectPlugin())
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- {
- // 取消充電
- AcChargingTerminalProcess();
- }
- break;
- case S_CHARGING:
- {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 停止充電
- AcChargingTerminalProcess();
- }
- }
- break;
- case S_COMPLETE:
- {}
- break;
- }
- }
- switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
- {
- case S_IDLE:
- {
- if(isDetectPlugin())
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- }
- break;
- case S_REASSIGN_CHECK:
- case S_REASSIGN:
- case S_PREPARNING:
- case S_PREPARING_FOR_EV:
- case S_PREPARING_FOR_EVSE:
- case S_CCS_PRECHARGE_ST0:
- case S_CCS_PRECHARGE_ST1:
- {
- // 取消充電
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- AcChargingTerminalProcess();
- else
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- break;
- case S_CHARGING:
- {
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart == NO)
- {
- // 停止充電
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- break;
- case S_COMPLETE:
- {
- // 回 IDLE
- //PRINTF_FUNC("right btn down.................S_COMPLETE \n");
- //chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
- }
- break;
- }
- }
- }
- else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
- {
- if(leftBtnPush)
- {
- leftBtnPush = false;
- PRINTF_FUNC("left btn up............................... \n");
- }
- }
- if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
- {
- if(!rightBtnPush)
- {
- rightBtnPush = true;
- PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
- else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
- chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- return;
- }
- }
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
- ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- }
- }
- }
- else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
- {
- if(rightBtnPush)
- {
- rightBtnPush = false;
- PRINTF_FUNC("right btn up............................... \n");
- }
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckErrorOccurStatus(byte index)
- {
- // 小板
- if (chargingInfo[index]->Type == _Type_Chademo)
- {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
- BoardErrOccurByString(index, "011012");
- // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
- // BoardErrOccurByString(index, "012234");
- }
- else if (chargingInfo[index]->Type == _Type_GB)
- {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES)
- BoardErrOccurByString(index, "011016");
- // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
- // BoardErrOccurByString(index, "012236");
- }
- else if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
- BoardErrOccurByString(index, "011014");
- // else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
- // BoardErrOccurByString(index, "012235");
- }
- // RB
- if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
- StopChargingProcessByString(2);
- InformOcppErrOccur(13);
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- InformOcppErrOccur(14);
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- InformOcppErrOccur(6);
- }
- }
- }
- //===============================================
- // 確認 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()
- {
- int pinIn[4] = { 22, 23, 44, 45 };
- unsigned int gpioValue = 0;
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
- gpio_get_value(pinIn[i], &gpioValue);
- {
- switch (pinIn[i])
- {
- case 22:
- bd1_1_status = gpioValue;
- break;
- case 23:
- bd1_2_status = gpioValue;
- break;
- case 44:
- bd0_1_status = gpioValue;
- break;
- case 45:
- bd0_2_status = gpioValue;
- break;
- }
- }
- }
- }
- void CheckGpioInStatus()
- {
- int pinIn[2] = { 27, 47 };
- unsigned int gpioValue = 0;
- for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
- {
- gpio_get_value(pinIn[i], &gpioValue);
- if (gpioValue == 0x01)
- {
- switch(pinIn[i])
- {
- // 小板緊急停止
- case 47:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 1)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- BoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- BoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- case 27:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 3)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- BoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- BoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- }
- }
- else
- {
- switch (pinIn[i])
- {
- // 小板解除緊急停止
- case 47:
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 1)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- ReleaseBoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- ReleaseBoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- case 27:
- {
- for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->slotsIndex == 3)
- {
- if (chargingInfo[i]->Type == _Type_Chademo)
- ReleaseBoardErrOccurByString(i, "023730");
- else if (chargingInfo[i]->Type == _Type_CCS_2)
- ReleaseBoardErrOccurByString(i, "013627");
- break;
- }
- }
- }
- break;
- }
- }
- }
- }
- //===============================================
- // Main process
- //===============================================
- // 檢查 Byte 中某個 Bit 的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
- {
- return ( _byte & mask_table[_bit] ) != 0x00;
- }
- // 設定 Byte 中某個 Bit的值
- // _byte : 欲改變的 byte
- // _bit : 該 byte 的第幾個 bit
- // value : 修改的值為 0 or 1
- void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
- {
- if(value == 1)
- *_byte |= (1 << _bit);
- else if (value == 0)
- *_byte ^= (1 << _bit);
- }
- void UserScanFunction()
- {
- bool idleReq = false;
- unsigned char idleIndex = 255;
- unsigned char stopReq = 255;
- // 當前非驗證的狀態
- if(!IsAuthorizingMode())
- {
- // 先判斷現在是否可以提供刷卡
- // 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
- // 2. 停止充電
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- return;
- }
- for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- if (chargingInfo[i]->SystemStatus == S_CHARGING)
- {
- stopReq = i;
- }
- if ((chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable == YES) ||
- (_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsAvailable == YES))
- {
- idleReq = true;
- idleIndex = i;
- }
- }
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ac_chargingInfo[0]->SystemStatus == S_CHARGING)
- {
- stopReq = DEFAULT_AC_INDEX;
- }
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
- {
- if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
- {
- char value[32];
- PRINTF_FUNC("ac stop charging \n");
- PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
- ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
- memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId,
- ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
- {
- AcChargingTerminalProcess();
- }
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
- (_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)))
- {
- char value[32];
- PRINTF_FUNC("stop charging \n");
- PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
- memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
- ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
- // 同一張卡直接停掉
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
- {
- ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- // // 進驗證
- // if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
- // {
- // _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
- // }
- // else
- // {
- // _authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
- // }
- //
- // StartSystemTimeoutDet(Timeout_AuthorizingForStop);
- // AuthorizingStart();
- }
- }
- else if (idleReq)
- {
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
- stopReq != 255 &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- idleReq = false;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
- (idleIndex != 255 && chargingInfo[idleIndex]->SystemStatus == S_IDLE))
- {
- PRINTF_FUNC("// LCM => Authorizing \n");
- // LCM => Authorizing
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
- // 進入確認卡號狀態
- AuthorizingStart();
- }
- else
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- else
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- }
- }
- else
- {
- // 透過後臺停止充電的判斷
- if (isAuthorizedComplete() ||
- (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- // 判斷後台回覆狀態
- if(canStartCharging() ||
- (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
- ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
- {
- if (_authorizeIndex != NO_DEFINE)
- {
- // 先找 AC
- if (_authorizeIndex == DEFAULT_AC_INDEX)
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
- {
- AcChargingTerminalProcess();
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
- strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
- {
- ChargingTerminalProcess(_authorizeIndex);
- }
- }
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- _authorizeIndex = NO_DEFINE;
- }
- }
- else
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- }
- else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
- {
- // 白名單驗證
- for (int i = 0; i < 10; i++)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
- {
- ChargingTerminalProcess(_authorizeIndex);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
- }
- }
- unsigned char isModeChange(unsigned char gun_index)
- {
- unsigned char result = NO;
- if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
- {
- result = YES;
- chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
- }
- return result;
- }
- void ScannerCardProcess()
- {
- if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
- ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- isCardScan = true;
- // 處理刷卡及驗證卡號的動作
- UserScanFunction();
- }
- if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
- {
- StartSystemTimeoutDet(Timeout_Authorizing);
- // 確認驗證卡號完成沒
- if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
- {
- StopSystemTimeoutDet();
- // 判斷後台回覆狀態
- if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
- {
- // LCM => Authorize complete
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- }
- else
- {
- // LCM => Authorize fail
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- }
- ClearAuthorizedFlag();
- }
- else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
- {
- // 白名單驗證
- for (int i = 0; i < 10; i++)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
- {
- if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
- ClearAuthorizedFlag();
- break;
- }
- }
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
- {
- StartSystemTimeoutDet(Timeout_VerifyFail);
- isCardScan = false;
- }
- else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
- {
- StartSystemTimeoutDet(Timeout_VerifyComp);
- }
- else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
- {
- StartSystemTimeoutDet(Timeout_WaitPlug);
- }
- else
- isCardScan = false;
- }
- bool AddGunInfoByConnector(byte typeValue, byte slots)
- {
- bool result = true;
- switch (typeValue)
- {
- case '0': // none
- break;
- case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
- break;
- case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
- break;
- case '3': // IEC 62196-2 Type 2 Plug
- case '4': // IEC 62196-2 Type 2 Socket
- if (AC_QUANTITY > _ac_Index)
- {
- ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
- // AC 固定 index
- ac_chargingInfo[_acgunIndex]->Index = 0;
- ac_chargingInfo[_acgunIndex]->ReservationId = -1;
- ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
- ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
- ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
- _ac_Index++;
- _acgunIndex++;
- }
- else
- result = false;
- break;
- case '5': // GB/T AC Plug
- break;
- case '6': // GB/T AC Socket
- break;
- case 'J': // CHAdeMO
- {
- if (CHAdeMO_QUANTITY > _chademoIndex)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_Chademo;
- chargingInfo[_gunIndex]->type_index = _chademoIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- _chademoIndex++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'U': // CCS1 combo
- case 'E': // CCS2 combo
- {
- if (CCS_QUANTITY > _ccsIndex)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_CCS_2;
- chargingInfo[_gunIndex]->type_index = _ccsIndex;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- // 現階段預設為走 DIN70121
- ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
- _ccsIndex++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'G': // GBT DC
- {
- if (GB_QUANTITY > _gb_Index)
- {
- chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
- chargingInfo[_gunIndex]->Index = _gunIndex;
- chargingInfo[_gunIndex]->ReservationId = -1;
- chargingInfo[_gunIndex]->slotsIndex = slots;
- chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
- chargingInfo[_gunIndex]->Type = _Type_GB;
- chargingInfo[_gunIndex]->type_index = _gb_Index;
- chargingInfo[_gunIndex]->IsAvailable = YES;
- _gb_Index++;
- _gunIndex++;
- }
- else
- result = false;
- }
- break;
- case 'D': // GBT DC x 2
- break;
- }
- return result;
- }
- bool CheckConnectorTypeStatus()
- {
- bool result = true;
- PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
- bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
- {
- byte slots = 1;
- for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
- {
- if(!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots))
- {
- return false;
- }
- slots++;
- }
- // AC index 接在 DC 後面
- if (AC_QUANTITY > 0)
- ac_chargingInfo[0]->Index += _gunIndex;
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
- PRINTF_FUNC("DC _gunCount = %d, AC _gunCount = %d \n",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
- ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
- result = false;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- {
- chargingInfo[0]->Evboard_id = 0x01;
- PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
- }
- else
- {
- // 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
- for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1)
- {
- // 與硬體相同 type : Chademo
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0)
- {
- // 與硬體相同 type : CCS
- if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1)
- {
- // 與硬體相同 type : GB
- if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- }
- if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1)
- {
- // 與硬體相同 type : Chademo
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0)
- {
- // 與硬體相同 type : CCS
- if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1)
- {
- // 與硬體相同 type : GB
- if (chargingInfo[gunIndex]->Type == _Type_GB)
- {
- chargingInfo[gunIndex]->Evboard_id = 0x02;
- }
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
- chargingInfo[gunIndex]->Evboard_id = 0x01;
- }
- PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", gunIndex, chargingInfo[gunIndex]->Type, chargingInfo[gunIndex]->Evboard_id);
- if (chargingInfo[gunIndex]->Evboard_id == 0x00)
- result = false;
- }
- }
- }
- else
- {
- // Module Name 不正確 - 告警
- result = false;
- }
- return result;
- }
- void KillTask()
- {
- ChangeLcmByIndex(_LCM_FIX);
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_PsuComm");
- //system("killall OcppBackend &");
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- char CheckUpdateProcess()
- {
- DIR *d;
- struct dirent *dir;
- d = opendir("/mnt/");
- if (d)
- {
- long int MaxLen=48*1024*1024, ImageLen = 0;
- while ((dir = readdir(d)) != NULL)
- {
- char *new_str;
- new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
- new_str[0] = '\0';
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- int fd = open(new_str, O_RDONLY);
- if (fd < 0)
- {
- return FAIL;
- }
- unsigned char *ptr = malloc(MaxLen); //-48 is take out the header
- memset(ptr, 0xFF, MaxLen); //-48 is take out the header
- //get the image length
- ImageLen = read(fd, ptr, MaxLen);
- if (ImageLen > 20)
- {
- unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
- PRINTF_FUNC("Typed...%x \r\n", Type);
- switch (Type)
- {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- {
- if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- return PASS;
- else
- return FAIL;
- }
- break;
- case 0x10000007:
- case 0x10000008:
- case 0x10000009:
- case 0x1000000A:
- {
- bool isPass = true;
- int CanFd = InitCanBus();
- if (CanFd > 0)
- {
- for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (!isPass)
- break;
- if (chargingInfo[index]->Type == _Type_CCS_2)
- {
- if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
- {
- isPass = false;
- }
- }
- }
- }
- else
- {
- printf("Upgrade CCS open CAN FD fail.\n");
- isPass = false;
- }
- return isPass;
- }
- break;
- case 0x10000006:
- case 0x1000000D:
- case 0x1000000E:
- case 0x20000002:
- case 0x10000014:
- {
- // CSU_PRIMARY_CONTROLLER : 0x10000006
- byte target = 0x00;
- if (Type == 0x10000006)
- target = UPGRADE_PRI;
- else if (Type == 0x1000000D)
- target = UPGRADE_RB;
- else if (Type == 0x1000000E)
- target = UPGRADE_FAN;
- else if (Type == 0x20000002)
- target = UPGRADE_AC;
- else if (Type == 0x10000014)
- target = UPGRADE_LED;
- int fd = InitComPort(target);
- if (Upgrade_UART(fd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- return PASS;
- else
- return FAIL;
- close(fd);
- }
- break;
- case 0x1000000B:
- case 0x1000000C:
- {
- // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
- bool isPass = true;
- int CanFd = InitCanBus();
- if (CanFd > 0)
- {
- for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- if (!isPass)
- break;
- if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
- (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB))
- {
- if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
- return PASS;
- else
- return FAIL;
- }
- }
- }
- else
- {
- PRINTF_FUNC("Upgrad FD fail. \n");
- isPass = false;
- }
- return isPass;
- break;
- }
- }
- }
- free(new_str);
- free(ptr);
- }
- }
- free(dir);
- closedir(d);
- return FAIL;
- }
- void CreateRfidFork()
- {
- pid_t rfidRecPid;
- rfidRecPid = fork();
- if (rfidRecPid == 0)
- {
- while(true)
- {
- // 刷卡判斷
- RFID rfid;
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
- !ShmSysConfigAndInfo->SysConfig.isRFID)
- {}
- else if(getRequestCardSN(rfidFd, 0, &rfid))
- {
- PRINTF_FUNC("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
- if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
- {
- if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
- {
- switch (rfid.snType)
- {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5],
- rfid.currentCard[6]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3],
- rfid.currentCard[4], rfid.currentCard[5],
- rfid.currentCard[6], rfid.currentCard[7],
- rfid.currentCard[8], rfid.currentCard[9]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[0], rfid.currentCard[1],
- rfid.currentCard[2], rfid.currentCard[3]);
- break;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
- {
- switch (rfid.snType)
- {
- case RFID_SN_TYPE_6BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[5], rfid.currentCard[4],
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_7BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[6], rfid.currentCard[5],
- rfid.currentCard[4], rfid.currentCard[3],
- rfid.currentCard[2], rfid.currentCard[1],
- rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_10BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
- rfid.currentCard[9], rfid.currentCard[8],
- rfid.currentCard[7], rfid.currentCard[6],
- rfid.currentCard[5], rfid.currentCard[4],
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- case RFID_SN_TYPE_4BYTE:
- sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
- "%02X%02X%02X%02X",
- rfid.currentCard[3], rfid.currentCard[2],
- rfid.currentCard[1], rfid.currentCard[0]);
- break;
- }
- }
- PRINTF_FUNC("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
- }
- }
- sleep(1);
- }
- }
- }
- void StartSystemTimeoutDet(unsigned char flag)
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
- {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- }
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
- }
- void StopSystemTimeoutDet()
- {
- gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
- }
- void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- if (chargingInfo[gunIndex]->TimeoutFlag != flag)
- {
- gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
- }
- chargingInfo[gunIndex]->TimeoutFlag = flag;
- }
- }
- void StopGunInfoTimeoutDet(unsigned char gunIndex)
- {
- if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
- {
- chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
- }
- }
- void CheckConnectionTimeout()
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- else
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
- {
- _connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- if(_connectionTimeout <= 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- else
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid > 0)
- {
- gettimeofday(&_cmdSubPriority_time, NULL);
- CheckConnectionTimeout();
- while(true)
- {
- if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
- {
- CheckConnectionTimeout();
- gettimeofday(&_cmdSubPriority_time, NULL);
- }
- //printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
- // 系統
- switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
- {
- case Timeout_SelftestChk:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT)
- {
- _SelfTestTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_Authorizing:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT)
- {
- _AuthorizedTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_VerifyFail:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
- {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_VerifyComp:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT)
- {
- _AutoReturnTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_WaitPlug:
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout)
- {
- _DetectPlugInTimeout();
- StopSystemTimeoutDet();
- }
- break;
- case Timeout_ReturnToChargingGunDet:
- {
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE)
- {
- DisplayChargingInfo();
- StopSystemTimeoutDet();
- }
- }
- break;
- case Timeout_AuthorizingForStop:
- {
- if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- ClearAuthorizedFlag();
- StopSystemTimeoutDet();
- }
- }
- break;
- }
- // 各槍
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- //printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
- switch(chargingInfo[gun_index]->TimeoutFlag)
- {
- case Timeout_Preparing:
- {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT)
- {
- _PrepareTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvChargingDet:
- {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT)
- {
- _DetectEvChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvseChargingDet:
- {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT)
- {
- _DetectEvseChargingEnableTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_EvseCompleteDet:
- {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT)
- {
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- case Timeout_ForCcsPrechargeDet:
- {
- if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT)
- {
- _CcsPrechargeTimeout(gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- }
- break;
- }
- }
- sleep(1);
- }
- }
- }
- void GetSystemTime()
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- tmCSU->tm_sec);
- // byte date[14];
- //
- //
- // //sprintf(&date, "%d", );
- //
- // date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
- // date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
- // date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
- // date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
- // date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
- //
- // date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
- // date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
- //
- // date[6] = (tmCSU->tm_mday) / 10 % 10;
- // date[7] = (tmCSU->tm_mday) / 1 % 10;
- //
- // date[8] = (tmCSU->tm_hour) / 10 % 10;
- // date[9] = (tmCSU->tm_hour) / 1 % 10;
- //
- // date[10] = (tmCSU->tm_min) / 10 % 10;
- // date[11] = (tmCSU->tm_min) / 1 % 10;
- //
- // date[12] = (tmCSU->tm_sec) / 10 % 10;
- // date[13] = (tmCSU->tm_sec) / 1 % 10;
- // PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
- // date[4], date[5], date[6], date[7],
- // date[8], date[9], date[10], date[11],
- // date[12], date[13]);
- }
- void CheckFactoryConfigFunction()
- {
- if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
- {
- system("cd /root;./FactoryConfig -m");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- void CheckFwUpdateFunction()
- {
- //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
- {
- DEBUG_INFO_MSG("ftp : update start. \n");
- KillTask();
- if (CheckUpdateProcess() == PASS)
- DEBUG_INFO_MSG("ftp : update complete. \n");
- else
- DEBUG_INFO_MSG("ftp : update fail. \n");
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(5);
- system("reboot -f");
- }
- else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
- {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
- {
- DEBUG_INFO_MSG("Backend : update start. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- KillTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_UPDATE);
- }
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
- {
- ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
- }
- if (CheckUpdateProcess() == PASS)
- {
- DEBUG_INFO_MSG("Backend : update complete. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- }
- else
- {
- DEBUG_INFO_MSG("Backend : update fail. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- }
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
- //===============================================
- // Check reservation date is expired
- //===============================================
- int isReservationExpired(unsigned char gun_index)
- {
- int result = NO;
- struct tm expiredDate;
- struct timeb expiredTime;
- if (sscanf((char*) ShmOCPP16Data->ReserveNow[gun_index].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()
- {
- if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
- {
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
- }
- if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES)
- {
- bool canReset = true;
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
- {
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus != S_IDLE &&
- chargingInfo[_index]->SystemStatus != S_RESERVATION &&
- chargingInfo[_index]->SystemStatus != S_MAINTAIN)
- {
- canReset = false;
- if (chargingInfo[_index]->SystemStatus >= S_REASSIGN && chargingInfo[_index]->SystemStatus < S_TERMINATING)
- {
- ChargingTerminalProcess(_index);
- }
- }
- }
- }
- if (canReset)
- {
- ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("reboot -f");
- }
- else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
- {
- DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
- ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
- sleep(3);
- system("killall OcppBackend &");
- KillTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- void OcppStartTransation(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- else
- strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
- }
- void OcppStopTransation(byte gunIndex)
- {
- byte _OcppGunIndex = gunIndex;
- // 如果有 AC 槍,而現在是 DC 第二把槍進入充電
- if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
- _OcppGunIndex = 2;
- if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- else
- strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
- PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
- ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
- }
- bool OcppRemoteStop(byte gunIndex)
- {
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.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;
- }
- void OcppRemoteStartChk()
- {
- if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
- {}
- else if(!isDetectPlugin())
- {
- // 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
- byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
- for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++)
- {
- if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES)
- {
- if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
- ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION)
- {
- ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
- ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- //ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
- ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- return;
- }
- ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
- }
- }
- byte threeGunIndex = 0;
- byte dcIndex = 0;
- bool isGunUsingStatus = false;
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- // 如果有 AC 槍,且 DC 槍也有兩把
- if (acDirIndex == 1 && _index == 1)
- threeGunIndex = 1;
- if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES)
- dcIndex = _index;
- if (chargingInfo[_index]->SystemStatus != S_IDLE)
- {
- isGunUsingStatus = true;
- }
- }
- // 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
- if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
- {
- if (dcIndex == 0)
- threeGunIndex = 0;
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- return;
- }
- if (dcIndex == 0)
- threeGunIndex = 0;
- if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES)
- {
- if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
- chargingInfo[dcIndex]->SystemStatus == S_RESERVATION)
- {
- chargingInfo[dcIndex]->RemoteStartFlag = YES;
- ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
- //ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- DetectPluginStart();
- }
- ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
- }
- }
- }
- void ChkOcppStatus(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
- if (isReservationExpired(gunIndex))
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
- chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
- }
- if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
- if (isReservationExpired(gunIndex))
- {
- PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
- chargingInfo[gunIndex]->ReservationId = 0;
- chargingInfo[gunIndex]->SystemStatus = S_IDLE;
- }
- ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
- }
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
- {
- PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
- ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
- if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, true);
- chargingInfo[gunIndex]->IsAvailable = YES;
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- setChargerMode(gunIndex, MODE_IDLE);
- }
- else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL)
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, false);
- chargingInfo[gunIndex]->IsAvailable = NO;
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES)
- {
- ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
- if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
- chargingInfo[gunIndex]->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(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
- result = true;
- }
- }
- return result;
- }
- bool CheckBackendChargingEnergy(byte gunIndex)
- {
- bool result = false;
- if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
- {
- if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
- result = true;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
- {
- // 隨插即充電的要看 offline
- if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
- {
- if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
- result = true;
- }
- }
- return result;
- }
- void InformOcppErrOccur(byte 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 (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, _error);
- }
- }
- //===============================================
- // SQLite3 related routine
- //===============================================
- int DB_Open(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char* createRecordSql="CREATE TABLE IF NOT EXISTS charging_record("
- "idx integer primary key AUTOINCREMENT, "
- "reservationId text, "
- "transactionId text, "
- "startMethod text, "
- "userId text, "
- "dateTimeStart text, "
- "dateTimeStop text,"
- "socStart text, "
- "socStop text, "
- "chargeEnergy text, "
- "stopReason text"
- ");";
- char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`IsAvailable` TEXT NOT NULL, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
- char* createrecordSql="CREATE TABLE IF NOT EXISTS `event_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`occurDatetime` TEXT NOT NULL, "
- "`statusCode` INTEGER NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully.\r\n");
- if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local charging record table successfully\n");
- }
- if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local config table successfully\n");
- }
- if (sqlite3_exec(db, createrecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Create local record table error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Opened local record table successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Record(sqlite3 *db, int gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
- "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
- chargingInfo[gun_index]->ReservationId,
- ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
- chargingInfo[gun_index]->StartMethod,
- chargingInfo[gun_index]->StartUserId,
- chargingInfo[gun_index]->StartDateTime,
- chargingInfo[gun_index]->StopDateTime,
- chargingInfo[gun_index]->EvBatteryStartSoc,
- chargingInfo[gun_index]->EvBatterySoc,
- chargingInfo[gun_index]->PresentChargedEnergy,
- ShmOCPP16Data->StopTransaction[gun_index].StopReason);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully.\n");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "Insert local charging record successfully\n");
- }
- sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "delete local charging error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC( "delete local charging record successfully\n");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
- {
- uint8_t result = false;
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local charging record database open successfully (%d).\r\n", IsAvailable);
- sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- PRINTF_FUNC( "update config error message: %s\n", errMsg);
- }
- else
- {
- PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
- {
- uint8_t result = true;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
- //DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- PRINTF_FUNC( "Local config query database open successfully.\r\n");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if(rows>0)
- {
- for(int idxRow=1;idxRow<=rows;idxRow++)
- {
- if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
- {
- result = false;
- }
- PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow*cols)+3]);
- }
- }
- else
- {
- PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- //===============================================
- // Config process
- //===============================================
- void AddPlugInTimes(byte gunIndex)
- {
- if (chargingInfo[gunIndex]->Type == _Type_Chademo)
- ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
- ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
- else if(chargingInfo[gunIndex]->Type == _Type_GB)
- ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
- }
- void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
- {
- char cmdBuf[32];
- struct timeb csuTime;
- struct tm *tmCSU;
- 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 *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
- else
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
- }
- void zipLogFiles()
- {
- const char* logPath = "/Storage/SystemLog";
- // 獲取目錄
- DIR* pDir = opendir(logPath);
- if (pDir != NULL)
- {
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- // PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
- // tmCSU->tm_sec);
- // Read items inside the folder
- struct dirent* pEntry = NULL;
- while ((pEntry = readdir(pDir)) != NULL)
- {
- if (strcmp(pEntry->d_name, ".") != 0 &&
- strcmp(pEntry->d_name, "..") != 0 &&
- strncmp(pEntry->d_name, "[", 1) == 0 &&
- strstr(pEntry->d_name, "tar") < 0)
- {
- char yearC[5];
- unsigned short year = 0;
- char monthC[3];
- unsigned short month = 0;
- yearC[4] = '\0';
- strncpy(yearC, pEntry->d_name + 1, 4);
- monthC[2] = '\0';
- strncpy(monthC, pEntry->d_name + 6, 2);
- year = atoi(yearC);
- month = atoi(monthC);
- if (year != 0)
- {
- if (year < tmCSU->tm_year + 1900 ||
- (year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
- {
- DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
- char file[256];
- memset(file, 0x00, sizeof(file));
- strcat(file, "tar zcvf ");
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- strcat(file, ".tar");
- strncat(file, " ", 1);
- strcat(file, logPath);
- strncat(file, "/", 1);
- strcat(file, pEntry->d_name);
- PRINTF_FUNC("zip = %s \n", file);
- system(file);
- }
- }
- }
- }
- }
- // Close folder
- closedir(pDir);
- }
- void ChangeGunSelectByIndex(byte sel)
- {
- ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
- ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
- }
- void CheckIsAlternatvieByModelName()
- {
- // 黑白機 ?
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UD1PH") == EQUAL ||
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ED1PH") == EQUAL)
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
- else
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
- }
- void StopProcessingLoop()
- {
- for (;;)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- sleep(1);
- }
- }
- void CreateWatchdog()
- {
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
- {
- wtdFd = InitWatchDog();
- if (wtdFd < 0)
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- }
- bool IsConnectorWholeIdle()
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if (chargingInfo[count]->SystemStatus != S_IDLE &&
- chargingInfo[count]->SystemStatus != S_RESERVATION)
- {
- result = false;
- break;
- }
- }
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
- {
- if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
- ac_chargingInfo[count]->IsErrorOccur == NO)
- {
- result = false;
- break;
- }
- }
- return result;
- }
- void ClearAlarmCodeWhenAcOff()
- {
- if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
- }
- }
- //==========================================
- // Check task processing
- //==========================================
- void CheckTask()
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- if(system("pidof -s Module_4g > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_4g not running, restart it.\r\n");
- system("/root/Module_4g &");
- }
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- if(system("pidof -s Module_Wifi > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_Wifi not running, restart it.\r\n");
- system("/root/Module_Wifi &");
- }
- }
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("OcppBackend not running, restart it.\r\n");
- system("/root/OcppBackend &");
- }
- }
- if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
- {
- DEBUG_ERROR_MSG("Module_ProduceUtils not running, restart it.\r\n");
- system ("/root/Module_ProduceUtils &");
- }
- }
- void InitialDHCP()
- {
- char tmpbuf[256];
- memset(tmpbuf,0,256);
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
- system(tmpbuf);
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- int GetStartScheduleTime(unsigned char *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(byte _index)
- {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO)
- {
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO)
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
- }
- else
- {
- // Get Charging Profile
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL)
- {
- int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
- byte _startCount = NO_DEFINE;
- byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
- for (byte _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;
- }
- }
- }
- PRINTF_FUNC("_startCount = %d \n", _startCount);
- if (_startCount < _maxCount)
- {
- PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
- chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
- //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
- // if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
- // {
- // chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
- // }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
- PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
- }
- //
- // printf("-------------Schedule------------\n");
- // printf("index = %d \n", _index);
- // printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
- // printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
- // printf("----------SchedulePeriod---------\n");
- // for (int v = 0; v < 10; v++)
- // {
- // printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
- // printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
- // }
- // printf("---------------------------------\n");
- }
- }
- void CheckReturnToChargingConn()
- {
- if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
- ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
- {
- bool isReturnTimeout = false;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- // 如果選的 DC 槍在充電~ 則 DC 槍不改變
- if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- isReturnTimeout = false;
- break;
- }
- }
- else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- // AC 槍
- if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
- {
- // 沒有選中 AC,且 AC 在充電中
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
- (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE))
- {
- // 當前 DC 充電槍在 idle 狀態
- if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
- chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION)
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
- ((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
- (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1)))
- {
- // 當前 DC 充電槍在 idle 狀態
- if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
- ac_chargingInfo[0]->SystemStatus == S_RESERVATION)
- {
- isReturnTimeout = true;
- StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
- }
- }
- }
- if (!isReturnTimeout)
- StopSystemTimeoutDet();
- }
- }
- bool GetStartChargingByAlterMode(byte _gun)
- {
- bool result = true;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
- ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
- {
- for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++)
- {
- if (_select != _gun)
- {
- if (chargingInfo[_select]->SystemStatus != S_IDLE &&
- chargingInfo[_select]->SystemStatus != S_RESERVATION)
- {
- result = false;
- break;
- }
- }
- }
- }
- return result;
- }
- int main(void)
- {
- if(CreateShareMemory() == 0)
- {
- #ifdef SystemLogMessage
- DEBUG_ERROR_MSG("CreatShareMemory NG \n");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- if (!InitialSystemDefaultConfig())
- {
- DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
- StopProcessingLoop();
- }
- PRINTF_FUNC("SW Version = %s \n", fwVersion);
- PRINTF_FUNC("Chademo = %d, CCS = %d, GB = %d, AC = %d \n",
- CHAdeMO_QUANTITY, CCS_QUANTITY, GB_QUANTITY, AC_QUANTITY);
- PRINTF_FUNC("CheckConnectorTypeStatus. \n");
- CheckGunTypeFromHw();
- PRINTF_FUNC("CheckIsAlternatvie, ModelName = %s\n", ShmSysConfigAndInfo->SysConfig.ModelName);
- CheckIsAlternatvieByModelName();
- PRINTF_FUNC("InitialShareMemoryInfo \n");
- InitialShareMemoryInfo();
- PRINTF_FUNC("ChargerType (IEC or UL) = %d \n", ShmSysConfigAndInfo->SysInfo.ChargerType);
- ChangeLcmByIndex(_LCM_INIT);
- if (!CheckConnectorTypeStatus())
- isModelNameMatch = false;
- Initialization();
- PRINTF_FUNC("Spawn all Task. \n");
- SpawnTask();
- if (!isModelNameMatch)
- {
- PRINTF_FUNC("Module Name & HW info none match. \n");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- ChangeLcmByIndex(_LCM_FIX);
- // Module Name 與硬體對應不正確
- DEBUG_ERROR_MSG("Module Name & HW info none match. \n");
- sleep(3);
- KillTask();
- StopProcessingLoop();
- }
- PRINTF_FUNC("Module Name & HW info correct. Initialize.......\n");
- CreateTimeoutFork();
- PRINTF_FUNC("Self test. \n");
- SelfTestRun();
- StopSystemTimeoutDet();
- PRINTF_FUNC("SelfTestSeq = %d, Work_Step = %d \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq, ShmPsuData->Work_Step);
- if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
- ShmPsuData->Work_Step == _NO_WORKING ||
- ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
- {
- if (!DisplaySelfTestFailReason())
- {
- PRINTF_FUNC("Soft reboot for retry self-tets. \n");
- sleep(3);
- system("killall OcppBackend &");
- KillTask();
- system("/usr/bin/run_evse_restart.sh");
- StopProcessingLoop();
- }
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_ALARM);
- }
- ChangeLcmByIndex(_LCM_FIX);
- sleep(3);
- KillTask();
- StopProcessingLoop();
- }
- else
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- // Local DB
- if(DB_Open(localDb) != PASS)
- {
- PRINTF_FUNC("DB_Open fail. \n");
- isDb_ready = false;
- }
- else
- {
- isDb_ready = true;
- for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
- {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- }
- }
- ChangeLcmByIndex(_LCM_IDLE);
- sleep(1);
- //***** 須新增的偵測 *****//
- // 1. Thernal - 控制風扇轉速
- // 2. ouput fuse - 控制風扇轉速
- CreateRfidFork();
- // Create Watchdog
- //CreateWatchdog();
- // Main loop
- PRINTF_FUNC("****************************Main Loop********************************** \n");
- gettimeofday(&_cmdMainPriority_time, NULL);
- for (;;)
- {
- CheckOcppStatus();
- ChkPrimaryStatus();
- if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
- ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- // OCPP 邏輯
- OcppRemoteStartChk();
- // 讀卡邏輯
- ScannerCardProcess();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- ClearAlarmCodeWhenAcOff();
- // 確認是否要回到充電中的槍畫面邏輯判斷
- CheckReturnToChargingConn();
- if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
- {
- CheckTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if (chargingInfo[_index]->SystemStatus == S_CHARGING)
- CheckSmartChargeProfile(_index);
- }
- gettimeofday(&_cmdMainPriority_time, NULL);
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- CheckGpioInStatus();
- CheckErrorOccurStatus(gun_index);
- ChkOcppStatus(gun_index);
- //PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
- switch(chargingInfo[gun_index]->SystemStatus)
- {
- case S_IDLE:
- case S_RESERVATION:
- case S_MAINTAIN:
- case S_ALARM:
- {
- if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
- isModeChange(gun_index))
- {
- PRINTF_FUNC("S_IDLE================================== %x \n", gun_index);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- chargingInfo[gun_index]->RemainChargingDuration = 0;
- strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
- isModeChange(gun_index))
- {
- PRINTF_FUNC("S_RESERVATION....................%x \n", gun_index);
- ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
- }
- if (chargingInfo[gun_index]->IsAvailable == NO)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
- }
- ClearDetectPluginFlag();
- setChargerMode(gun_index, MODE_ALARM);
- }
- else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
- {/* 不給充電 */
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX)
- {
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++)
- setChargerMode(g_index, MODE_IDLE);
- }
- if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
- {
- if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
- {
- // 均充 -> 最大充
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
- {
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
- {
- PRINTF_FUNC("=============Smart Charging============= Step 11 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
- {
- PRINTF_FUNC("=============Smart Charging============= Step 14 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- }
- else
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- { // Idle 正常程序起點
- // 判斷是否有啟用檢查插槍
- if(isDetectPlugin())
- {
- // 卡號驗證成功後,等待充電槍插入充電車
- if (chargingInfo[gun_index]->RemoteStartFlag == YES)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
- chargingInfo[gun_index]->IsAvailable)
- {
- PRINTF_FUNC("-----------------1----------------- %d \n", gun_index);
- chargingInfo[gun_index]->RemoteStartFlag = NO;
- chargingInfo[gun_index]->isRemoteStart = YES;
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
- ClearDetectPluginFlag();
- continue;
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
- {
- if (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- PRINTF_FUNC("-----------------2----------------- \n");
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
- PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
- strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- // 當前操作的槍號,進入 Preparing
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- if (!isCardScan)
- {
- // LCM => Waiting for plugging
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
- }
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION)
- {
- if (!isReservationExpired(gun_index))
- {
- chargingInfo[gun_index]->SystemStatus = S_IDLE;
- }
- }
- else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
- (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
- {
- PRINTF_FUNC("-----------------3----------------- \n");
- bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
- if (isCanStartChargingFlag)
- {
- ChangeGunSelectByIndex(gun_index);
- AddPlugInTimes(gun_index);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- ClearDetectPluginFlag();
- continue;
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
- }
- } // Idle 正常程序終點
- }
- ReleaseAlarmCode(gun_index);
- }
- break;
- case S_REASSIGN_CHECK:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("S_REASSIGN_CHECK================================== %x \n", gun_index);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- StopSystemTimeoutDet();
- }
- bool isRessign = false;
- if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
- {
- if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
- {
- for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
- {
- // 有其他槍已經分配好 psu 模塊
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
- chargingInfo[index]->SystemStatus >= S_PREPARNING &&
- chargingInfo[index]->SystemStatus != S_MAINTAIN)
- {
- PRINTF_FUNC("=============Smart Charging============= Step 1 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
- isRessign = true;
- break;
- }
- }
- }
- else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
- {
- // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
- if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
- {
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
- {
- PRINTF_FUNC("=============Smart Charging============= Step 14 \n");
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
- {
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- continue;
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- continue;
- }
- }
- if (isRessign)
- setChargerMode(gun_index, MODE_REASSIGN);
- else
- setChargerMode(gun_index, MODE_PRECHARGE);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- break;
- case S_REASSIGN:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
- gettimeofday(&_toAverage_time, NULL);
- }
- // 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
- // 此狀態下~ 控制權在於 PSU 及 EV小板 Process
- if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
- ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
- {
- if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging)
- setChargerMode(gun_index, MODE_PRECHARGE);
- else
- setChargerMode(gun_index, MODE_IDLE);
- }
- else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
- ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
- {
- PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
- ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
- ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
- }
- //PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- break;
- case S_PREPARNING:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- }
- if (ShmPsuData->SystemPresentPsuQuantity > 0 && ShmPsuData->SystemAvailablePower > 10 &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES || OcppRemoteStop(gun_index) == YES)
- {
- // 板端或後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- break;
- case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("S_PREPARING_FOR_EV================================== %x \n", gun_index);
- //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- // 檢查車端的槍鎖是否為鎖上
- if (isEvGunLocked_chademo(gun_index) == YES)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- // 檢查車端的 charging enable 是否為 1
- if (isEvGunLocked_gb(gun_index) == YES)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- // 檢查車端的 charging enable 是否為 1
- if (isEvGunLocked_ccs(gun_index) == YES)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES ||
- OcppRemoteStop(gun_index) == YES)
- {
- // 板端或後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Pre-charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- break;
- case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- // 檢查樁端的 GFD 結果
- if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8)
- {
- // 當前操作的槍號,進入 Charging
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012296");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- // 檢查樁端的 GFD 結果
- if (isPrechargeStatus_gb(gun_index) > 9)
- {
- setChargerMode(gun_index, MODE_CHARGING);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012298");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- // 檢查樁端的 GFD 結果
- if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
- chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING))
- {
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012297");
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES ||
- OcppRemoteStop(gun_index) == YES)
- {
- // 板端或後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Pre-charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
- }
- break;
- case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("S_CHARGING================================== %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- ftime(&startChargingTime[gun_index]);
- ChangeStartOrStopDateTime(YES, gun_index);
- OcppStartTransation(gun_index);
- }
- if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf)
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
- ftime(&endChargingTime[gun_index]);
- chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
- (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
- {
- // UVP
- RecordAlarmCode(gun_index, "012289");
- ChargingTerminalProcess(gun_index);
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012296");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- else if (isPrechargeStatus_gb(gun_index) == 10 &&
- (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
- (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)))
- {
- // UVP
- RecordAlarmCode(gun_index, "012290");
- ChargingTerminalProcess(gun_index);
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012298");
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
- (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
- {
- // UVP
- RecordAlarmCode(gun_index, "012288");
- ChargingTerminalProcess(gun_index);
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012297");
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) ||
- OcppRemoteStop(gun_index) ||
- CheckBackendChargingTimeout(gun_index) ||
- CheckBackendChargingEnergy(gun_index) ||
- strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
- {
- PRINTF_FUNC("S_CHARGING=======Stop=========================== %f \n", (chargingInfo[gun_index]->EvBatterytargetVoltage * 10));
- // 板端或後臺要求停止
- ChargingTerminalProcess(gun_index);
- }
- // LCM => Charging
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
- }
- break;
- case S_TERMINATING:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC ("terminating......................... %x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- }
- if (chargingInfo[gun_index]->Type == _Type_Chademo)
- {
- // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
- if (isEvStopCharging_chademo(gun_index) == YES)
- {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
- }
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012234");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012296");
- }
- if (isEvStopCharging_chademo(gun_index) == YES ||
- isPrechargeStatus_chademo(gun_index) <= 0)
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_GB)
- {
- PRINTF_FUNC("************ GB lock Status = %d, status = %d \n", isEvStopCharging_gb(gun_index), isPrechargeStatus_gb(gun_index));
- // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
- if (isEvStopCharging_chademo(gun_index) == YES)
- {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
- }
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012236");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012298");
- }
- if (isEvStopCharging_gb(gun_index) == YES ||
- isPrechargeStatus_gb(gun_index) <= 0)
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
- {
- // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
- if (isEvStopCharging_chademo(gun_index) == YES)
- {
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
- }
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
- {
- // GFD 警告
- RecordWarningCode(gun_index, "012297");
- }
- if (isEvStopCharging_ccs(gun_index) == YES &&
- (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
- isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14))
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- // 車端的停止
- if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- }
- break;
- case S_COMPLETE:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC ("complete......................... %x \n", gun_index);
- if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
- {
- OcppStopTransation(gun_index);
- }
- ftime(&endChargingTime[gun_index]);
- if (chargingInfo[gun_index]->PresentChargedDuration != 0)
- chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
- chargingInfo[gun_index]->isRemoteStart = NO;
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
- ChangeStartOrStopDateTime(NO, gun_index);
- DB_Insert_Record(localDb, gun_index);
- }
- if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
- GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
- ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
- StopGunInfoTimeoutDet(gun_index);
- StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止
- ChargingTerminalProcess(gun_index);
- }
- // 等待 EV 小板 (CCS) 通知可以開始 Precharge
- // 切換 D+ Relay to Precharge Relay
- if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
- {
- if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
- //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
- {
- PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- }
- }
- else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
- {
- setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
- }
- break;
- }
- case S_CCS_PRECHARGE_ST1:
- {
- if (isModeChange(gun_index))
- {
- PRINTF_FUNC("CCS Precharge Processing 2....................%x \n", gun_index);
- }
- if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
- {
- // GFD 錯誤停止
- RecordAlarmCode(gun_index, "012235");
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端要求停止
- ChargingTerminalProcess(gun_index);
- }
- // 等待小板通知進入充電
- // 切換 D+ Relay to Precharge Relay
- if (chargingInfo[gun_index]->RelayK1K2Status == YES)
- {
- chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
- setChargerMode(gun_index, MODE_CHARGING);
- }
- break;
- }
- }
- }
- if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
- {
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
- }
- else
- {
- bool dcPageRun = false;
- if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
- {
- if (ac_chargingInfo[0]->SystemStatus == S_IDLE)
- ChangeLcmByIndex(_LCM_IDLE);
- else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING)
- ChangeLcmByIndex(_LCM_PRE_CHARGE);
- else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
- ChangeLcmByIndex(_LCM_CHARGING);
- else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
- ac_chargingInfo[0]->SystemStatus == S_COMPLETE)
- ChangeLcmByIndex(_LCM_COMPLETE);
- else
- dcPageRun = true;
- }
- else
- dcPageRun = true;
- if (dcPageRun)
- ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
- }
- write(wtdFd, "a", 1);
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|