123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287 |
- /*
- * main.c
- *
- * Created on: 2020年9月10日
- * Author: Wendell
- */
- #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"
- #include "Module_EvComm.h"
- #include "Module_CabinetParallel.h"
- #include "Common.h"
- #define BTN_RELEASE 0
- #define BTN_PRESS 1
- #define MAX_BUF 64
- #define MtdBlockSize 0x300000
- #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 UPGRADE_DORC1 0x07
- #define UPGRADE_DORC2 0x08
- #define UPGRADE_DDRB 0x09
- #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 MAIN_PRIORITY_INTERVAL 5
- #define CABINET_ROLE_TIMEOUT 3 // unit: 1s
- #define GUN_PREPARE_TIMEOUT 30
- #define GUN_EV_WAIT_TIMEOUT (120 + 10)
- #define GUN_EVSE_WAIT_TIMEOUT (60 + 10)
- #define GUN_COMP_WAIT_TIMEOUT 10
- #define GUN_PRECHARGING_TIMEOUT 60
- #define REBOOT_TIMEOUT 10
- #define RESET_TIMEOUT 10
- #define OCPP_COST_REQ_INTERVAL 1
- #define DISPENSER_RECONNECTE_TIME 30
- #define DISPENSER_AUTH_COMP_TIME 3
- #define FORCE_BALANCE_TIME 5
- #define DISPENSER_UPGRADE_TIME 600
- #define AC_CONTACTOR_REOPEN_TIME 60
- #define PSU_FAILURE_RESUME_TIME 180
- #define MAX_AC_CONTACTOR_COUNT 3
- #define STANDBY_TIME 600
- #define FAST_STANDBY_TIME 10
- #define E4U_STANDBY_TIME 1800
- #define WIRING_INFO_DELAY 30
- #define WAIT_REASSIGN_TIME 40 // unit: second
- #define MAX_REQUEST_CHARGING_TIME 15 // unit: second
- #define MIN_WAIT_PREPARNING_TIME 1 // unit: second
- #define FORCE_CHARGING_CMD_DELAY 3 // unit: second
- #define FORCE_CHARGING_WAIT_EVSE 10 // unit: second
- #define TRY_RESET_4G_WIFI_TIME 300 // unit: second
- #define FAST_RESET_4G_WIFI_TIME 60 // unit: second
- #define ENERAGY_INTERVAL 1 // unit: second
- #define FAULT_RELEASE_TIME 2 // unit: second
- #define MAINTAIN_RECOVERY_TIME 1 // unit: second
- #define PARALLEL_WAIT_TIME 3 // unit: second
- #define START_UPGRADE_TIME 60 // unit: second
- #define PCABINET_UPGRADE_TIME 300 // unit: second
- #define MCABINET_UPGRADE_TIME 60 // unit: second
- #define CONNECTION_TIME_OFFSET 5 // unit: second
- #define PLUG_IN_HOLD_TIME 1 // unit: second
- #define FINAL_COST_TIMEOUT 3 // unit: second
- #define FINAL_COST_UPDATE_TIME 10 // unit: second
- #define MAX_FINAL_COST_MISC_COUNT 3
- #define PARKING_STATUS_TIMEOUT 3 // unit: second
- #define OCCUPANCY_FEE_TIMEOUT 10 // unit: second
- #define MIN_AVAILABLE_MEMORY 200 // unit: MB
- #define AUTO_START_CHARGING "AutoStartCharging"
- #define CONTACTOR_AUTO_ON_OFF 0
- #define CONTACTOR_AUTO_ON_TIME 60
- #define CONTACTOR_AUTO_OFF_TIME 300
- #define WAIT_DISPENSER_STOP_TIMEOUT 3 // unit: second
- #define STARTTRANSATION_TIME 1
- #define STOP_TARTTRANSATION_DELAY 2
- #define WAIT_DIAGNOSTICS_CONFIRM 10 // unit: second
- #define WAIT_DIAGNOSTICS_TIMEOUT 120 // unit: second
- 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 _UpgradeNeedReboot = FALSE;
- bool _isBridgeModeConfig = false;
- #define GUN_DERATING_COUNT 2
- const int GunDeratingTemp[GUN_DERATING_COUNT] = {80, 85};
- const byte Group_to_Location_2_Gun[GENERAL_GUN_QUANTITY] = {0, 1, 0, 0};
- const byte Location_to_Group_2_Gun[GENERAL_GUN_QUANTITY] = {0, 1, 0, 0};
- const byte GroupParallelRelay_2_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 1, 0, 0},
- {1, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0}
- };
- //Location: 1 2 3 4
- // Gun: 1 3 4 2
- //Parallel: 1 2 3
- //const byte Group_to_Location_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 1, 2};
- //const byte Location_to_Group_4_Gun[GENERAL_GUN_QUANTITY] = {0, 2, 3, 1};
- //const byte GroupParallelRelay_4_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- //{
- // {0, 3, 1, 2}, // group 0
- // {1, 0, 2, 3}, // group 1
- // {1, 3, 0, 2}, // group 2
- // {1, 3, 2, 0} // group 3
- //};
- //Location: 1 2 3 4
- // Gun: 1 4 3 2
- //Parallel: 1 2 3
- const byte Group_to_Location_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 2, 1};
- const byte Location_to_Group_4_Gun[GENERAL_GUN_QUANTITY] = {0, 3, 2, 1};
- const byte GroupParallelRelay_4_Gun[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 3, 2, 1}, // group 0
- {1, 0, 3, 2}, // group 1
- {1, 3, 0, 2}, // group 2
- {1, 3, 2, 0} // group 3
- };
- const byte GroupParallelRelay_4_Gun_6Parallel[GENERAL_GUN_QUANTITY][GENERAL_GUN_QUANTITY] =
- {
- {0, 4, 6, 1}, // group 0
- {4, 0, 3, 5}, // group 1
- {6, 3, 0, 2}, // group 2
- {1, 5, 2, 0} // group 3
- };
- 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 ChargingAlarmProcess(byte gunIndex);
- void InformOcppErrOccur(byte codeType);
- void SetOcppErrorCode(unsigned char _index, char *errCode);
- void SetOcppVendorErrorCode(unsigned char _index, char *vendorCode);
- 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 DB_Update_LocalConsumption(sqlite3 *db, uint8_t gun_index, float value);
- void DB_Update_GunConsumption(sqlite3 *db, uint8_t gun_index, float value);
- float DB_Get_LocalConsumption(sqlite3 *db, uint8_t gun_index);
- float DB_Get_GunConsumption(sqlite3 *db, uint8_t gun_index);
- float Get_PowerConsumption(uint8_t gun_index);
- void Update_PowerConsumption(uint8_t gun_index);
- int DB_Insert_FinalCost(sqlite3 *db, uint8_t gun_index, int txId, char *description);
- int DB_Update_FinalCost_Status(sqlite3 *db, int txId, int status);
- int DB_Get_Undisposed_FinalCost(sqlite3 *db, int gunIndex, char *costString);
- int DB_Reboot_Record(sqlite3 *db);
- int DB_Insert_Ocmf(sqlite3 *db, int gun_index, char *txId, char *ocmfKey, char *ocmfInfo);
- int DB_Update_Ocmf_Status(sqlite3 *db, char *txId, int status);
- int DB_Get_Undisposed_Ocmf(sqlite3 *db, int *gunIndex, char *txId, char *ocmfKey, char *ocmfInfo);
- void InitialDHCP();
- void InitialDispenserDhcpServerConfig(void);
- void StartDispenserDhcpServer(void);
- int GetStartScheduleTime(unsigned char *time);
- void CheckConnectionTimeout(void);
- bool IsParallelCabinetIdle(void);
- bool IsStandbyEnable(void);
- bool IsGunIdle(int gunIndex, int idleType);
- bool IsDispenserIdle(int dispenserIndex);
- bool IsConnectorWholeIdle(void);
- void SetAcContactor(unsigned char OnOff);
- void UpdateErrorCodeToOcpp(byte index);
- bool CheckConnectorTypeStatus(void);
- void CreateWatchdog(void);
- void TryCloseWatchdog(void);
- void TryFeedWatchdog(void);
- bool IsReadyParalleling(void);
- void SetParallelingStart(void);
- void SetParallelingDone(void);
- void SetPCabinetOutputRelay(unsigned char index, unsigned char OnOff);
- void SetParallelCabinetAcContactor(unsigned char OnOff);
- unsigned short GetTotalParallelCabinetPower(void);
- void MCabinetParallelingProcess(void);
- void SCabinetControllProcess(void);
- bool Is_WebServer_Alive(void);
- void Run_WebServer_Service(void);
- bool Get_Ocpp_ConnectionStatus(void);
- void Run_Ocpp_Service(void);
- bool Is_Ocpp_Task_Alive(void);
- void Kill_Ocpp_Service(void);
- void Run_MaintainOcpp_Service(void);
- bool Is_MaintainOcpp_Task_Alive(void);
- void Kill_MaintainOcpp_Service(void);
- long int Get_Ocpp_procDogTime(void);
- void Clean_Ocpp_procDogTime(void);
- bool Is_Ocpp_BootNotification(void);
- void Clean_Ocpp_BootNotification(void);
- bool Is_Ocpp_ResetReq(void);
- bool Chk_Ocpp_Reset_Type(char *type);
- void Clean_Ocpp_ResetReq(void);
- void Set_Ocpp_AuthorizeReq(void);
- bool Is_Ocpp_AuthorizeConf(void);
- bool Is_Ocpp_Authorize_Status(char *status);
- bool Is_Ocpp_UpdateFirmwareReq(void);
- void Clean_Ocpp_UpdateFirmwareReq(void);
- bool Is_Ocpp_UpdateFirmwareStatus(char *status);
- void Set_Ocpp_UpdateFirmwareStatus(char *status);
- void Clean_Ocpp_UpdateFirmwareStatus(char *status);
- void Set_Ocpp_FirmwareStatusNotificationReq(void);
- bool Is_Ocpp_StopOnInvalidId_Enable(void);
- bool Is_Ocpp_AuthorizeRemoteTxRequests(void);
- int Get_Ocpp_ConnectionTimeOut(void);
- void Get_Ocpp_DefaultPrice(char *defaultPrice);
- void Get_Ocpp_UserPrice(char * userId, char *userPrice);
- void Clean_Ocpp_UserPrice(void);
- void Get_Ocpp_RunningCost(int gun_index, char *cost);
- void Clean_Ocpp_RunningCost(int gun_index);
- void Get_Ocpp_FinalCost(int gun_index, char *cost);
- void Clean_Ocpp_FinalCost(int gun_index);
- int Get_Ocpp_FinalCostTxId(int gun_index);
- void Get_Ocpp_TimeOffset(char *timeOffset);
- void Get_Ocpp_PreAuthAmount(char *amount);
- void Get_Ocpp_PowerSharingServerIP(char *ip);
- void Get_Ocpp_Refunding(char *Refunding);
- void Clean_Ocpp_Refunding(void);
- bool Is_Ocpp_LcdOverideReq(int *gun, int *page);
- void Clean_Ocpp_LcdOverideReq(void);
- void Get_Ocpp_ChargerStationInfo(int *station_id, char *name);
- bool Is_Ocpp_ChargerStationReq(void);
- void Clean_Ocpp_ChargerStationReq(void);
- void Get_Ocpp_WeatherInfo(int *weatherID, float *temperature);
- bool Is_Ocpp_WeatherReq(void);
- void Clean_Ocpp_WeatherReq(void);
- void Set_Ocpp_DeductTransaction(int transaction);
- void Set_Ocpp_DeductCreditNo(char *userId);
- void Set_Ocpp_DeductVemData(char *vemData);
- void Set_Ocpp_DeductAmount(double value);
- void Set_Ocpp_DeductResult(unsigned char result);
- void Set_Ocpp_DonateInvoice(unsigned char donate);
- bool Is_Ocpp_ReportCreditDeductReq(void);
- void Set_Ocpp_ReportCreditDeductReq(void);
- void Clean_Ocpp_TcciSerialNo(int gun_index);
- bool Set_Ocpp_TcciReaderStatus(int gun_index, DeductResultInfoData *ReaderStatus);
- void Clean_Ocpp_TcciCreditInfo(int gun_index);
- void Set_Ocpp_TcciReaderStatusReq(int gun_index);
- bool Is_Ocpp_TcciReaderStatusReq(int gun_index);
- void Set_Ocpp_StartTransactionIdTag(int gun_index, char *id);
- void Set_Ocpp_StartTransactionReq(int gun_index);
- bool Is_Ocpp_StartTransactionConf(int gun_index);
- void Clean_Ocpp_StartTransactionConf(int gun_index);
- bool Is_Ocpp_StartTransaction_Status(int gun_index, char *status);
- bool Is_Ocpp_StartTransaction_Accepted(int gun_index);
- void Get_Ocpp_StartTransaction_Status(int gun_index, char *status);
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId);
- bool Is_Invalid_StartTransactionId(int gun_index);
- void Set_Ocpp_StopTransactionId(int gun_index, char *id);
- void Set_Ocpp_StopTransactionReq(int gun_index);
- void Chk_Ocpp_Backup_ErrorCode(int gun_index);
- bool Is_Ocpp_ReserveNowReq(int gun_index);
- void Clean_Ocpp_ReserveNowReq(int gun_index);
- int Get_Ocpp_ReserveNowId(int gun_index);
- void Set_Ocpp_ReserveNowConf(int gun_index);
- void Get_Ocpp_ReserveNowExpiryDate(int gun_index, char *date);
- bool Is_Ocpp_ReserveNowExpired(int gun_index);
- void Get_Ocpp_ReserveNowIdTag(int gun_index, char *idTag);
- bool Is_Ocpp_ReserveNowIdTag(uint8_t gun_index, char *authIdTag);
- bool Is_Ocpp_CancelReservationReq(int gun_index);
- void Clean_Ocpp_CancelReservationReq(int gun_index);
- void Set_Ocpp_CancelReservationConf(int gun_index);
- bool Is_Ocpp_ChangeAvailabilityReq(int gun_index);
- void Clean_Ocpp_ChangeAvailabilityReq(int gun_index);
- bool Chk_Ocpp_Availability_Type(int gun_index, char *type);
- bool Is_Ocpp_UnlockConnectorReq(int gun_index);
- void Clean_Ocpp_UnlockConnectorReq(int gun_index);
- void Set_Ocpp_UnlockConnectorConf(int gun_index);
- bool Is_Ocpp_RemoteStartReq(int gun_index);
- void Clean_Ocpp_RemoteStartReq(int gun_index);
- void Get_Ocpp_RemoteStartIdTag(int gun_index, char *idTag);
- bool Is_Ocpp_RemoteStopReq(int gun_index);
- void Clean_Ocpp_RemoteStopReq(int gun_index);
- void Set_Ocpp_StopReason(int gun_index, char *reason);
- void Get_Ocpp_StopReason(int gun_index, char *reason);
- void Clean_Ocpp_StopReason(int gun_index);
- void Set_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode);
- bool Is_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode);
- void Set_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode);
- bool Is_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode);
- bool Is_Ocpp_ChargingProfileConf(int gun_index);
- void Clean_Ocpp_ChargingProfileConf(int gun_index);
- bool Is_Ocpp_ChargingProfileReq(int gun_index);
- void Set_Ocpp_ChargingProfileReq(int gun_index);
- bool Is_Ocpp_ChargingProfileKind(int gun_index, char *kind);
- bool Is_Ocpp_ChargingProfileId(int gun_index);
- int Get_Ocpp_ChargingProfileStartTime(int gun_index);
- int Get_Ocpp_ChargingProfileScheduleCount(int gun_index);
- int Get_Ocpp_ChargingProfileScheduleTime(int gun_index, int schedule_index);
- float Get_Ocpp_ChargingProfileScheduleLimit(int gun_index, int schedule_index);
- int Get_Ocpp_ChargingProfileScheduleNumberPhases(int gun_index, int schedule_index);
- int Get_Ocpp_ChargingProfileStartIndex(int gun_index);
- bool Is_Ocpp_MaxChargingProfileKind(char *kind);
- bool Is_Ocpp_MaxChargingProfileId(void);
- int Get_Ocpp_MaxProfileStartTime(void);
- int Get_Ocpp_MaxProfileScheduleCount(void);
- int Get_Ocpp_MaxProfileScheduleTime(int schedule_index);
- float Get_Ocpp_MaxProfileScheduleLimit(int schedule_index);
- int Get_Ocpp_MaxProfileScheduleNumberPhases(int schedule_index);
- int Get_Ocpp_MaxProfileStartIndex(void);
- int Is_Ocpp_RemoteStartWaitReq(void);
- void Get_Ocpp_SessionTarget(int gunIndex, struct StructSessionTarget *sessionTarget);
- int Get_Ocpp_OffLineMaxChargingPower(void);
- bool Is_Ocpp_SendOcmfDataReq(int gunIndex);
- void Set_Ocpp_SendOcmfDataReq(int gunIndex);
- void Clean_Ocpp_SendOcmfDataReq(int gunIndex);
- void Set_Ocpp_OcmfData(int gunIndex, char *key, char *ocmfInfo);
- void Set_Deduct_UserId(int gunIndex, char *userId);
- void Set_Deduct_TransactionId(int gunIndex, int transaction);
- void Clean_DeductInfo(int gunIndex);
- bool Is_DeductResultReq(int gunIndex);
- bool Is_ReaderStatusReq(int gunIndex);
- void Clean_ReaderStatusInfo(int gunIndex);
- void Set_UserTransactionId(int gunIndex, int transaction);
- void Set_UserPrice(int gunIndex, float price);
- void Set_UserTotalCost(int gunIndex, float cost);
- void Set_UserAccountBalance(int gunIndex, float balance);
- void Set_UserDiscount(int gunIndex, float discount);
- void Clean_UserTransaction(int gunIndex);
- bool Is_OccupancyDeductReq(int gunIndex);
- void Clean_OccupancyDeductReq(int gunIndex);
- bool Is_OccupancyKeepCountingReq(int gunIndex);
- void Set_OccupancyKeepCountingReq(int gunIndex);
- void Clean_OccupancyKeepCountingReq(int gunIndex);
- bool Is_OccupancyFeeForceCancelReq(int gunIndex);
- void Set_OccupancyFeeForceCancelReq(int gunIndex);
- void Clean_OccupancyFeeForceCancelReq(int gunIndex);
- bool Is_Ocpp_GetDiagnosticsReq(void);
- void Clean_Ocpp_GetDiagnosticsReq(void);
- 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[2];
- struct LedModuleData *ShmLedModuleData;
- struct OCPP16Data *ShmOCPP16Data;
- struct OCPP20Data *ShmOCPP20Data;
- struct OCPP16Data *ShmOCPP16DataPH;
- struct MeterInformation *ShmCsuMeterData;
- ChargerInfoData *ShmChargerInfo;
- PsuPositionInfoData *ShmPsuPosition;
- PsuGroupingInfoData *ShmPsuGrouping;
- struct ChargingInfoData *chargingInfo[CONNECTOR_QUANTITY];
- struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
- struct timespec _cmdMainPriority_time;
- struct timespec _cmdSubPriority_time;
- struct timespec _ConnectorAuthorizing_Time[CONNECTOR_QUANTITY];
- struct timespec _ConnectorAuthorizeFail_Time[CONNECTOR_QUANTITY];
- struct timespec _DispenserAuthorizing_Time[CONNECTOR_QUANTITY];
- struct timespec _DispenserUpgrade_time;
- struct timespec _Standby_time;
- struct timespec _SystemStatus_Time[CONNECTOR_QUANTITY];
- struct timespec _ChargedEnergy_Time[CONNECTOR_QUANTITY];
- struct timespec _Parallel_Time;
- struct timespec _RemoteStartNoId_Time;
- float gunOutputVol[CONNECTOR_QUANTITY];
- unsigned char _ocppProfileChkFlag[CONNECTOR_QUANTITY];
- float _lastProfilePower[CONNECTOR_QUANTITY];
- float _lastProfileCurrent[CONNECTOR_QUANTITY];
- float _lastMaxProfilePower;
- float _lsatGunMeterValue[CONNECTOR_QUANTITY];
- struct StructStatusNotification _BackupStatusNotification[CONNECTOR_QUANTITY];
- bool _useGunMeterValue[MAX_GUN_QUANTITY];
- bool _triggerTransaction[MAX_GUN_QUANTITY];
- bool _plugInHold[MAX_GUN_QUANTITY];
- struct timespec _PlugInHold_Time[MAX_GUN_QUANTITY];
- struct timespec _DispenserBill_Time[MAX_DISPENSER_QUANTITY];
- struct timespec _ConnectorBill_Time[MAX_GUN_QUANTITY];
- struct timespec _ParkingStatus_Time[MAX_GUN_QUANTITY];
- struct timespec _GetOccupancyFee_Time[MAX_GUN_QUANTITY];
- struct timespec _Diagnostics_Time;
- bool _canUpdateFinalCost[MAX_DISPENSER_QUANTITY];
- bool _isUndisposedFinalCost[MAX_DISPENSER_QUANTITY];
- int _notifyOccupancyFeeAct[MAX_GUN_QUANTITY];
- bool _NeedReset4gWifi;
- struct timespec _4gWifiReset_time;
- int _psuLostQuantity = 0;
- bool _isStandbyEnable = true;
- bool isModelNameMatch = true;
- bool _NeedDiagnostics = false;
- //int rfidFd = -1;
- //char* rfidPortName = "/dev/ttyS2";
- #if ENABLE_PCBA_TEST == 0
- char* fwVersion = "V2.05.00.0000.00";
- char* subVersion = "04";
- #else
- char* fwVersion = "PCBA.00.04";
- char* subVersion = "00";
- #endif
- sqlite3 *localDb;
- bool isDb_ready;
- sqlite3 *networkDb;
- //================================================
- // 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
- LOG_ERROR("Set SO_RCVTIMEO NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("Set SO_RCVBUF NG");
- #endif
- }
- nbytes=40960;
- if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("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
- LOG_ERROR("open 407 Communication port NG");
- #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;
- int timeout = 180;
- 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)
- {
- LOG_ERROR("System watch dog initial fail.\r\n");
- }
- ioctl(fd, _IOWR('W', 6, int), &timeout);
- return fd;
- }
- void setChargerMode(byte gun_index, byte mode)
- {
- chargingInfo[gun_index]->SystemStatus = mode;
- }
- long long DiffTimebWithNow(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- long long StartTime,StopTime;
- ftime(&ET);
- StartTime=(long long)ST.time;
- StopTime=(long long)ET.time;
- return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
- }
- //=================================
- // Create all share memory
- //=================================
- int CreateShareMemory()
- {
- int MeterSMId;
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG");
- #endif
- return 0;
- }
- else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG");
- #endif
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmStatusCodeData NG");
- #endif
- return 0;
- }
- else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmStatusCodeData NG");
- #endif
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
- //creat ShmPsuData
- if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmPsuData NG");
- #endif
- return 0;
- }
- else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmPsuData NG");
- #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
- LOG_ERROR("[main]CreatShareMemory:shmget ShmCHAdeMOData NG");
- #endif
- return 0;
- }
- else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmCHAdeMOData NG");
- #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
- LOG_ERROR("[main]CreatShareMemory:shmget ShmGBTData NG");
- #endif
- return 0;
- }
- else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmGBTData NG");
- #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
- LOG_ERROR("[main]CreatShareMemory:shmget ShmCcsData NG");
- #endif
- return 0;
- }
- else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmCcsData NG");
- #endif
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
- }
- */
- //creat ShmPrimaryMcuData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmPrimaryMcuData NGn");
- #endif
- return 0;
- }
- else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG");
- #endif
- return 0;
- }
- memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
- //creat ShmFanModuleData
- if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmFanModuleData NG");
- #endif
- return 0;
- }
- else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmFanModuleData NG");
- #endif
- return 0;
- }
- memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
- //creat ShmRelayModuleData
- if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmRelayModuleData[0] NG");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData[0] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmRelayModuleData[0] NG");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData[0], 0, sizeof(struct RelayModuleData));
- // DO360 RC2
- if ((MeterSMId = shmget(ShmRelay2BdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmRelayModuleData[1] NG");
- #endif
- return 0;
- }
- else if ((ShmRelayModuleData[1] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmRelayModuleData[1] NG");
- #endif
- return 0;
- }
- memset(ShmRelayModuleData[1], 0, sizeof(struct RelayModuleData));
- if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmLedModuleData NG");
- #endif
- return 0;
- }
- else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmLedModuleData NG");
- #endif
- return 0;
- }
- memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
- //creat ShmOCPP16Data
- if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ShmOCPP16Data NG");
- #endif
- return 0;
- }
- else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ShmOCPP16Data NG");
- #endif
- return 0;
- }
- memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
- {
- LOG_ERROR("[main]CreatShareMemory:shmget OCPP20Data NG");
- return 0;
- }
- else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- LOG_ERROR("[main]CreatShareMemory:shmat OCPP20Data NG");
- return 0;
- }
- memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
- //creat ShmOCPP16DataPH
- if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
- {
- LOG_ERROR("shmget ShmOCPP16DataPH NG");
- return 0;
- }
- else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- LOG_ERROR("shmat ShmOCPP16DataPH NG");
- return 0;
- }
- memset(ShmOCPP16DataPH,0,sizeof(struct OCPP16Data));
- if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmget ChargerInfoData NG");
- #endif
- return 0;
- }
- else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("[main]CreatShareMemory:shmat ChargerInfoData NG");
- #endif
- return 0;
- }
- memset(ShmChargerInfo, 0, sizeof(ChargerInfoData));
- ShmPsuPosition = &ShmChargerInfo->PsuPosition;
- ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
- return 1;
- }
- //======================================================
- // Peripheral initial
- //======================================================
- void InitGPIO()
- {
- /*****************0~3, 4 bank, bank x 32+ num*********************/
- /***************************************************************/
- /*************** GPIO 0 ***************************************/
- /***************************************************************/
- /* GPMC_AD8 => GPIO0_22 *//*ID BD1_1*/ // no use
- system("echo 22 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio22/direction");
- /* GPMC_AD9 => GPIO0_23 *//*ID BD1_2*/ // no use
- system("echo 23 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio23/direction");
- /* GPMC_AD10 => GPIO0_26 *//*IO BD1_1*/ // no use
- 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*/ // no use
- 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*/ // no use
- 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*/ // no use
- system("echo 20 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio20/direction");
- /***************************************************************/
- /*************** GPIO 1 ***************************************/
- /***************************************************************/
- /* GPMC_AD12 => GPIO1_12 *//*ID BD2_1*/ // no use
- system("echo 44 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio44/direction");
- /* GPMC_AD13 => GPIO1_13 *//*ID BD2_2*/ // no use
- system("echo 45 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio45/direction");
- /* GPMC_AD14 => GPIO1_14 *//*IO BD2_1*/ // no use
- 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*/ // no use
- 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*/ // no use
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio88/direction");
- /*LCD_VSYNC => GPIO2_22*//*CCS communication board 2 proximity*/ // no use
- 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*/ // no use
- 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*/ // no use
- 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");
- LOG_INFO("[main]InitGPIO: Initial GPIO OK");
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd, wrd;
- unsigned char *buf;
- unsigned int ChkSum, ChkSumOrg;
- if((buf = malloc(MtdBlockSize)) == NULL)
- {
- LOG_ERROR("malloc buffer NG, rebooting..\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
- //================================================
- system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock10 NG, rebooting..\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);
- LOG_ERROR("read SysConfigData data NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for(wrd = ARRAY_SIZE(ptr->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++)
- {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- memcpy(&ptr->ModelName, buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev)), ARRAY_SIZE(ptr->ModelName));
- memcpy(&ptr->SerialNumber, buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev) + ARRAY_SIZE(ptr->ModelName) + ARRAY_SIZE(ptr->AcModelName)), ARRAY_SIZE(ptr->SerialNumber));
- //================================================
- // Load configuration from mtdblock11
- //================================================
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("Primary SysConfigData checksum NG, read backup\n");
- system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock11 (backup) NG, rebooting..\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);
- LOG_ERROR("read backup SysConfigData data NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for(wrd = ARRAY_SIZE(ptr->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++)
- {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- //================================================
- // Load configuration from mtdblock12 (Factory default)
- //================================================
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("backup SysConfigData checksum NG, read Factory default\n");
- system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
- fd = open("/mnt/EvseConfig.bin", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- LOG_ERROR("open mtdblock12 (Factory default) NG, rebooting..\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);
- LOG_ERROR("read factory default SysConfigData data NG, rebooting..\n");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- ChkSum = 0;
- for(wrd = ARRAY_SIZE(ptr->CsuBootLoadFwRev); wrd < MtdBlockSize - 4; wrd++)
- {
- ChkSum += buf[wrd];
- }
- memcpy(&ChkSumOrg, buf + (MtdBlockSize - 4), sizeof(ChkSumOrg));
- memcpy(buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
- memcpy(buf + (ARRAY_SIZE(ptr->CsuBootLoadFwRev) + ARRAY_SIZE(ptr->ModelName) + ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
- if(ChkSum != ChkSumOrg)
- {
- LOG_ERROR("factory default SysConfigData checksum NG, restore factory default\n");
- free(buf);
- system("cd /root;./FactoryConfig -m");
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- return FAIL;
- }
- }
- }
- //load OK
- memcpy((struct SysConfigData *)ptr, buf, sizeof(struct SysConfigData));
- free(buf);
- system("rm -f /mnt/EvseConfig.bin");
- // SysConfig in flash is empty (0xffffffff)
- if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
- (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
- (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
- (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
- {
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
- {
- LOG_INFO("Model name over length.");
- memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
- {
- LOG_INFO("Model serial number over length.");
- memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
- }
- if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
- {
- LOG_INFO("System id over length.");
- memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
- }
- if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
- {
- LOG_INFO("Ethernet dhcp config is null.");
- }
- system("cd /root;./Module_FactoryConfig -m");
- sleep(3);
- system("/usr/bin/run_evse_restart.sh");
- }
- LOG_INFO("Load SysConfigData OK");
- return PASS;
- }
- int isEthernetCablePlugIn(int ethernet)
- {
- int fd, PlugInStatus = 0;
- char ch[2];
- char buffer[64];
- snprintf(buffer, sizeof(buffer), "/sys/class/net/eth%d/carrier", ethernet);
- fd = open(buffer, O_RDONLY);
- if(fd < 0)
- {
- return -1;
- }
- if(read(fd, ch, 1) < 0)
- {
- return -1;
- }
- PlugInStatus = atoi(ch);
- close(fd);
- return PlugInStatus;
- }
- 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(tmp)-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;
- }
- int isUap0up(void)
- {
- int result = FAIL;
- FILE *fp;
- char cmd[256];
- char buf[512];
- strcpy(cmd, "ifconfig uap0");;
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- if(strstr(buf, "uap0") > 0)
- {
- result = PASS;
- }
- }
- }
- pclose(fp);
- return result;
- }
- void InitialApModeDhcpServerConfig(void)
- {
- system("echo 'start 192.168.10.100' > /etc/udhcpd.conf");
- system("echo 'end 192.168.10.150' >> /etc/udhcpd.conf");
- system("echo 'interface uap0' >> /etc/udhcpd.conf");
- system("echo 'lease_file /var/log/udhcpd.leases'>> /etc/udhcpd.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd.conf");
- system("echo 'opt router 192.168.10.10' >> /etc/udhcpd.conf");
- system("echo 'option domain local' >> /etc/udhcpd.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd.conf");
- usleep(1000);
- }
- void InitialBridgeModeDhcpServerConfig(void)
- {
- system("echo 'start 192.168.10.100' > /etc/udhcpd.conf");
- system("echo 'end 192.168.10.150' >> /etc/udhcpd.conf");
- system("echo 'interface br0' >> /etc/udhcpd.conf");
- system("echo 'lease_file /var/log/udhcpd.leases'>> /etc/udhcpd.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd.conf");
- system("echo 'opt router 192.168.10.10' >> /etc/udhcpd.conf");
- system("echo 'option domain local' >> /etc/udhcpd.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd.conf");
- usleep(1000);
- }
- bool Is_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- return (ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue & misc_cmd) > 0 ? true : false;
- }
- void Set_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue |= misc_cmd;
- }
- void Clean_Dispenser_MiscCommand(int dispenser, int misc_cmd)
- {
- ShmChargerInfo->DispenserMiscReq[dispenser].CtrlValue &= ~misc_cmd;
- }
- bool Is_Connector_MiscCommand(int connector, int misc_cmd)
- {
- return (ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue & misc_cmd) > 0 ? true : false;
- }
- void Set_Connector_MiscCommand(int connector, int misc_cmd)
- {
- ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue |= misc_cmd;
- }
- void Clean_Connector_MiscCommand(int connector, int misc_cmd)
- {
- ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue &= ~misc_cmd;
- }
- void AnnounceEthernetStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_ETHERNET_STATUS);
- }
- }
- }
- void AnnounceWiFiStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_WIFI_STATUS);
- }
- }
- }
- void AnnounceTelcomModemStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_TELCOM_MODEM_STATUS);
- }
- }
- }
- void AnnounceBackendStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_BACKEND_STATUS);
- }
- }
- }
- void AnnounceBillingStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_BILLING_STATUS);
- }
- }
- }
- void AnnounceStopChargingButtonStatus(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_STOP_BUTTON_STATUS);
- }
- }
- }
- void AnnounceAuthModeConfig(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_AUTH_MODE_CONFIG);
- }
- }
- }
- void AnnounceEVCCIDConfig(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_EVCCID_CONFIG);
- }
- }
- }
- void AnnounceLEDIntensity(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_LED_INTENSITY);
- }
- }
- }
- void AnnounceCurrency(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_CURRENCY);
- }
- }
- }
- void AnnounceRfidEndian(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_RFID_CARD_ENDIAN);
- }
- }
- }
- void AnnounceRfidReader(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_RFID_ENABLE);
- }
- }
- }
- void AnnounceRemoteStartNoID(void)
- {
- for(int index = 0; index < CONNECTOR_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
- if(chargingInfo[gun]->SystemStatus == S_IDLE)
- {
- ShmChargerInfo->ConnectorPageReq[gun].bits.RemoteStartNoID = true;
- break;
- }
- }
- }
- }
- }
- void AnnounceLineStatusCode(int gun, int status)
- {
- int dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- ShmChargerInfo->LineApi.StatusCode[gun] = status;
- Set_Connector_MiscCommand(gun, MISC_CONN_LINE_STATUS);
- }
- }
- void AnnounceStationInfo(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_STATION_INFO);
- }
- }
- }
- void AnnounceOccupancyPrice(void)
- {
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_PARKING_PRICE);
- }
- }
- }
- void UpdateConfigAndIcon(void)
- {
- unsigned char status = _Connnection_Disable;
- // update ethernet connection status
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet == YES ? _Connnection_Disconnected : _Connnection_Connected;
- if(ShmChargerInfo->CabinetMiscValue.EthernetStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.EthernetStatus = status;
- AnnounceEthernetStatus();
- }
- // update wifi connection status
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? _Connnection_Disconnected : _Connnection_Connected;
- }
- else
- {
- status = _Connnection_Disable;
- }
- if(ShmChargerInfo->CabinetMiscValue.WiFiStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.WiFiStatus = status;
- AnnounceWiFiStatus();
- }
- // update 4g connection status
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- status = (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == NO &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES) ? _Connnection_Connected : _Connnection_Disconnected;
- }
- else
- {
- status = _Connnection_Disable;
- }
- if(ShmChargerInfo->CabinetMiscValue.TelcomModemStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.TelcomModemStatus = status;
- AnnounceTelcomModemStatus();
- }
- // update backend connection status
- status = ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet == YES ? _Connnection_Disconnected : _Connnection_Connected;
- if(ShmChargerInfo->CabinetMiscValue.BackendStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.BackendStatus = status;
- AnnounceBackendStatus();
- }
- // update billing status
- status = ShmSysConfigAndInfo->SysConfig.BillingData.isBilling;
- if(ShmChargerInfo->CabinetMiscValue.BillingStatus != status)
- {
- ShmChargerInfo->CabinetMiscValue.BillingStatus = status;
- AnnounceBillingStatus();
- }
- // update stop charging button
- status = ShmSysConfigAndInfo->SysConfig.StopChargingByButton;
- if(ShmChargerInfo->CabinetMiscValue.StopChargingButton != status)
- {
- ShmChargerInfo->CabinetMiscValue.StopChargingButton = status;
- AnnounceStopChargingButtonStatus();
- }
- // update AuthMode config
- status = ShmSysConfigAndInfo->SysConfig.AuthorisationMode;
- if(ShmChargerInfo->CabinetMiscValue.AuthModeConfig != status)
- {
- ShmChargerInfo->CabinetMiscValue.AuthModeConfig = status;
- AnnounceAuthModeConfig();
- AnnounceEVCCIDConfig();
- }
- // update EVCCID config
- status = ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID;
- if(ShmChargerInfo->CabinetMiscValue.EVCCIDConfig != status)
- {
- ShmChargerInfo->CabinetMiscValue.EVCCIDConfig = status;
- AnnounceEVCCIDConfig();
- }
- // update LED Intensity
- status = ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity;
- if(ShmChargerInfo->CabinetMiscValue.LEDIntensity != status)
- {
- ShmChargerInfo->CabinetMiscValue.LEDIntensity = status;
- AnnounceLEDIntensity();
- }
- // update currency
- status = ShmSysConfigAndInfo->SysConfig.BillingData.Currency;
- if(ShmChargerInfo->CabinetMiscValue.Currency != status)
- {
- ShmChargerInfo->CabinetMiscValue.Currency = status;
- AnnounceCurrency();
- }
- // update RfidCardNumEndian
- status = ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian;
- if(ShmChargerInfo->CabinetMiscValue.RfidEndian != status)
- {
- ShmChargerInfo->CabinetMiscValue.RfidEndian = status;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Phihong ||
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- AnnounceRfidEndian();
- }
- }
- // update AuthMode config
- status = ShmSysConfigAndInfo->SysConfig.isRFID;
- if(ShmChargerInfo->AuthInfo.AuthMode.bits.RFIDEnable != status)
- {
- ShmChargerInfo->AuthInfo.AuthMode.bits.RFIDEnable = status;
- ShmChargerInfo->CabinetMiscValue.RfidReaderEnable = status;
- AnnounceRfidReader();
- }
- }
- void Check4gWifiReset(void)
- {
- int timeDelay = 0;
- if(ShmChargerInfo->Control.SysCtrl.bits.BackendEnable)
- {
- if((!ShmSysConfigAndInfo->SysInfo.InternetConn && !ShmSysConfigAndInfo->SysInfo.OcppConnStatus &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE ||
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)) ||
- ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES)
- {
- if(!_NeedReset4gWifi)
- {
- GetClockTime(&_4gWifiReset_time);
- LOG_INFO("Backend Enable But Internet Not Available!");
- }
- _NeedReset4gWifi = true;
- }
- else
- {
- _NeedReset4gWifi = false;
- }
- if(_NeedReset4gWifi)
- {
- timeDelay = ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES ?
- FAST_RESET_4G_WIFI_TIME : TRY_RESET_4G_WIFI_TIME;
- if(GetTimeoutValue(_4gWifiReset_time) / uSEC_VAL >= timeDelay)
- {
- ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable = true;
- usleep(100000);
- // before reset 4g io, kill Module_4g & Module_Wifi task
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("killall Module_4g &");
- }
- usleep(100000);
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("killall Module_Wifi &");
- }
- LOG_INFO("Reset 4g_Wifi Module");
- system("echo 1 > /sys/class/gpio/gpio104/value");
- sleep(1);
- system("echo 0 > /sys/class/gpio/gpio104/value");
- _NeedReset4gWifi = false;
- ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable = false;
- }
- }
- }
- else
- {
- _NeedReset4gWifi = false;
- }
- }
- void MasterCabinetDhcpClientConfig(void)
- {
- char tmpbuf[256];
- //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);
- }
- void InitMasterCabinetEthernet(void)
- {
- char tmpbuf[256];
- //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", "192.168.100.1", "255.255.255.0");
- system(tmpbuf);
- }
- void InitSlaveCabinetEthernet(void)
- {
- char tmpbuf[256];
- system("/sbin/ifconfig eth0 down");
- system("/sbin/ifconfig eth1 down");
- system("killall udhcpc");
- system("rm -rf /etc/resolv.conf");
- system("pgrep -f \"udhcpd /etc/udhcpd_eth1.conf\" | xargs kill");
- //Init Eth0 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth0 192.168.100.3%d netmask %s up",
- (ShmChargerInfo->Control.CabinetSwitch - 1),
- "255.255.255.0");
- system(tmpbuf);
- system("/sbin/route add default gw 192.168.100.1 eth0");
- //Init Eth1 for internet
- memset(tmpbuf,0,256);
- sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up", SLAVE_ETH1_IP, SLAVE_ETH1_SUBMASK);
- system(tmpbuf);
- }
- void InitEthernet(void)
- {
- system("ifconfig eth0 down");
- system("ifconfig eth1 down");
- sleep(2);
- 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);
- InitMasterCabinetEthernet();
- MasterCabinetDhcpClientConfig();
- // DO360 DHCP Server
- InitialDispenserDhcpServerConfig();
- StartDispenserDhcpServer();
- pid_t pid = fork();
- uint8_t cnt_pingDNS_Fail;
- if(pid == 0)
- {
- ShmChargerInfo->CabinetMiscValue.BackendStatus = _Connnection_Disconnected;
- ShmChargerInfo->CabinetMiscValue.EthernetStatus = _Connnection_Disconnected;
- ShmChargerInfo->CabinetMiscValue.WiFiStatus = _Connnection_Disable;
- ShmChargerInfo->CabinetMiscValue.TelcomModemStatus = _Connnection_Disable;
- LOG_INFO("Internet Fork PID = %d", getpid());
- for(;;)
- {
- if(isEthernetCablePlugIn(0) == YES)
- {
- if(isRouteFail())
- {
- LOG_INFO("eth0 not in route, restart eht0.");
- system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
- if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
- {
- InitialDHCP();
- }
- else
- {
- system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
- 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);
- }
- }
- }
- if(isReachableInternet() == PASS)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet != NO)
- {
- LOG_INFO("Internet is Reachable");
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = NO;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
- cnt_pingDNS_Fail = 0;
- }
- else
- {
- if(++cnt_pingDNS_Fail > 3)
- {
- if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet != YES)
- {
- LOG_INFO("Internet is Disconnect Via Ethernet");
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = YES;
- ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
- }
- }
- bool ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
- if(ethResult == YES)
- {
- system("/sbin/ifmetric eth0 0");
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric mlan0 1");
- }
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
- 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.TelecomInterface.TelcomEnabled == YES &&
- ((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')))
- {
- system("/sbin/ifmetric ppp0 2");
- }
- }
- }
- if (!ethResult &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
- {
- ethResult = (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == NO &&
- ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES) ? YES : NO;
- if (ethResult)
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
- ((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");
- }
- }
- }
- // Bridge ethernet to uap0 to get dynamic ip address
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP))
- {
- if((isUap0up() == PASS) && access("/sys/class/net/br0/address", F_OK) == -1)
- {
- system("/usr/sbin/brctl addbr br0");
- system("/usr/sbin/brctl addif br0 eth0");
- system("/usr/sbin/brctl addif br0 uap0");
- system("/sbin/ifconfig br0 192.168.10.200 up");
- InitialBridgeModeDhcpServerConfig();
- //system("/bin/sed -i '/interface/d' /etc/udhcpd.conf");
- //system("/bin/echo 'interface br0' >> /etc/udhcpd.conf");
- system("pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd.conf");
- LOG_INFO("Bridge uap0 & eth0 for local power sharing by ethernet.");
- _isBridgeModeConfig = true;
- }
- }
- else
- {
- if(access("/sys/class/net/br0/address", F_OK) != -1)
- {
- system("/sbin/ifconfig br0 down");
- system("/usr/sbin/brctl delbr br0");
- LOG_INFO("Disable uap0 & eth0 Bridge.");
- }
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP && _isBridgeModeConfig)
- {
- InitialApModeDhcpServerConfig();
- system("pgrep -f \"udhcpd /etc/udhcpd.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd.conf");
- LOG_INFO("Restart uap0 udhcpd.");
- _isBridgeModeConfig = false;
- }
- }
- // Change uap0 to low priority
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE &&
- (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP) &&
- (isUap0up() == PASS))
- {
- system("/sbin/ifmetric uap0 1");
- }
- //==============================================
- // Check Local Power Sharing Communication
- //==============================================
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing == _SYS_POWER_SHARING_MODE_SLAVE)
- {
- if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError == ON)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError = OFF;
- }
- }
- else
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError == OFF)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError = ON;
- }
- }
- }
- else
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LocalPowerSharingCommunicationError = OFF;
- }
- if(!Is_Ocpp_Task_Alive())
- {
- ShmSysConfigAndInfo->SysInfo.OcppConnStatus = false;
- }
- ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.WiFiDisable = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_DISABLE ? true : false;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.Telocom4GModuleDisable = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == false ? true : false;
- ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet = ShmSysConfigAndInfo->SysInfo.OcppConnStatus == false ? true : false;
- UpdateConfigAndIcon();
- Check4gWifiReset();
- sleep(5);
- }
- }
- #ifdef SystemLogMessage
- LOG_INFO("[main]InitEthernet: Initial Ethernet OK.");
- #endif
- }
- 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);
- sprintf(ShmChargerInfo->SysMisc.MainVersion, fwVersion);
- sprintf(ShmChargerInfo->SysMisc.SubVersion, subVersion);
- #if ENABLE_PCBA_TEST == 0
- GetFullFirmwareVersion(fwVersion, (char *)ShmSysConfigAndInfo->SysConfig.ModelName, (char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
- // 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;
- #endif
- }
- void InitialShareMemoryInfo()
- {
- FILE *fp;
- char cmd[512];
- char buf[512];
- _UpgradeNeedReboot = FALSE;
- _psuLostQuantity = 0;
- //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.Relay2ModuleHwRev, " "); //DO360 RC2
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, " "); //DO360 RC2
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Connector1FwRev, " ");
- sprintf((char *) ShmSysConfigAndInfo->SysInfo.Connector2FwRev, " ");
- 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;
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- 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));
- memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev)); //DO360 RC2
- ShmPrimaryMcuData->SelfTest_Comp = NO;
- ShmRelayModuleData[0]->SelfTest_Comp = NO;
- ShmRelayModuleData[1]->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;
- ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
- ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
- LOG_INFO("DispenserSequence = %d, MaxConnectorQuantity = %d",
- ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
- ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
- {
- LOG_INFO("Dispenser[%d] <=> %d", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- memset((char *)&_BackupStatusNotification[i], 0, sizeof(struct StructStatusNotification));
- _useGunMeterValue[i] = false;
- _notifyOccupancyFeeAct[i] = _Notify_None;
- }
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- _canUpdateFinalCost[i] = false;
- _isUndisposedFinalCost[i] = true;
- }
- }
- int Initialization(void)
- {
- // int pinOut[2] = { 116, 115 };
- for (byte count = 0; count < CONNECTOR_QUANTITY; count++)
- {
- chargingInfo[count]->RemoteStartFlag = NO;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[count].Parameter.bits.RemoteStartConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[count].Parameter.bits.RemoteStopConfirm = false;
- SetOcppErrorCode(count, "NoError");
- }
- LOG_INFO("Initialization OK");
- return PASS;
- }
- void InitialPsuGroupingAndLocation(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- memcpy(ShmPsuGrouping->Location, Group_to_Location_4_Gun, sizeof(ShmPsuGrouping->Location));
- memcpy(ShmPsuGrouping->Layout, Location_to_Group_4_Gun, sizeof(ShmPsuGrouping->Layout));
- }
- else
- {
- memcpy(ShmPsuGrouping->Location, Group_to_Location_2_Gun, sizeof(ShmPsuGrouping->Location));
- memcpy(ShmPsuGrouping->Layout, Location_to_Group_2_Gun, sizeof(ShmPsuGrouping->Layout));
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- ShmPsuGrouping->GroupCollection[i].Index = i;
- ShmPsuGrouping->GroupCollection[i].Location = ShmPsuGrouping->Location[i];
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay == 0)
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_4_Gun[i][0], GENERAL_GUN_QUANTITY);
- }
- else
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_4_Gun_6Parallel[i][0], GENERAL_GUN_QUANTITY);
- }
- }
- else
- {
- memcpy(&ShmPsuGrouping->GroupCollection[i].ParallelConfig[0], &GroupParallelRelay_2_Gun[i][0], GENERAL_GUN_QUANTITY);
- }
- ShmChargerInfo->Control.GunAvailable[i] = NO;
- }
- }
- void InitialCustomerCode(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'A' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'D')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Audi;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'E' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == '4')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_E4U;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'U' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'U')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_UCar;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'T' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'C')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_TCC;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'O' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'L')
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Shell;
- }
- else
- {
- ShmChargerInfo->Control.CustomerCode = _CUSTOMER_CODE_Phihong;
- }
- }
- void InitialCustomizedSetting(void)
- {
- ShmChargerInfo->Control.CustomizedInfo.StandbyTime = STANDBY_TIME;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisableForTcc = true;
- }
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_E4U)
- {
- ShmChargerInfo->Control.CustomizedInfo.Flag.bits.CustomizedStandbyTime = true;
- ShmChargerInfo->Control.CustomizedInfo.StandbyTime = E4U_STANDBY_TIME;
- }
- }
- void InitialMaxDispenserConnectorQuantity(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == false)
- {
- ShmChargerInfo->Control.MaxDispenser = 2;
- ShmChargerInfo->Control.MaxConnector = 2;
- }
- else
- {
- ShmChargerInfo->Control.MaxDispenser = GENERAL_GUN_QUANTITY;
- ShmChargerInfo->Control.MaxConnector = GENERAL_GUN_QUANTITY;
- }
- }
- void InitialAuthMode(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
- {
- }
- }
- void InitialQRCodeMode(void)
- {
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi ||
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_ChargeBoxId;
- }
- else
- {
- // customized
- if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode)
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_Customized;
- }
- else
- {
- ShmChargerInfo->AuthInfo.QRCodeMode = _QR_MODE_Default;
- }
- }
- }
- void InitialPowerCabinetSetting(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'A' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'D')
- {
- ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = true;
- }
- ShmChargerInfo->CabinetMiscValue.BillingStatus = ShmSysConfigAndInfo->SysConfig.BillingData.isBilling;
- ShmChargerInfo->CabinetMiscValue.StopChargingButton = ShmSysConfigAndInfo->SysConfig.StopChargingByButton;
- ShmChargerInfo->CabinetMiscValue.AuthModeConfig = ShmSysConfigAndInfo->SysConfig.AuthorisationMode;
- ShmChargerInfo->CabinetMiscValue.EVCCIDConfig = ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID;
- }
- void Initial6ParallelSetting(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[11] >= '3' && ShmSysConfigAndInfo->SysConfig.ModelName[11] <= '9')
- {
- ShmChargerInfo->Control.SysCtrl.bits.Enable6ParallelRelay = 1;
- }
- }
- void PowerModuleLibSelection(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'L')
- {
- ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib = true;
- }
- else
- {
- ShmChargerInfo->Control.LibCtrl.bits.InfyPwrLib = true;
- }
- }
- bool InitialChargerSetting(void)
- {
- bool result = true;
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' &&
- (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'O' || ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'L'))
- {
- ShmChargerInfo->Control.PrimaryCtrl.bits.AcContactorReverse = true;
- ShmChargerInfo->Control.PrimaryCtrl.bits.DoorSensorReverse = true;
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DOLedIndication = true;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
- {
- if(!(ShmSysConfigAndInfo->SysConfig.ModelName[12] == 'P' && ShmSysConfigAndInfo->SysConfig.ModelName[13] == 'K'))
- {
- ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
- }
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DKLedIndication = true;
- }
- else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'B')
- {
- //ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
- ShmChargerInfo->Control.SysCtrl.bits.DOLedIndication = true;
- //ShmChargerInfo->Control.SysCtrl.bits.DKLedIndication = true;
- ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable = true;
- ShmChargerInfo->Control.RelayCtrl.bits.DcInputEnable = true;
- }
- else
- {
- result = false;
- }
- InitialCustomerCode();
- InitialCustomizedSetting();
- InitialMaxDispenserConnectorQuantity();
- InitialAuthMode();
- InitialQRCodeMode();
- Initial6ParallelSetting();
- InitialPsuGroupingAndLocation();
- InitialPowerCabinetSetting();
- PowerModuleLibSelection();
- if(!CheckConnectorTypeStatus())
- {
- result = false;
- }
- return result;
- }
- bool InitialSystemDefaultConfig()
- {
- bool result = true;
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- InitGPIO();
- InitEthernet();
- GetMacAddress();
- return result;
- }
- void SelfTestRun(void)
- {
- LOG_INFO("Self test.");
- system("/root/Module_ChargerSelfTest &");
- }
- void SpawnPowerModuleTask(void)
- {
- if(ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib)
- {
- system("/root/Module_PsuComm_PH &");
- }
- else
- {
- system("/root/Module_PsuComm &");
- }
- }
- void KillPowerModuleTask(void)
- {
- if(ShmChargerInfo->Control.LibCtrl.bits.PhPwrLib)
- {
- system("killall Module_PsuComm_PH");
- }
- else
- {
- system("killall Module_PsuComm");
- }
- }
- void SpawnNormalService(void)
- {
- system("/root/Module_EventLogging &");
- system("/root/Module_PrimaryComm &");
- system("/root/Module_EvComm &");
- //system("/root/Module_LcmControl &");
- system("/root/Module_InternalComm &");
- SpawnPowerModuleTask();
- system("/root/Module_ProduceUtils &");
- system("/root/Module_CabinetParallel &");
- system("/root/Module_LedIndication &");
- system("/root/Module_Authorize &");
- system("/root/Module_Firewall &");
- }
- void SpawnOcppService(void)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- Run_Ocpp_Service();
- }
- }
- void SpawnMaintainOcppService(void)
- {
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- Run_MaintainOcpp_Service();
- }
- }
- void SpawnInternetService(void)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("/root/Module_4g &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("/root/Module_Wifi &");
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- system("/root/Module_4g &");
- }
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- system("/root/Module_Wifi &");
- }
- }
- }
- int SpawnTask(void)
- {
- sleep(2);
- SpawnNormalService();
- SpawnInternetService();
- return PASS;
- }
- int runFlashShellCmd(const char *cmd)
- {
- int result = FAIL;
- char buf[256];
- FILE *fp;
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- while(fgets(buf, sizeof(buf), fp) != NULL)
- {
- LOG_INFO("%s\n", buf);
- }
- result = PASS;
- }
- pclose(fp);
- return result;
- }
- 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 = ARRAY_SIZE(UsrData->CsuBootLoadFwRev); i < MtdBlockSize - 4; i++)
- {
- Chk += *(BufTmp+i);
- }
- memcpy(BufTmp + MtdBlockSize - 4, &Chk, 4);
- // Output configuration to file.
- fd = open("/mnt/EvseTempConfig.bin", O_RDWR | O_CREAT | O_TRUNC);
- if(fd < 0)
- {
- LOG_ERROR("open /mnt/EvseTempConfig.bin NG");
- free(BufTmp);
- return 0;
- }
- wrd = write(fd, BufTmp, MtdBlockSize);
- close(fd);
- if(wrd < MtdBlockSize)
- {
- LOG_ERROR("write /mnt/EvseTempConfig.bin NG");
- free(BufTmp);
- return 0;
- }
- LOG_INFO("EvseTempConfig write to file in /mnt OK.");
- LOG_INFO("Erase /dev/mtd10.");
- runFlashShellCmd("flash_erase /dev/mtd10 0 0");
- LOG_INFO("Write /dev/mtd10.");
- runFlashShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseTempConfig.bin");
- LOG_INFO("Erase /dev/mtd11.");
- runFlashShellCmd("flash_erase /dev/mtd11 0 0");
- LOG_INFO("Write /dev/mtd11.");
- runFlashShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseTempConfig.bin");
- system("rm -f /mnt/EvseTempConfig.bin");
- LOG_INFO("EvseTempConfig write to flash OK");
- }
- else
- {
- LOG_ERROR("alloc BlockSize NG");
- result = FAIL;
- }
- if(BufTmp != NULL)
- {
- free(BufTmp);
- }
- return result;
- }
- //===============================================
- // Common Detect Chk - Stop Charging ?
- //===============================================
- bool isEvBoardStopChargeFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.AlarmStop;
- }
- bool isNormalStopChargeFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.NormalStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.ManualStop);
- }
- bool isResetStopChargeFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.HardResetStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.SoftResetStop);
- }
- bool isInvalidIdStopFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop;
- }
- bool isSessionTargetStopFlag(byte gunIndex)
- {
- return chargingInfo[gunIndex]->ChargingStopFlag.bits.SessionTargetStop;
- }
- bool isBackendStopFlag(byte gunIndex)
- {
- return (chargingInfo[gunIndex]->ChargingStopFlag.bits.BackendStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.RemoteStop || chargingInfo[gunIndex]->ChargingStopFlag.bits.UnlockStop);
- }
- void ReleaseAlarmCode(byte gunIndex)
- {
- if(!Is_Ocpp_StatusNotificationErrorCode(gunIndex, "NoError"))
- {
- SetOcppErrorCode(gunIndex, "NoError");
- }
- if(!Is_Ocpp_StatusNotificationVendorCode(gunIndex, ""))
- {
- SetOcppVendorErrorCode(gunIndex, "");
- }
- if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL)
- {
- strcpy((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "");
- }
- if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL)
- {
- strcpy((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "");
- }
- if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemotenAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemotenAlarmCode, "");
- }
- if (strcmp((char *)ShmChargerInfo->GunError[gunIndex].GunAlarmCode, "") != EQUAL)
- {
- strcpy((char *)ShmChargerInfo->GunError[gunIndex].GunAlarmCode, "");
- }
- }
- //===============================================
- // EmergencyStop and Charging Stop
- //===============================================
- void ChargingTerminalProcess(byte gunIndex)
- {
- setChargerMode(gunIndex, MODE_TERMINATING);
- }
- void ChargingAlarmProcess(byte gunIndex)
- {
- UpdateErrorCodeToOcpp(gunIndex);
- setChargerMode(gunIndex, MODE_ALARM);
- }
- 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;
- if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
- {
- return;
- }
- // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
- // 其錯誤等級為 2
- if (strncmp(code, "042251", 6) == EQUAL || strncmp(code, "042252", 6) == EQUAL ||
- strncmp(code, "042238", 6) == EQUAL || strncmp(code, "042267", 6) == EQUAL ||
- strncmp(code, "042328", 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))
- {
- if (strncmp((char *)chargingInfo[gun]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun]->ConnectorAlarmCode, code, 6);
- }
- InformOcppErrOccur(4);
- ChargingAlarmProcess(gun);
- }
- }
- StopChargingProcessByString(level);
- }
- }
- void ReleaseEmsOccureByString(byte index, char *code)
- {
- bool isTrigger = false;
- byte level = 2;
- if (strncmp(code, "042251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- }
- else if (strncmp(code, "042252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- }
- else if (strncmp(code, "042237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- }
- else if (strncmp(code, "042238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- else if (strncmp(code, "042267", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == YES)
- {
- isTrigger = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NO;
- }
- if (isTrigger)
- {
- ReleaseChargingProcessByString(level);
- }
- }
- //===============================================
- // 確認硬體 (按鈕) 狀態
- //===============================================
- void ChkPrimaryStatus()
- {
- if(ShmChargerInfo->Control.TestCtrl.bits.ChargingSimulation)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = NO;
- return;
- }
- if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = YES;
- EmcOccureByString("042251");
- }
- else
- {
- ReleaseEmsOccureByString(0, "042251");
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = NO;
- }
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
- //EmcOccureByString("042238");
- }
- else
- {
- //ReleaseEmsOccureByString(0, "042238");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
- }
- 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 &&
- (ShmChargerInfo->Control.CustomizedInfo.TiltSensorStep == _TILT_SENSOR_NONE ||
- ShmChargerInfo->Control.CustomizedInfo.TiltSensorStep == _TILT_SENSOR_FINISH))
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
- EmcOccureByString("042252");
- }
- else
- {
- ReleaseEmsOccureByString(0, "042252");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- {
- EmcOccureByString("042328");
- SetAcContactor(OFF);
- }
- if(ShmChargerInfo->Control.CustomizedInfo.TiltSensorFail)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.TiltSensorStestFail = YES;
- }
- else
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.TiltSensorStestFail = NO;
- }
- }
- struct timespec _AcContactReOpen_Time;
- void ChkPsuStatus(void)
- {
- if(!ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- if(IsConnectorWholeIdle())
- {
- for(int psuGroup = 0; psuGroup < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; psuGroup++)
- {
- //if(ShmPsuData->PsuGroup[psuGroup].GroupErrorFlag.PsuGroupErrorValue != 0)
- //{
- // ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
- //}
- if(ShmChargerInfo->PsuGrouping.GroupPsuStatus_OR[psuGroup].StatusVal & PSU_STATUS_FLAG_FAULT)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
- }
- }
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
- {
- EmcOccureByString("042267");
- }
- }
- else
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor &&
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume == NO)
- {
- bool allFaultStatus = true;
- for(int gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
- {
- if(chargingInfo[gunIndex]->SystemStatus != S_FAULT && chargingInfo[gunIndex]->SystemStatus != S_MAINTAIN)
- {
- allFaultStatus = false;
- }
- }
- if(allFaultStatus)
- {
- LOG_INFO("PSU Failure, Need Resume");
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume = YES;
- }
- }
- }
- }
- int AcContactorReOpenCount = 0;
- void PsuFailureResume(void)
- {
- if(ShmChargerInfo->Control.PsuCtrl.bits.FailureResume)
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu == NO)
- {
- LOG_INFO("Ac Contactor Off By Psu Failure");
- // update _AcContactReOpen_Time
- GetClockTime(&_AcContactReOpen_Time);
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = YES;
- AcContactorReOpenCount++;
- }
- else
- {
- if(AcContactorReOpenCount < MAX_AC_CONTACTOR_COUNT)
- {
- if(GetTimeoutValue(_AcContactReOpen_Time) / uSEC_VAL >= AC_CONTACTOR_REOPEN_TIME)
- {
- ReleaseEmsOccureByString(0, "042267");
- // update _AcContactReOpen_Time
- GetClockTime(&_AcContactReOpen_Time);
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = NO;
- ShmChargerInfo->Control.PsuCtrl.bits.FailureResume = NO;
- LOG_INFO("Psu Failure Resume");
- }
- }
- }
- }
- else
- {
- if(AcContactorReOpenCount > 0)
- {
- if(GetTimeoutValue(_AcContactReOpen_Time) / uSEC_VAL >= PSU_FAILURE_RESUME_TIME)
- {
- AcContactorReOpenCount = 0;
- }
- }
- }
- }
- void SetAcContactor(unsigned char OnOff)
- {
- OnOff = OnOff ? ON : OFF;
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor != OnOff)
- {
- if(OnOff)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = NO;
- }
- LOG_INFO("Set Ac Contactor %s", OnOff == ON ? "On" : "Off");
- }
- ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = OnOff == ON ? ON : OFF;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER && ShmChargerInfo->ParallelCabinet.ParallelStatus == _Parallel_None)
- {
- SetParallelCabinetAcContactor(OnOff);
- }
- }
- int GetStandbyTime(void)
- {
- int time = STANDBY_TIME;
- if(ShmChargerInfo->Control.TestCtrl.bits.FastStandbyTime)
- {
- time = FAST_STANDBY_TIME;
- }
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.CustomizedStandbyTime)
- {
- time = ShmChargerInfo->Control.CustomizedInfo.StandbyTime;
- }
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyImmediately)
- {
- time = FAST_STANDBY_TIME;
- }
- return time;
- }
- void StandbyCheck(void)
- {
- bool enable = IsStandbyEnable();
- if(IsConnectorWholeIdle() && IsParallelCabinetIdle())
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown)
- {
- int time = GetStandbyTime();
- #if CONTACTOR_AUTO_ON_OFF == 1
- time = CONTACTOR_AUTO_ON_TIME;
- #endif
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcContactor)
- {
- if(GetSecTimeoutValue(_Standby_time) >= time && enable)
- {
- SetAcContactor(OFF);
- }
- }
- #if CONTACTOR_AUTO_ON_OFF == 1
- time = CONTACTOR_AUTO_ON_TIME + CONTACTOR_AUTO_OFF_TIME;
- if((GetTimeoutValue(_Standby_time) / uSEC_VAL) >= time)
- {
- SetAcContactor(ON);
- }
- #endif
- }
- else
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = YES;
- GetClockTime(&_Standby_time);
- }
- }
- else
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown)
- {
- ShmChargerInfo->Control.RelayCtrl.bits.StandbyCountdown = NO;
- }
- }
- }
- void CheckDisconnectionStatusRecovery(void)
- {
- bool recovery = true;
- // check all connector
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.Disconnection)
- {
- recovery = false;
- }
- }
- if(recovery)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = false;
- }
- }
- //===============================================
- // 確認各小板偵測的錯誤狀況
- //===============================================
- void CheckErrorOccurStatus(byte index)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.NormalStopRequest)
- {
- chargingInfo[index]->ChargingStopFlag.bits.NormalStop = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AlarmStopRequest)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemotenAlarmCode, 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d Error Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- if(ShmChargerInfo->GunError[index].ErrFlag.ErrorValue != 0)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- char *strGunError[] = {"042279", "041039", "041040", "042358", "042359"};
- for(int i = 0; i < MAX_GUN_ERROR_QUANTITY; i++)
- {
- if((ShmChargerInfo->GunError[index].ErrFlag.ErrorValue & (1 << i)) > 0)
- {
- memcpy(ShmChargerInfo->GunError[index].GunAlarmCode, strGunError[i], 6);
- break;
- }
- }
- memcpy(chargingInfo[index]->ConnectorAlarmCode, ShmChargerInfo->GunError[index].GunAlarmCode, 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d GunError Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.TimeoutStopRequest)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.TimeoutStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.Disconnection = true;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = true;
- if(chargingInfo[index]->SystemStatus == S_AUTHORIZING ||
- chargingInfo[index]->SystemStatus == S_PREPARNING ||
- chargingInfo[index]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[index]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[index]->SystemStatus == S_CHARGING)
- {
- if(strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042304", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d Disconnect Alarm Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else if(chargingInfo[index]->SystemStatus == S_REASSIGN_CHECK ||
- chargingInfo[index]->SystemStatus == S_REASSIGN)
- {
- setChargerMode(index, MODE_IDLE);
- }
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo)
- {
- CheckDisconnectionStatusRecovery();
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_PRIMARY;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042251", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042252", 6);
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_PRIMARY)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- // 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);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042203", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042204", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042205", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d RC Board Input UVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- if(ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable == NO)
- {
- 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);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042200", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042201", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042202", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Connector %d RC Board Input OVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- else
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
- StopChargingProcessByString(2);
- }
- if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042327", 6);
- else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
- memcpy(chargingInfo[index]->ConnectorAlarmCode, "042328", 6);
- }
- if(!chargingInfo[index]->ChargingStopFlag.bits.AlarmStop)
- {
- LOG_INFO("Gun %d DC Input OVP/UVP Occur %s", index + 1, chargingInfo[index]->ConnectorAlarmCode);
- }
- chargingInfo[index]->ChargingStopFlag.bits.AlarmStop = true;
- }
- else
- {
- if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
- {
- ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
- ReleaseChargingProcessByString(2);
- }
- }
- }
- }
- int DiffTimebWithNowSec(struct timeb ST)
- {
- //return milli-second
- struct timeb ET;
- unsigned int StartTime,StopTime;
- ftime(&ET);
- StartTime=(unsigned int)ST.time;
- StopTime=(unsigned int)ET.time;
- return (StopTime-StartTime);
- }
- int CheckTimeOut(char *start)
- {
- int result = YES;
- struct ParsingResult
- {
- int result;
- int scanedElement;
- int year;
- int month;
- int mday;
- int hour;
- int min;
- int sec;
- int tz_hour;
- int tz_min;
- float minSec;
- }parsingResult;
- struct tm tmStart;
- struct timeb tbStart;
- memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
- if(strstr((char*)start, ".") != NULL)
- {
- // Original data with mini second
- if(strstr((char*)start, "Z") != NULL)
- {
- // Original data with Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.minSec);
- }
- else
- {
- // Original data without Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.minSec,
- &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- else
- {
- // Original data without mini second
- if(strstr((char*)start, "Z") != NULL)
- {
- // Original data with Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec);
- }
- else
- {
- // Original data without Z
- parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
- &parsingResult.year,
- &parsingResult.month,
- &parsingResult.mday,
- &parsingResult.hour,
- &parsingResult.min,
- &parsingResult.sec,
- &parsingResult.tz_hour,
- &parsingResult.tz_min);
- }
- }
- if(parsingResult.scanedElement >= 6)
- {
- tmStart.tm_year = parsingResult.year - 1900;
- tmStart.tm_mon = parsingResult.month - 1;
- tmStart.tm_mday = parsingResult.mday;
- tmStart.tm_hour = parsingResult.hour;
- tmStart.tm_min = parsingResult.min;
- tmStart.tm_sec = parsingResult.sec;
- tmStart.tm_gmtoff = 0;
- tbStart.time = mktime(&tmStart);
- tbStart.timezone = 0;
- tbStart.millitm = 0;
- tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
- if(DiffTimebWithNowSec(tbStart) <= 0)
- result = NO;
- else
- result = YES;
- }
- else
- {
- LOG_INFO("Start date parsing error");
- }
- return result;
- }
- bool Is_WebServer_Alive(void)
- {
- if(system("pidof -s lighttpd > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- void Run_WebServer_Service(void)
- {
- system("/root/web.sh");
- }
- bool Is_LocalPowerSharing_Alive(void)
- {
- if(system("pidof -s Module_PowerSharing > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- void Run_LocalPowerSharing_Service(void)
- {
- system ("/root/Module_PowerSharing &");
- }
- //===============================================
- // Ocpp_Service
- //===============================================
- void Run_Ocpp_Service(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- system("/root/OcppBackend &");
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- system("/root/OcppBackend20 &");
- return;
- }
- }
- bool Is_Ocpp_Task_Alive(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(system("pidof -s OcppBackend > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(system("pidof -s OcppBackend20 > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- return false;
- }
- void Kill_Ocpp_Service(void)
- {
- system("killall OcppBackend");
- system("killall OcppBackend20");
- }
- //===============================================
- // Maintain Ocpp_Service
- //===============================================
- void Run_MaintainOcpp_Service(void)
- {
- system("/root/OcppBackendPH &");
- }
- bool Is_MaintainOcpp_Task_Alive(void)
- {
- if(system("pidof -s OcppBackendPH > /dev/null") != 0)
- {
- return false;
- }
- return true;
- }
- void Kill_MaintainOcpp_Service(void)
- {
- system("killall OcppBackendPH");
- }
- //===============================================
- // Ocpp OcppConnStatus
- //===============================================
- bool Get_Ocpp_ConnectionStatus(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->OcppConnStatus > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->OcppConnStatus > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp procDogTime
- //===============================================
- long int Get_Ocpp_procDogTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->procDogTime;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->procDogTime;
- }
- return 0;
- }
- void Clean_Ocpp_procDogTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->procDogTime = time((time_t*)NULL);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->procDogTime = time((time_t*)NULL);
- return;
- }
- }
- //===============================================
- // Ocpp Boot Notification
- //===============================================
- bool Is_Ocpp_BootNotification(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_BootNotification(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.BootNotificationConf = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.BootNotificationConf = false;
- return;
- }
- }
- //===============================================
- // Ocpp Rest
- //===============================================
- bool Is_Ocpp_ResetReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.ResetReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.ResetReq == YES ? true : false;
- }
- return false;
- }
- bool Chk_Ocpp_Reset_Type(char *type)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->Reset.Type, type) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->Reset.type, type) == EQUAL ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ResetReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
- ShmOCPP16Data->MsMsg.bits.ResetReq = false;
- ShmOCPP16Data->MsMsg.bits.ResetConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- sprintf ( (char*) ShmOCPP20Data->Reset.Response_status, "Accepted" );
- ShmOCPP20Data->MsMsg.bits.ResetReq = false;
- ShmOCPP20Data->MsMsg.bits.ResetConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp AuthorizeReq
- //===============================================
- void Set_Ocpp_AuthorizeReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = false;
- ShmOCPP16Data->SpMsg.bits.AuthorizeReq = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.AuthorizeConf = false;
- ShmOCPP20Data->SpMsg.bits.AuthorizeReq = true;
- return;
- }
- }
- bool Is_Ocpp_AuthorizeConf(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SpMsg.bits.AuthorizeConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SpMsg.bits.AuthorizeConf == YES ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_Authorize_Status(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp UpdateFirmwareReq
- //===============================================
- bool Is_Ocpp_UpdateFirmwareReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_UpdateFirmwareReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = false;
- return;
- }
- }
- bool Is_Ocpp_UpdateFirmwareStatus(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- void Set_Ocpp_UpdateFirmwareStatus(char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, status);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, status);
- return;
- }
- }
- void Clean_Ocpp_UpdateFirmwareStatus(char *status)
- {
- Set_Ocpp_UpdateFirmwareStatus("");
- }
- void Set_Ocpp_FirmwareStatusNotificationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- return;
- }
- }
- //===============================================
- // Ocpp StopTransactionOnInvalidId
- //===============================================
- bool Is_Ocpp_StopOnInvalidId_Enable(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE") > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strstr((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE") > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp AuthorizeRemoteTxRequests
- //===============================================
- bool Is_Ocpp_AuthorizeRemoteTxRequests(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") > 0 ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strstr((char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "TRUE") > 0 ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp ConnectionTimeOut
- //===============================================
- int Get_Ocpp_ConnectionTimeOut(void)
- {
- int timeout = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "") != 0)
- {
- timeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "" ) != 0)
- {
- timeout = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
- }
- }
- return timeout > 0 ? timeout : 0;
- }
- //===============================================
- // Ocpp DefaultPrice
- //===============================================
- void Get_Ocpp_DefaultPrice(char *defaultPrice)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(defaultPrice, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(defaultPrice, "");
- return;
- }
- strcpy(defaultPrice, "");
- }
- //===============================================
- // Ocpp UserPrice
- //===============================================
- void Get_Ocpp_UserPrice(char *userId, char *userPrice)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(userId, (char *)ShmOCPP16Data->Cost.SetUserPrice.idToken);
- strcpy(userPrice, (char *)ShmOCPP16Data->Cost.SetUserPrice.price);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(userId, "");
- strcpy(userPrice, "");
- return;
- }
- strcpy(userId, "");
- strcpy(userPrice, "");
- }
- void Clean_Ocpp_UserPrice(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp RunningCost
- //===============================================
- void Get_Ocpp_RunningCost(int gun_index, char *cost)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(cost, (char *)ShmOCPP16Data->Cost.RunningCost[gun_index].description);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(cost, (char *)"");
- return;
- }
- }
- void Clean_Ocpp_RunningCost(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.RunningCost[gun_index], 0x00, sizeof(struct StrcutRunningCost));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp FinalCost
- //===============================================
- void Get_Ocpp_FinalCost(int gun_index, char *cost)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(cost, (char *)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(cost, (char *)"");
- return;
- }
- }
- void Clean_Ocpp_FinalCost(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->Cost.FinalCost[gun_index], 0x00, sizeof(struct StrcutFinalCost));
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- int Get_Ocpp_FinalCostTxId(int gun_index)
- {
- int txId = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- txId = ShmOCPP16Data->Cost.FinalCost[gun_index].txId;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return txId;
- }
- //===============================================
- // Ocpp TimeOffset
- //===============================================
- void Get_Ocpp_TimeOffset(char *timeOffset)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(timeOffset, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(timeOffset, "");
- return;
- }
- strcpy(timeOffset, "");
- }
- //===============================================
- // Ocpp PreAuthAmount
- //===============================================
- void Get_Ocpp_PreAuthAmount(char *amount)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(amount, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(amount, "");
- return;
- }
- strcpy(amount, "");
- }
- //===============================================
- // Ocpp PowerSharingServerIP
- //===============================================
- void Get_Ocpp_PowerSharingServerIP(char *ip)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(ip, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(ip, "");
- return;
- }
- strcpy(ip, "");
- }
- //===============================================
- // Ocpp Refunding
- //===============================================
- void Get_Ocpp_Refunding(char *Refunding)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- void Clean_Ocpp_Refunding(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- //===============================================
- // Ocpp LcdOveride
- //===============================================
- bool Is_Ocpp_LcdOverideReq(int *gun, int *page)
- {
- *gun = ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId;
- *page = ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index;
- return ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq ? true : false;
- }
- void Clean_Ocpp_LcdOverideReq(void)
- {
- ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = false;
- }
- //===============================================
- // Ocpp StationInfo
- //===============================================
- void Get_Ocpp_ChargerStationInfo(int *station_id, char *name)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(name, (char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_ChargerStationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ChargerInfoReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_ChargerStationReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ChargerInfoReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp WeatherInfo
- //===============================================
- void Get_Ocpp_WeatherInfo(int *weatherID, float *temperature)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- *weatherID = ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId;
- *temperature = ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_WeatherReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.WeatherInfoReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_WeatherReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.WeatherInfoReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp DeductInfo
- //===============================================
- void Set_Ocpp_DeductTransaction(int transaction)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.txId = transaction;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductCreditNo(char *userId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, userId, strlen(userId));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductVemData(char *vemData)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.vemData, vemData);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductAmount(double value)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.amount = value;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DeductResult(unsigned char result)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult = result;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_DonateInvoice(unsigned char donate)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice = donate ? YES : NO;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Set_Ocpp_DeductInfo(DeductResultInfoData *deductInfo)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.DeductInfo.txId = deductInfo->TransactionId;
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo, (char *)deductInfo->creditNo, sizeof(deductInfo->creditNo));
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.vemData, deductInfo->VemData, sizeof(deductInfo->VemData));
- ShmOCPP16Data->TcciCustomData.DeductInfo.amount = ((double)deductInfo->DeductAmount / 100);
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo, deductInfo->ApprovalNumber, sizeof(deductInfo->ApprovalNumber));
- ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult = deductInfo->DeductResult;
- ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice = deductInfo->IsDonateInvoice ? YES : NO;
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- bool Is_Ocpp_ReportCreditDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_ReportCreditDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = YES;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci SerialNo
- //===============================================
- void Clean_Ocpp_TcciSerialNo(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset((char *)&ShmOCPP16Data->TcciCustomData.SerialNo[gun_index], 0x00, sizeof(37));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci ReaderStatus
- //===============================================
- bool Set_Ocpp_TcciReaderStatus(int gun_index, DeductResultInfoData *ReaderStatus)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(ReaderStatus->DeductResult == _Deduct_PreAuth_Cancel || ReaderStatus->DeductResult == _Deduct_PreAuth || ReaderStatus->DeductResult == _Deduct_PreAuth_Pass)
- {
- switch(ReaderStatus->DeductResult)
- {
- case _Deduct_PreAuth_Pass:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 1;
- break;
- case _Deduct_PreAuth_Cancel:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 2;
- break;
- case _Deduct_PreAuth:
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus = 0;
- break;
- }
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo, ReaderStatus->creditNo, sizeof(ReaderStatus->creditNo));
- memcpy((char *)&ShmOCPP16Data->TcciCustomData.VEMData[gun_index], ReaderStatus->VemData, sizeof(ReaderStatus->VemData));
- return true;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Clean_Ocpp_TcciCreditInfo(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset((char *)&ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo, 0x00, sizeof(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
- memset((char *)&ShmOCPP16Data->TcciCustomData.VEMData[gun_index], 0x00, sizeof(ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_TcciReaderStatusReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_TcciReaderStatusReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- //===============================================
- // Ocpp Tcci OccupancyFeeDisplay
- //===============================================
- bool Is_Ocpp_TcciOccupancyDisplayReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_TcciOccupancyDisplayReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- // input: gun_index, sn_len
- // output: sn
- // return: action
- int Get_Ocpp_TcciOccupancyAction(int gun_index, int sn_len, char *sn)
- {
- int action = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- action = ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId;
- if(action == _ParkingAction_DisplayButton)
- {
- memcpy(sn, ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, sn_len);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return action;
- }
- void Clean_Ocpp_TcciOccupancyActionAndSn(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = 0;
- memset(ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, 0x00, sizeof(ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci SetOccupancyPrice
- //===============================================
- bool Is_Ocpp_TcciSetOccupancyPriceReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Clean_Ocpp_TcciSetOccupancyPriceReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- float Get_Ocpp_TcciOccupancyPrice(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return 0;
- }
- //===============================================
- // Ocpp Tcci GetOccupancyFee
- //===============================================
- bool Is_Ocpp_TcciOccupancyFeeActReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_TcciOccupancyFeeAct(int gun_index, OccupancyBillInfo *bill, int action)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN, 0x00, sizeof(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
- memcpy(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN, bill->Sn, sizeof(bill->Sn));
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action = action;
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Clean_Ocpp_TcciNotifyOccupancyFeeActReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action = _Notify_None;
- ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Get_Ocpp_TcciGetOccupancyFeeResponse(int gun_index, OccupancyBillInfo *bill)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- bill->Duration = ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_duration;
- bill->Fee = ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_occupancyFee;
- memcpy(bill->StartTime, ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_startTime, sizeof(bill->StartTime));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- bool Is_Ocpp_TcciOccupancyFeeActStatus(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].response_status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- //===============================================
- // Ocpp Tcci ReportOccupancyDeductReq
- //===============================================
- bool Is_Ocpp_TcciReportOccupancyDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return false;
- }
- return false;
- }
- void Set_Ocpp_TcciReportOccupancyDeductReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Tcci OccupancyDeductResult
- //===============================================
- bool Set_Ocpp_OccupancyDeductResult(OccupancyDeductInfo *deduct, bool pass_fail)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memset(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult, 0x00, sizeof(struct StructOccupancyDeductResult));
- ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult = pass_fail;
- ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount = deduct->Fee;
- memcpy(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN[0], &deduct->Sn[0], sizeof(deduct->Sn));
- memcpy(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo[0], &deduct->creditNo[0], sizeof(deduct->creditNo));
- memcpy(&ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo[0], &deduct->ApprovalNumber[0], sizeof(deduct->ApprovalNumber));
- return true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- //===============================================
- // Ocpp Start Transaction
- //===============================================
- void Set_Ocpp_StartTransactionIdTag(int gun_index, char *id)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, id);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent [gun_index].idToken.idToken, id);
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, id);
- }
- }
- void Set_Ocpp_StartTransactionReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits [gun_index].TransactionEventReq = true;
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = true;
- }
- }
- bool Is_Ocpp_StartTransactionConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf == YES)
- {
- if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "Started") != NULL)
- {
- return true;
- }
- else
- {
- ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = false;
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- return false;
- }
- void Clean_Ocpp_StartTransactionConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = false;
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = false;
- }
- }
- bool Is_Ocpp_StartTransaction_Status(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, status) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, status) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_StartTransaction_Accepted(int gun_index)
- {
- return Is_Ocpp_StartTransaction_Status(gun_index, "Accepted");
- }
- void Get_Ocpp_StartTransaction_Status(int gun_index, char *status)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(status, (char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(status, (char *)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status);
- }
- }
- void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
- return;
- }
- sprintf(transactionId, "%d", 0);
- }
- bool Is_Invalid_StartTransactionId(int gun_index)
- {
- if(Is_Ocpp_StartTransaction_Status(gun_index, "Blocked") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Expired") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Invalid") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NoCredit") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAllowedTypeEVSE") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAtThisLocation") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "NotAtThisTime") ||
- Is_Ocpp_StartTransaction_Status(gun_index, "Unknown"))
- {
- return true;
- }
- return false;
- }
- //===============================================
- // Ocpp Stop Transaction
- //===============================================
- void Set_Ocpp_StopTransactionId(int gun_index, char *id)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, id);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent [gun_index].idToken.idToken, id);
- return;
- }
- }
- void Set_Ocpp_StopTransactionReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = true;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CpMsg.bits [gun_index].TransactionEventReq = true;
- }
- // MaintainServer
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = true;
- }
- }
- //===============================================
- // Ocpp Check Backup Error Code
- //===============================================
- void Chk_Ocpp_Backup_ErrorCode(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "") == EQUAL)
- {
- if(strcmp((char *)_BackupStatusNotification[gun_index].ErrorCode, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, (char *)_BackupStatusNotification[gun_index].ErrorCode);
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, (char *)_BackupStatusNotification[gun_index].VendorErrorCode);
- }
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Ocpp Reserve Now
- //===============================================
- bool Is_Ocpp_ReserveNowReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ReserveNowReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq = false;
- return;
- }
- }
- int Get_Ocpp_ReserveNowId(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->ReserveNow[gun_index].ReservationId;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->ReserveNow[gun_index].id;
- }
- return 0;
- }
- void Set_Ocpp_ReserveNowConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits [gun_index].ReserveNowConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits [gun_index].ReserveNowConf = true;
- return;
- }
- }
- void Get_Ocpp_ReserveNowExpiryDate(int gun_index, char *date)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(date, (char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(date, (char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime);
- return;
- }
- strcpy(date, "");
- return;
- }
- bool Is_Ocpp_ReserveNowExpired(int gun_index)
- {
- bool _expired = true;
- char _expiryDate[128];
- Get_Ocpp_ReserveNowExpiryDate(gun_index, _expiryDate);
- _expired = CheckTimeOut(_expiryDate);
- return _expired;
- }
- void Get_Ocpp_ReserveNowIdTag(int gun_index, char *idTag)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(idTag, (char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(idTag, (char *)ShmOCPP20Data->ReserveNow[gun_index].idToken.idToken);
- return;
- }
- strcpy(idTag, "");
- return;
- }
- bool Is_Ocpp_ReserveNowIdTag(uint8_t gun_index, char *authIdTag)
- {
- char ReserveIdTag[32];
- Get_Ocpp_ReserveNowIdTag(gun_index, ReserveIdTag);
- return strcmp(ReserveIdTag, authIdTag) == EQUAL ? true : false;
- }
- //===============================================
- // Ocpp Cancel Reservation
- //===============================================
- bool Is_Ocpp_CancelReservationReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_CancelReservationReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq = false;
- return;
- }
- }
- void Set_Ocpp_CancelReservationConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits [gun_index].CancelReservationConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits [gun_index].CancelReservationConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp Change Availability
- //===============================================
- bool Is_Ocpp_ChangeAvailabilityReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ChangeAvailabilityReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = false;
- return;
- }
- }
- bool Chk_Ocpp_Availability_Type(int gun_index, char *type)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->ChangeAvailability[gun_index].Type, type) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->ChangeAvailability[gun_index].operationalStatus, type) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp Unlock Connector
- //===============================================
- bool Is_Ocpp_UnlockConnectorReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_UnlockConnectorReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq = false;
- return;
- }
- }
- void Set_Ocpp_UnlockConnectorConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus, "Unlocked");
- ShmOCPP16Data->CsMsg.bits [gun_index].UnlockConnectorConf = true;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->UnlockConnector[gun_index].Response_status, "Unlocked");
- ShmOCPP20Data->CsMsg.bits [gun_index].UnlockConnectorConf = true;
- return;
- }
- }
- //===============================================
- // Ocpp Remote Start
- //===============================================
- bool Is_Ocpp_RemoteStartReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_RemoteStartReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq = false;
- return;
- }
- }
- void Get_Ocpp_RemoteStartIdTag(int gun_index, char *idTag)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(idTag, (char *)&ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag[0]);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(idTag, (char *)&ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken[0]);
- return;
- }
- strcpy(idTag, "");
- }
- //===============================================
- // Ocpp Remote Stop
- //===============================================
- bool Is_Ocpp_RemoteStopReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_RemoteStopReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = false;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq = false;
- return;
- }
- }
- //===============================================
- // Ocpp StopReason
- //===============================================
- void Set_Ocpp_StopReason(int gun_index, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- if(strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, reason);
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- if(strcmp((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "" ) == EQUAL)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, reason);
- }
- }
- // Maintain server
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- memcpy(ShmOCPP16DataPH->StopTransaction[gun_index].StopReason, ShmOCPP16Data->StopTransaction[gun_index].StopReason, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].StopReason));
- }
- }
- void Get_Ocpp_StopReason(int gun_index, char *reason)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy(reason, (char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy(reason, (char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
- return;
- }
- strcpy(reason, "");
- }
- void Clean_Ocpp_StopReason(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason, "");
- }
- // Maintain server
- if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason, "");
- }
- }
- //===============================================
- // Ocpp StatusNotification ErrorCode
- //===============================================
- void Set_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, errCode);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- bool Is_Ocpp_StatusNotificationErrorCode(int gun_index, char *errCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, errCode) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)_BackupStatusNotification[gun_index].ErrorCode, errCode) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp StatusNotification VendorErrorCode
- //===============================================
- void Set_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, vendorCode);
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return;
- }
- }
- bool Is_Ocpp_StatusNotificationVendorCode(int gun_index, char *vendorCode)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, vendorCode) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)_BackupStatusNotification[gun_index].VendorErrorCode, vendorCode) == EQUAL ? true : false;
- }
- return false;
- }
- //===============================================
- // Ocpp ChargingProfileConf
- //===============================================
- bool Is_Ocpp_ChargingProfileConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf == YES ? true : false;
- }
- return false;
- }
- void Clean_Ocpp_ChargingProfileConf(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = NO;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf = NO;
- return;
- }
- }
- //===============================================
- // Ocpp ChargingProfileReq
- //===============================================
- bool Is_Ocpp_ChargingProfileReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == YES ? true : false;
- }
- return false;
- }
- void Set_Ocpp_ChargingProfileReq(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = YES;
- return;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = YES;
- return;
- }
- }
- //===============================================
- // Ocpp SmartChargingProfile ChargingProfileKind
- //===============================================
- bool Is_Ocpp_ChargingProfileKind(int gun_index, char *kind)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind, kind) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->SmartChargingProfile [gun_index].chargingProfileKind, kind) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_ChargingProfileId(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].id == YES ? true : false;
- }
- return false;
- }
- int Get_Ocpp_ChargingProfileStartTime(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule);
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleCount(int gun_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod);
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleTime(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].StartPeriod;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].startPeriod;
- }
- return 0;
- }
- float Get_Ocpp_ChargingProfileScheduleLimit(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].Limit;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileScheduleNumberPhases(int gun_index, int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[schedule_index].NumberPhases;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[schedule_index].numberPhases;
- }
- return 0;
- }
- int Get_Ocpp_ChargingProfileStartIndex(int gun_index)
- {
- int _time = 0, _scheduleTime = 0;
- int _maxCount = 0;
- float _limit = 0;
- int _startCount = NO_DEFINE;
- _time = Get_Ocpp_ChargingProfileStartTime(gun_index);
- _maxCount = Get_Ocpp_ChargingProfileScheduleCount(gun_index);
- for(int i = 0; i < _maxCount; i++)
- {
- _scheduleTime = Get_Ocpp_ChargingProfileScheduleTime(gun_index, i);
- if(_time >= _scheduleTime)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(gun_index, i);
- if((i == 0 && _limit >= MIN_OUTPUT_CUR) || _limit > MIN_OUTPUT_CUR)
- {
- _startCount = i;
- }
- }
- }
- return _startCount;
- }
- //===============================================
- // Ocpp MaxChargingProfile ChargingProfileKind
- //===============================================
- bool Is_Ocpp_MaxChargingProfileKind(char *kind)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return strcmp((char *)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, kind) == EQUAL ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return strcmp((char *)ShmOCPP20Data->MaxChargingProfile.chargingProfileKind, kind) == EQUAL ? true : false;
- }
- return false;
- }
- bool Is_Ocpp_MaxChargingProfileId(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingProfileId == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.id == YES ? true : false;
- }
- return false;
- }
- int Get_Ocpp_MaxProfileStartTime(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return GetStartScheduleTime(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return GetStartScheduleTime(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].startSchedule);
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleCount(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ARRAY_SIZE(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod);
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleTime(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].StartPeriod;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].startPeriod;
- }
- return 0;
- }
- float Get_Ocpp_MaxProfileScheduleLimit(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].Limit;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileScheduleNumberPhases(int schedule_index)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[schedule_index].NumberPhases;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[schedule_index].limit;
- }
- return 0;
- }
- int Get_Ocpp_MaxProfileStartIndex(void)
- {
- int _time = 0, _scheduleTime = 0;
- int _maxCount = 0;
- float _limit = 0;
- int _startCount = NO_DEFINE;
- _time = Get_Ocpp_MaxProfileStartTime();
- _maxCount = Get_Ocpp_MaxProfileScheduleCount();
- for(int i = 0; i < _maxCount; i++)
- {
- _scheduleTime = Get_Ocpp_MaxProfileScheduleTime(i);
- if(_time >= _scheduleTime)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(i);
- if((i == 0 && _limit >= MIN_OUTPUT_CUR) || _limit > MIN_OUTPUT_CUR)
- {
- _startCount = i;
- }
- }
- }
- return _startCount;
- }
- //===============================================
- // Ocpp isRemoteStartWaitReq
- //===============================================
- int Is_Ocpp_RemoteStartWaitReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- return ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq;
- }
- return 0;
- }
- //===============================================
- // Ocpp SessionTarget
- //===============================================
- void Get_Ocpp_SessionTarget(int gunIndex, struct StructSessionTarget *sessionTarget)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- memcpy(sessionTarget, &ShmOCPP16Data->SessionTarget[gunIndex], sizeof(struct StructSessionTarget));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- memcpy(sessionTarget, &ShmOCPP20Data->SessionTarget[gunIndex], sizeof(struct StructSessionTarget));
- }
- }
- //===============================================
- // Ocpp OffLineMaxChargingPower
- //===============================================
- int Get_Ocpp_OffLineMaxChargingPower(void)
- {
- // unit: W
- int maxChargingPower = 0;
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- maxChargingPower = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- maxChargingPower = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OffLineMaxChargingPower].variableAttribute[0].value);
- }
- return maxChargingPower > 0 ? maxChargingPower : 0;
- }
- //===============================================
- // Ocpp OcmfData
- //===============================================
- bool Is_Ocpp_SendOcmfDataReq(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->OcmfData[gunIndex].SendOcmfDataReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Set_Ocpp_SendOcmfDataReq(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->OcmfData[gunIndex].SendOcmfDataReq = YES;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Clean_Ocpp_SendOcmfDataReq(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->OcmfData[gunIndex].SendOcmfDataReq = NO;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- void Set_Ocpp_OcmfData(int gunIndex, char *key, char *ocmfInfo)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- strncpy((char *)ShmOCPP16Data->OcmfData[gunIndex].PublicKey, key, sizeof(ShmOCPP16Data->OcmfData[gunIndex].PublicKey));
- strncpy((char *)ShmOCPP16Data->OcmfData[gunIndex].DataString, ocmfInfo, sizeof(ShmOCPP16Data->OcmfData[gunIndex].DataString));
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // Set_StartIdType
- //===============================================
- void Set_StartIdType(int gunIndex, int type)
- {
- chargingInfo[gunIndex]->StartIdType = type;
- }
- //===============================================
- // DeductResult
- //===============================================
- void Set_Deduct_UserId(int gunIndex, char *userId)
- {
- memcpy((char *)&ShmChargerInfo->DeductResultReq[gunIndex].creditNo, userId, strlen(userId));
- }
- void Set_Deduct_TransactionId(int gunIndex, int transaction)
- {
- ShmChargerInfo->DeductResultReq[gunIndex].TransactionId = transaction;
- }
- void Clean_DeductInfo(int gunIndex)
- {
- memset(&ShmChargerInfo->DeductResultReq[gunIndex], 0x00, sizeof(DeductResultInfoData));
- }
- bool Is_DeductResultReq(int gunIndex)
- {
- return ShmChargerInfo->DeductResultReq[gunIndex].DeductReq ? true : false;
- }
- //===============================================
- // ReaderStatus
- //===============================================
- bool Is_ReaderStatusReq(int gunIndex)
- {
- return ShmChargerInfo->ReaderStatus[gunIndex].ReaderStatusReq ? true : false;
- }
- void Clean_ReaderStatusInfo(int gunIndex)
- {
- memset(&ShmChargerInfo->ReaderStatus[gunIndex], 0x00, sizeof(DeductResultInfoData));
- }
- //===============================================
- // TransactionInfoData
- //===============================================
- void Set_UserTransactionId(int gunIndex, int transaction)
- {
- ShmChargerInfo->UserTransaction[gunIndex].TransactionId = transaction;
- }
- void Set_UserPrice(int gunIndex, float price)
- {
- ShmChargerInfo->UserTransaction[gunIndex].UserPrice = price;
- }
- void Set_UserTotalCost(int gunIndex, float cost)
- {
- ShmChargerInfo->UserTransaction[gunIndex].TotalCost = cost;
- }
- void Set_UserAccountBalance(int gunIndex, float balance)
- {
- ShmChargerInfo->UserTransaction[gunIndex].AccountBalance = balance;
- }
- void Set_UserDiscount(int gunIndex, float discount)
- {
- ShmChargerInfo->UserTransaction[gunIndex].CostDiscount = discount;
- }
- void Clean_UserTransaction(int gunIndex)
- {
- memset(&ShmChargerInfo->UserTransaction[gunIndex], 0x00, sizeof(TransactionInfoData));
- ShmChargerInfo->UserTransaction[gunIndex].AccountBalance = -65535;
- }
- void Clean_UserPriceAndReceipt(int gunIndex)
- {
- memset((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gunIndex][0], 0x00, sizeof(ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gunIndex]));
- memset((char *)&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gunIndex][0], 0x00, sizeof(ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gunIndex]));
- }
- //===============================================
- // OccupancyDeductReq
- //===============================================
- bool Is_OccupancyDeductReq(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.DeductReq ? true : false;
- }
- void Clean_OccupancyDeductReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.DeductReq = false;
- }
- bool Is_OccupancyKeepCountingReq(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.KeepCounting ? true : false;
- }
- void Set_OccupancyKeepCountingReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.KeepCounting = true;
- }
- void Clean_OccupancyKeepCountingReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.KeepCounting = false;
- }
- bool Is_OccupancyFeeForceCancelReq(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.ForceCancel ? true : false;
- }
- void Set_OccupancyFeeForceCancelReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.ForceCancel = true;
- }
- void Clean_OccupancyFeeForceCancelReq(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.ForceCancel = false;
- }
- //===============================================
- // Ocpp GetDiagnosticsReq
- //===============================================
- bool Is_Ocpp_GetDiagnosticsReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- return ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq == YES ? true : false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- return false;
- }
- void Clean_Ocpp_GetDiagnosticsReq(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
- {
- ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = false;
- }
- if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
- {
- }
- }
- //===============================================
- // 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()
- {
- }
- 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 AnnounceAccountBalance(unsigned char index, float balance)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = true;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = balance;
- if(!ShmChargerInfo->Control.TestCtrl.bits.DisableBalance)
- {
- Set_Connector_MiscCommand(index, MISC_CONN_ACCOUNT_BALANCE);
- }
- LOG_INFO("%sAnnounce Account Balance %4.2f To Connector %d",
- ShmChargerInfo->Control.TestCtrl.bits.DisableBalance ? "Do Not " : "", balance, index + 1);
- }
- void FouceAnnounceAccountBalance(unsigned char index)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance)
- {
- AnnounceAccountBalance(index, 0);
- }
- }
- void CleanConnectorUserIdAndPrice(unsigned char index)
- {
- if(chargingInfo[index]->SystemStatus == S_IDLE)
- {
- LOG_INFO("*********** Connector %d Clean UserId & UserPrice ***********", index + 1);
- memset(chargingInfo[index]->StartUserId, 0x00, 32);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].UserPrice = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = -65535;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = false;
- }
- }
- void DispenserAuthInitial(unsigned char dispenser)
- {
- LOG_INFO("*********** Dispenser %d Authorizing Initial ***********", dispenser + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- // clean dispenser price
- memset((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[dispenser][0], 0x00, sizeof(ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[dispenser]));
- }
- void GunAuthInitial(unsigned char connector)
- {
- LOG_INFO("*********** Gun %d Authorizing Initial ***********", connector + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- }
- unsigned char _preGunAuthResult[GENERAL_GUN_QUANTITY];
- unsigned char _preDispenserAuthResult[GENERAL_GUN_QUANTITY];
- struct timespec _GunAuth_Time[GENERAL_GUN_QUANTITY];
- struct timespec _DispenserAuth_Time[GENERAL_GUN_QUANTITY];
- void AuthorizeTimeoutProcess(void)
- {
- int CompletedTime = 0;
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult != _AuthResult_None)
- {
- if(_preGunAuthResult[index] != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult)
- {
- GetClockTime(&_GunAuth_Time[index]);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult == _AuthResult_Invalid)
- {
- FouceAnnounceAccountBalance(index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult == _AuthResult_Invalid)
- {
- if(GetTimeoutValue(_GunAuth_Time[index]) / uSEC_VAL >= AUTHORIZE_COMPLETED_TIME)
- {
- LOG_INFO("*********** Gun %d Authorizing Initial ***********", index + 1);
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- CleanConnectorUserIdAndPrice(index);
- }
- }
- }
- _preGunAuthResult[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthInfo.AuthResult;
- }
- for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult != _AuthResult_None)
- {
- if(_preDispenserAuthResult[index] != ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult)
- {
- GetClockTime(&_DispenserAuth_Time[index]);
- }
- CompletedTime = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult == _AuthResult_Valid ?
- (ShmChargerInfo->CabinetMiscValue.ConnectionTimeout + AUTHORIZE_COMPLETED_TIME) : AUTHORIZE_COMPLETED_TIME;
- if(GetTimeoutValue(_DispenserAuth_Time[index]) / uSEC_VAL >= CompletedTime)
- {
- DispenserAuthInitial(index);
- }
- }
- _preDispenserAuthResult[index] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthInfo.AuthResult;
- }
- }
- BOOL IsConnectorAuthorizeSuccess(unsigned char connector)
- {
- BOOL success = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- success = true;
- }
- return success;
- }
- BOOL IsAutoGunSelectionAuthorizeSuccess(unsigned char connector)
- {
- BOOL success = false;
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- success = true;
- }
- return success;
- }
- bool CheckConnectorTypeStatus(void)
- {
- bool result = true;
- if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 14)
- {
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = ShmChargerInfo->Control.MaxConnector;
- ShmChargerInfo->Control.ChargerRatingPower = ParsingRatingPower((char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- ShmChargerInfo->Control.PsuQuantityByModel = ShmChargerInfo->Control.ChargerRatingPower / (INFY_SINGLE_PSU_POWER / 100);
- LOG_INFO("DC Gun Count = %d, RatingPower = %d.%d kW",
- ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
- (ShmChargerInfo->Control.ChargerRatingPower / 10),
- (ShmChargerInfo->Control.ChargerRatingPower % 10));
- if(ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
- {
- result = false;
- }
- //DO360 charging info default setting
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- chargingInfo[i] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData;
- chargingInfo[i]->Index = (i < ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity || i == 0) ? i : 0xFF;
- chargingInfo[i]->Evboard_id = 0x00;
- chargingInfo[i]->ReservationId = -1;
- chargingInfo[i]->slotsIndex = 0;
- chargingInfo[i]->SystemStatus = S_BOOTING;
- chargingInfo[i]->Type = _Type_Unknown;
- chargingInfo[i]->type_index = 0;
- chargingInfo[i]->IsAvailable = YES;
- }
- }
- else
- {
- // Module Name 不正確 - 告警
- result = false;
- }
- return result;
- }
- void KillTaskExceptPrimary()
- {
- system("killall Module_Authorize");
- system("killall Module_CabinetParallel");
- system("killall Module_ChargerSelfTest");
- system("killall Module_LedIndication");
- system("killall Module_EvComm");
- system("killall Module_InternalComm");
- system("killall Module_Firewall");
- KillPowerModuleTask();
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- void KillNtpd(void)
- {
- system("killall ntpd");
- }
- void KillAllTask()
- {
- system("killall Module_Authorize");
- system("killall Module_CabinetParallel");
- system("killall Module_ChargerSelfTest");
- system("killall Module_LedIndication");
- system("killall Module_EventLogging");
- system("killall Module_PrimaryComm");
- system("killall Module_EvComm");
- system("killall Module_LcmControl");
- system("killall Module_InternalComm");
- system("killall Module_Firewall");
- KillPowerModuleTask();
- Kill_Ocpp_Service();
- Kill_MaintainOcpp_Service();
- system("killall Module_4g &");
- system("killall Module_Wifi &");
- }
- int TransferImageViaFTP(char *IpAddress, char *SourcePath)
- {
- int isPass = PASS;
- unsigned char ftpcmdbuf[256];
- //Using ftpput command to transfer upgrade image,
- //User name : root
- //User password : y42j/4cj84
- //Destination : as same as source path
- sprintf((char*)ftpcmdbuf,"ftpput -u root -p y42j/4cj84 %s \"%s\" \"%s\"", IpAddress, SourcePath, SourcePath);
- if(system((char*)ftpcmdbuf) != 0)
- {
- isPass = FAIL;
- }
- return isPass;
- }
- void TriggerDispenserUpgrade(unsigned char index, char *FileName)
- {
- memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, 0x00, 128);
- memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, FileName, strlen(FileName));
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.FirmwareUpdateRequest = true;
- LOG_INFO("Trigger dispenser %d to update image [%s]", index + 1, FileName);
- }
- BOOL PutImageToAllDispenser(char *SourcePath, char *FileName, char *model_name)
- {
- int isPass = FAIL;
- int isImageOK[GENERAL_GUN_QUANTITY];
- int dispenser_index = 0;
- BOOL transferred = FALSE;
- memset(isImageOK, 0x00, sizeof(isImageOK));
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- isPass = FAIL;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
- {
- dispenser_index = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex;
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser_index].ModelName, (char *)model_name) != EQUAL)
- {
- LOG_INFO("Dispenser %d model name [%s] update ignore",
- dispenser_index + 1,
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser_index].ModelName);
- continue;
- }
- char DispenserIpAddress[16];
- memset((char*)DispenserIpAddress, 0x00, 16);
- sprintf((char*)DispenserIpAddress, "%d.%d.%d.%d",
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) & 0xFF));
- LOG_INFO("Transfer Image(%s) to Dispenser %d (IP: %s)", SourcePath, dispenser_index + 1, DispenserIpAddress);
- isPass = TransferImageViaFTP(DispenserIpAddress, SourcePath);
- isImageOK[dispenser_index] = isPass;
- LOG_INFO("Dispenser %d Put Image %s", dispenser_index + 1, isPass == PASS ? "OK" : "Fail");
- }
- }
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(isImageOK[i] > 0)
- {
- TriggerDispenserUpgrade(i, FileName);
- transferred = true;
- }
- }
- return transferred;
- }
- BOOL WaitAllDispenserUpgradeCompleted(void)
- {
- BOOL completed = TRUE;
- GetClockTime(&_DispenserUpgrade_time);
- do
- {
- completed = TRUE;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted)
- {
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest = false;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm = false;
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted = false;
- LOG_INFO("Dispenser %d Upgrade Success", i + 1);
- }
- else
- {
- completed = FALSE;
- }
- }
- }
- if(GetTimeoutValue(_DispenserUpgrade_time) / uSEC_VAL >= DISPENSER_UPGRADE_TIME)
- {
- LOG_INFO("Wait Upgrade Timeout");
- completed = FALSE;
- break;
- }
- if(completed == FALSE)
- {
- sleep(1);
- }
- }while(!completed);
- return completed;
- }
- void UpgradePrepare(void)
- {
- int count = 0;
- SetAcContactor(OFF);
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- }
- }
- }
- if(count > 0)
- {
- sleep(3);
- }
- else
- {
- sleep(1);
- }
- }
- void TriggerPCabinetUpgrade(unsigned char index, char *FileName)
- {
- memset(ShmChargerInfo->ParallelCabinet.PCabinet[index].FwFileName, 0x00, 128);
- memcpy(ShmChargerInfo->ParallelCabinet.PCabinet[index].FwFileName, FileName, strlen(FileName));
- ShmChargerInfo->ParallelCabinet.PCabinet[index].UpdateRequest = YES;
- LOG_INFO("Trigger PCabinet %d to update image [%s]", index + 1, FileName);
- }
- BOOL PutImageToAllParallelCabinet(char *SourcePath, char *FileName)
- {
- int isPass = FAIL;
- BOOL transferred = FALSE;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- int channel = ShmChargerInfo->ParallelCabinet.PCabinet[i].SocketChannel;
- if(ShmChargerInfo->CabinetConnInfo[channel].Status == _SCONN_MATCHED &&
- ShmChargerInfo->ParallelCabinet.PCUpdateState[i] == Not_Update)
- {
- char PCabinetIpAddress[16];
- memset((char*)PCabinetIpAddress, 0x00, 16);
- sprintf((char*)PCabinetIpAddress, "%d.%d.%d.%d",
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 0) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 8) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 16) & 0xFF),
- ((ShmChargerInfo->CabinetConnInfo[channel].IpAddress >> 24) & 0xFF));
- isPass = TransferImageViaFTP(PCabinetIpAddress, SourcePath);
- if(isPass == PASS)
- {
- TriggerPCabinetUpgrade(i, FileName);
- }
- transferred = true;
- }
- }
- }
- return transferred;
- }
- BOOL WaitAllPCabinetStartUpgrade(void)
- {
- BOOL isStart = true;
- int count = 0;
- struct timespec _waitStart;
- GetClockTime(&_waitStart);
- do
- {
- isStart = true;
- count = 0;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- if(ShmChargerInfo->ParallelCabinet.PCUpdateState[i] != Updating)
- {
- isStart = false;
- }
- }
- }
- if((GetTimeoutValue(_waitStart) / uSEC_VAL) >= START_UPGRADE_TIME)
- {
- isStart = false;
- break;
- }
- usleep(10000);
- }while(!isStart);
- if(isStart && count > 0)
- {
- LOG_INFO("Total %d PCabinet upgrade start...", count);
- }
- else
- {
- if(count > 0)
- {
- LOG_INFO("Wait PCabinet upgrade timeout");
- }
- else
- {
- LOG_INFO("No PCabinet need to upgrade");
- }
- }
- return isStart;
- }
- BOOL WaitAllPCabinetUpgradeCompleted(void)
- {
- BOOL completed = true;
- int count = 0;
- struct timespec _waitCompleted;
- GetClockTime(&_waitCompleted);
- do
- {
- completed = true;
- count = 0;
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- count++;
- if(ShmChargerInfo->ParallelCabinet.PCUpdateState[i] != Updated)
- {
- completed = false;
- }
- }
- }
- if((GetTimeoutValue(_waitCompleted) / uSEC_VAL) >= PCABINET_UPGRADE_TIME)
- {
- completed = false;
- break;
- }
- usleep(10000);
- }while(!completed);
- if(completed && count > 0)
- {
- LOG_INFO("Total %d PCabinet upgrade completed!", count);
- }
- else
- {
- if(count > 0)
- {
- LOG_INFO("Wait PCabinet upgrade completed timeout");
- }
- else
- {
- LOG_INFO("Need not to wait PCabinet completed");
- }
- }
- return completed;
- }
- BOOL WaitMCabinetUpgradeCompleted(void)
- {
- BOOL completed = true;
- struct timespec _waitCompleted;
- GetClockTime(&_waitCompleted);
- do
- {
- completed = false;
- if(ShmChargerInfo->SCabinetControl.NeedUpgrade == _R_NoUpgrade)
- {
- completed = true;
- }
- if(ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Idle &&
- ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Alarm &&
- ShmChargerInfo->SCabinetControl.SCabinetStatus != _DeviceStatus_Charging)
- {
- completed = false;
- break;
- }
- if((GetTimeoutValue(_waitCompleted) / uSEC_VAL) >= MCABINET_UPGRADE_TIME)
- {
- completed = false;
- break;
- }
- usleep(10000);
- }while(!completed);
- if(completed)
- {
- LOG_INFO("MCabinet upgrade completed!");
- }
- else
- {
- LOG_INFO("Wait MCabinet upgrade timeout or disconnected...");
- }
- return completed;
- }
- bool IsModelNameMatch(char *model)
- {
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == model[0] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[1] == model[1] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[7] == model[7] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[8] == model[8] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[9] == model[9] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[11] == model[11] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[12] == model[12] &&
- ShmSysConfigAndInfo->SysConfig.ModelName[13] == model[13])
- {
- return true;
- }
- return false;
- }
- unsigned long long getAvailableMemory(void)
- {
- long pages = sysconf(_SC_AVPHYS_PAGES);
- long page_size = sysconf(_SC_PAGE_SIZE);
- return pages * page_size;
- }
- void ImageTypeParsing(unsigned int type, char *type_str)
- {
- switch(type)
- {
- case 0x10000001:
- sprintf(type_str, "Image_uboot");
- break;
- case 0x10000002:
- sprintf(type_str, "Image_dtb");
- break;
- case 0x10000003:
- sprintf(type_str, "Image_zImage");
- break;
- case 0x10000004:
- sprintf(type_str, "Image_ramdisk");
- break;
- case 0x10000005:
- sprintf(type_str, "Image_Factory");
- break;
- case 0x10000006:
- sprintf(type_str, "Image_Primary");
- break;
- case 0x10000007:
- sprintf(type_str, "Image_CCS_uboot");
- break;
- case 0x10000008:
- sprintf(type_str, "Image_CCS_dtb");
- break;
- case 0x10000009:
- sprintf(type_str, "Image_CCS_zImage");
- break;
- case 0x1000000A:
- sprintf(type_str, "Image_CCS_ramdisk");
- break;
- case 0x1000000B:
- sprintf(type_str, "Image_CAHdeMO");
- break;
- case 0x1000000C:
- sprintf(type_str, "Image_GBT");
- break;
- case 0x1000000D:
- sprintf(type_str, "Image_Relay");
- break;
- case 0x1000000E:
- sprintf(type_str, "Image_Fan");
- break;
- case 0x1000000F:
- sprintf(type_str, "Image_LCM");
- break;
- case 0x10000010:
- sprintf(type_str, "Image_Infy_PFC");
- break;
- case 0x10000011:
- sprintf(type_str, "Image_Infy_DD");
- break;
- case 0x10000014:
- sprintf(type_str, "Image_LED");
- break;
- case 0x10000015:
- sprintf(type_str, "Image_LCM_APK");
- break;
- default:
- sprintf(type_str, "Image_Unknown");
- break;
- }
- }
- char CheckUpdateProcess()
- {
- char _model[32];
- char _type[32];
- bool support = false;
- bool OneImageOnly = false;
- int isPass = true;
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- byte target = 0;
- char *new_str = NULL;
- unsigned char *ptr = NULL;
- int fd = 0;
- int uartFd = 0;
- unsigned int Type = 0;
- long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
- DIR *d;
- struct dirent *dir;
- char cmdBuf[128];
- int availableMem = 0;
- memset(_model, 0x00, sizeof(_model));
- memset(_type, 0x00, sizeof(_type));
- availableMem = getAvailableMemory() / (1024 * 1024);
- LOG_INFO("AvailableMemory: %d MBytes", availableMem);
- // If available memory too small, free memory cache first
- if(availableMem < MIN_AVAILABLE_MEMORY)
- {
- LOG_INFO("Available memory less than %d MBytes, free cache & kill ntpd.", MIN_AVAILABLE_MEMORY);
- system("echo 3 > /proc/sys/vm/drop_caches");
- KillNtpd();
- availableMem = getAvailableMemory() / (1024 * 1024);
- LOG_INFO("AvailableMemory: %d MBytes", availableMem);
- }
- d = opendir("/mnt/");
- if(d)
- {
- while((dir = readdir(d)) != NULL && !OneImageOnly)
- {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
- continue;
- }
- new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- fd = open(new_str, O_RDONLY);
- if(fd < 0)
- {
- close(fd);
- free(new_str);
- continue;
- }
- LOG_INFO("%s\n", new_str);
- ptr = calloc(MaxLen, sizeof(char)); //-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)
- {
- memcpy(_model, ptr, 16);
- Type = (((unsigned int)ptr[16]) << 24 | ((unsigned int)ptr[17]) << 16 | ((unsigned int)ptr[18]) << 8 | ((unsigned int)ptr[19]));
- ImageTypeParsing(Type, _type);
- LOG_INFO("Model: %s, Type: %s", _model, _type);
- }
- free(ptr);
- if (ImageLen > 20)
- {
- support = false;
- availableMem = getAvailableMemory() / (1024 * 1024);
- LOG_INFO("AvailableMemory: %dMByte", availableMem);
- //if(strcmp(model, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == EQUAL)
- if(IsModelNameMatch(_model))
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- PutImageToAllParallelCabinet(new_str, dir->d_name);
- WaitAllPCabinetStartUpgrade();
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE && ShmChargerInfo->SCabinetControl.NeedUpgrade)
- {
- ShmChargerInfo->SCabinetControl.UpgradeState = Updating;
- sleep(1);
- }
- switch (Type)
- {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- support = true;
- _UpgradeNeedReboot = TRUE;
- LOG_INFO("Upgrade Flash Start...", Type);
- isPass = Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- LOG_INFO("Upgrade Flash End, %s", isPass ? "Pass" : "Fail");
- break;
- case 0x10000006: // primary mcu
- case 0x1000000D: // relay board
- case 0x1000000E: // fan board
- case 0x10000014: // led board
- support = true;
- 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 == 0x10000014)
- {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if(target == UPGRADE_RB)
- {
- isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC1, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- if(isPass == PASS)
- {
- retSucc++;
- }
- else
- {
- retFail++;
- }
- LOG_INFO("Upgrade %s", isPass == PASS ? "Success" : "Fail");
- if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
- {
- sleep(3);
- isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC2, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- }
- else
- {
- isPass = Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
- }
- close(uartFd);
- break;
- }
- if(support)
- {
- if(isPass == PASS)
- {
- retSucc++;
- }
- else
- {
- retFail++;
- }
- LOG_INFO("Upgrade %s", isPass == PASS ? "Success" : "Fail");
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- LOG_INFO("MCabinet upgrade completed");
- WaitAllPCabinetUpgradeCompleted();
- }
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE && ShmChargerInfo->SCabinetControl.UpgradeState == Updating)
- {
- ShmChargerInfo->SCabinetControl.UpgradeState = Updated;
- LOG_INFO("SCabinet upgrade completed");
- WaitMCabinetUpgradeCompleted();
- }
- }
- else
- {
- if(_model[0] == 'D' && (_model[1] == 'D' || _model[1] == 'X'))
- {
- OneImageOnly = true;
- _UpgradeNeedReboot = TRUE;
- LOG_INFO("Start Put Image To Dispenser");
- PutImageToAllDispenser(new_str, dir->d_name, _model);
- WaitAllDispenserUpgradeCompleted();
- LOG_INFO("All Dispenser Upgrade Completed");
- }
- else
- {
- retFail++;
- LOG_INFO("Model Name Is Not Match: %s", _model);
- }
- }
- }
- else
- {
- retFail++;
- LOG_INFO("Image length is illegal");
- }
- sprintf(cmdBuf, "rm -f %s", new_str);
- system(cmdBuf);
- close(fd);
- free(new_str);
- }
- }
- closedir(d);
- if(retFail != 0)
- {
- return FAIL;
- }
- return PASS;
- }
- void TriggerDispenserConnectionTimeoutSetting(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_CONNECTION_TIMEOUT))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_CONNECTION_TIMEOUT);
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Connector Timeout Value: %d **********", ShmChargerInfo->CabinetMiscValue.ConnectionTimeout);
- }
- }
- void CheckConnectionTimeout(void)
- {
- if(!Is_Ocpp_Task_Alive())
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _connectionTimeout = Get_Ocpp_ConnectionTimeOut();
- if(_connectionTimeout <= 0)
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- else
- {
- _connectionTimeout = CONN_PLUG_TIME_OUT;
- }
- }
- if(_connectionTimeout != ShmChargerInfo->CabinetMiscValue.ConnectionTimeout)
- {
- ShmChargerInfo->CabinetMiscValue.ConnectionTimeout = _connectionTimeout;
- TriggerDispenserConnectionTimeoutSetting();
- }
- }
- void CreateTimeoutFork()
- {
- pid_t timeoutPid;
- timeoutPid = fork();
- if (timeoutPid == 0)
- {
- GetClockTime(&_cmdSubPriority_time);
- CheckConnectionTimeout();
- LOG_INFO("Timeout Fork PID = %d", getpid());
- while(true)
- {
- if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
- {
- CheckConnectionTimeout();
- GetClockTime(&_cmdSubPriority_time);
- }
- sleep(1);
- }
- }
- }
- void CheckFactoryConfigFunction(void)
- {
- if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
- {
- char Buf[256];
- sprintf(Buf, "cd /root;./FactoryConfig -m");
- system(Buf);
- system("rm -f /Storage/OCPP/OCPPConfiguration");
- system("sync");
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- }
- void CheckFwUpdateFunction(void)
- {
- char UpdateResult = PASS;
- if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSelfTest = false;
- UpgradePrepare();
- ShmChargerInfo->Control.PrimaryCtrl.bits.Paused = true;
- ShmChargerInfo->Control.RelayCtrl.bits.Paused = true;
- ShmChargerInfo->Control.FanCtrl.bits.Paused = true;
- LOG_INFO("ftp : update start.");
- TryCloseWatchdog();
- //KillTask();
- system("killall Module_PrimaryComm");
- system("killall Module_InternalComm");
- UpdateResult = CheckUpdateProcess();
- if (UpdateResult == PASS)
- {
- LOG_INFO("ftp : update complete.");
- }
- else
- {
- LOG_INFO("ftp : update fail.");
- }
- ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
- sleep(10);
- if(_UpgradeNeedReboot)
- {
- system("reboot -f");
- }
- else
- {
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- else if(Is_Ocpp_UpdateFirmwareReq())
- {
- Clean_Ocpp_UpdateFirmwareReq();
- ShmChargerInfo->Control.SysCtrl.bits.NeedSelfTest = false;
- UpgradePrepare();
- ShmChargerInfo->Control.PrimaryCtrl.bits.Paused = true;
- ShmChargerInfo->Control.RelayCtrl.bits.Paused = true;
- ShmChargerInfo->Control.FanCtrl.bits.Paused = true;
- if(Is_Ocpp_UpdateFirmwareStatus("Downloaded"))
- {
- LOG_INFO("Backend : update start.");
- TryCloseWatchdog();
- Set_Ocpp_UpdateFirmwareStatus("Installing");
- Set_Ocpp_FirmwareStatusNotificationReq();
- //KillTask();
- system("killall Module_PrimaryComm");
- system("killall Module_InternalComm");
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- setChargerMode(_index, MODE_UPDATE);
- }
- UpdateResult = CheckUpdateProcess();
- if (UpdateResult == PASS)
- {
- LOG_INFO("Backend : update complete.");
- Set_Ocpp_UpdateFirmwareStatus("Installed");
- }
- else
- {
- LOG_INFO("Backend : update fail.");
- Set_Ocpp_UpdateFirmwareStatus("InstallationFailed");
- }
- Set_Ocpp_FirmwareStatusNotificationReq();
- sleep(10);
- if(_UpgradeNeedReboot)
- {
- system("reboot -f");
- }
- else
- {
- KillAllTask();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- void ExecuteWriteFlash(void)
- {
- struct SysConfigData config;
- memcpy(&config, &ShmSysConfigAndInfo->SysConfig, sizeof(struct SysConfigData));
- config.SwitchDebugFlag = NO;
- strcpy((char *) config.UserId, "");
- int result = StoreUsrConfigData(&config);
- if(result != 1)
- {
- LOG_INFO("Store User Config NG");
- }
- else
- {
- LOG_INFO("Store User Config OK");
- }
- }
- struct timespec _WiringInfo_time;
- int CheckFlashUpdate(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.FlashConfigChanged)
- {
- ShmChargerInfo->Control.SysCtrl.bits.FlashConfigChanged = false;
- LOG_INFO("Flash Config Changed");
- GetClockTime(&_WiringInfo_time);
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = true;
- }
- if(ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable)
- {
- // wait for 30s to write flash or write flash immediately
- if((GetTimeoutValue(_WiringInfo_time) / uSEC_VAL) >= WIRING_INFO_DELAY ||
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashImmediately)
- {
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashEnable = false;
- LOG_INFO("Start Writing Flash");
- pid_t writePid = fork();
- if(writePid == 0)
- {
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashBusy = true;
- ExecuteWriteFlash();
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashBusy = false;
- if(ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.WriteFlashAndReset = false;
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- LOG_INFO("Write Flash OK And Need Soft Reset");
- }
- return NO;
- }
- LOG_INFO("Write Flash Conpleted");
- }
- }
- return YES;
- }
- void CheckSoftHardReset(void)
- {
- if(ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = false;
- LOG_INFO("********** Need Soft Reset **********");
- sleep(5);
- Kill_Ocpp_Service();
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- if(ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset)
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = false;
- LOG_INFO("********** Need Hard Reset **********");
- sleep(5);
- system("reboot -f");
- }
- }
- struct timespec _Reboot_time;
- void TriggerDispenserHardwareReboot(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootConfirm == 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_HARDWARE_REBOOT))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_HARDWARE_REBOOT);
- }
- }
- }
- if(trigger)
- {
- GetClockTime(&_Reboot_time);
- LOG_INFO("********** Trigger Dispenser Hardware Reboot **********");
- }
- }
- BOOL IsDispenserHardwareRebootResponsed(void)
- {
- BOOL response_ok = TRUE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootConfirm)
- {
- response_ok = FALSE;
- // 10s for reboot request timeout
- if((GetTimeoutValue(_Reboot_time) / uSEC_VAL) >= REBOOT_TIMEOUT)
- {
- response_ok = TRUE;
- LOG_INFO("Reboot request timeout");
- }
- }
- }
- }
- return response_ok;
- }
- struct timespec _Reset_time;
- void TriggerDispenserSoftwareReset(void)
- {
- BOOL trigger = FALSE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetConfirm == 0 &&
- !Is_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_SOFTWARE_RESET);
- }
- }
- }
- if(trigger)
- {
- GetClockTime(&_Reset_time);
- LOG_INFO("********** Trigger Dispenser Software Reset **********");
- }
- }
- BOOL IsDispenserSoftwareResetResponsed(void)
- {
- BOOL response_ok = TRUE;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetConfirm)
- {
- response_ok = FALSE;
- // 10s for reset request timeout
- if((GetTimeoutValue(_Reset_time) / uSEC_VAL) >= RESET_TIMEOUT)
- {
- response_ok = TRUE;
- LOG_INFO("Reset request timeout");
- }
- }
- }
- }
- return response_ok;
- }
- // return time offset
- int TimeOffsetKeyParsing(char *StringItem)
- {
- int offset = 0;
- int hour = 0, minute = 0, sign = 1;
- char *ptrSave, *ptrToken;
- char strSource[501];
- memset(strSource, 0x00, sizeof(strSource));
- strcpy(strSource, StringItem);
- if(strSource[0] != '+' && strSource[0] != '-')
- {
- return offset;
- }
- sign = strSource[0] == '+' ? (1) : (-1);
- ptrToken = strtok_r(&strSource[1], ":", &ptrSave);
- if(ptrToken != NULL)
- {
- hour = atoi(ptrToken);
- ptrToken = strtok_r(NULL, ":", &ptrSave);
- if(ptrToken != NULL)
- {
- minute = atoi(ptrToken);
- offset = ((hour * 60) + minute) * sign;
- }
- }
- return offset;
- }
- char MyDefaultPriceString[501];
- void DefaultPriceHandler(void)
- {
- char price[501];
- char defaultPrice[512];
- memset(defaultPrice, 0x00, sizeof(defaultPrice));
- Get_Ocpp_DefaultPrice((char *)price);
- if(strcmp(MyDefaultPriceString, (char *)price) != EQUAL)
- {
- float ConnectionFee = 0, OccupancyFee = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = PriceParsing(price, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = PriceParsing(price, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing(price, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- LOG_INFO("******** Customer Audi Default Price *******");
- LOG_INFO("********** Connection Fee: %4.2f **********", ConnectionFee);
- LOG_INFO("********** Current Rate: %4.2f **********", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
- LOG_INFO("********** Occupancy Fee: %4.2f **********", OccupancyFee);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = DefaultPriceParsing(price);
- ShellPriceParsing(price, defaultPrice);
- LOG_INFO("******* Customer Shell Default Price *******");
- LOG_INFO("*** Default Price: [%s]", defaultPrice);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = TccDefaultPriceParsing(price, &ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[0]);
- LOG_INFO("******* Customer Tcc Default Price *******");
- LOG_INFO("*** TimeOfDayPricing: %4.2f", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
- }
- else
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = DefaultPriceParsing(price);
- strcpy(defaultPrice, price);
- LOG_INFO("********** Standard Default Price **********");
- LOG_INFO("********** Current Rate: %4.2f **********", ShmChargerInfo->PriceAndReceiptInfo.CurrentRate);
- LOG_INFO("*** Default Price: [%s]", defaultPrice);
- }
- strcpy(MyDefaultPriceString, price);
- }
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC)
- {
- ShmChargerInfo->PriceAndReceiptInfo.CurrentRate = GetNowTimePricing(&ShmChargerInfo->PriceAndReceiptInfo.TimeOfDayPricing[0]);
- }
- if(ShmChargerInfo->CabinetMiscValue.DefaultPrice != ShmChargerInfo->PriceAndReceiptInfo.CurrentRate)
- {
- ShmChargerInfo->CabinetMiscValue.DefaultPrice = ShmChargerInfo->PriceAndReceiptInfo.CurrentRate;
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE))
- {
- Set_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE);
- }
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_CURRENCY))
- {
- Set_Dispenser_MiscCommand(i, MISC_DISP_CURRENCY);
- }
- }
- }
- LOG_INFO("********** Trigger Dispenser Default Price Value **********");
- }
- if(strlen(defaultPrice) > 0)
- {
- strcpy(ShmChargerInfo->PriceAndReceiptInfo.DefaultPriceString, defaultPrice);
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE_STRING))
- {
- Set_Dispenser_MiscCommand(i, MISC_DISP_DEFAULT_PRICE_STRING);
- }
- }
- }
- LOG_INFO("********** Trigger Dispenser Default Price Value String **********");
- }
- }
- void UserPriceHandler(void)
- {
- char UserId[32];
- char price[500];
- char userPrice[512];
- memset(userPrice, 0x00, sizeof(userPrice));
- Get_Ocpp_UserPrice(UserId, price);
- if(strlen((char *)UserId) > 0 && strlen((char *)price) > 0)
- {
- float ConnectionFee = 0, CurrentRate = 0, OccupancyFee = 0;
- float AccountBalance = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = PriceParsing((char *)price, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- CurrentRate = PriceParsing((char *)price, "Current Rate", _AUDI_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing((char *)price, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- AccountBalance = PriceParsing((char *)price, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
- LOG_INFO("********* Customer Audi User Price *********");
- LOG_INFO("********* User Id: [%s]", UserId);
- LOG_INFO("********* Connection Fee: [%7.2f]", ConnectionFee);
- LOG_INFO("********* Current Rate: [%7.2f]", CurrentRate);
- LOG_INFO("********* Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("********* Account Balance: [%7.2f]", AccountBalance);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- ShellPriceParsing(price, userPrice);
- LOG_INFO("******** Customer Shell User Price *********");
- LOG_INFO("******** User Id: [%s]", UserId);
- LOG_INFO("******** User Price: [%s]", userPrice);
- }
- else
- {
- CurrentRate = PriceParsing((char *)price, "chargineFee", _PHIHONG_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing((char *)price, "parkingFee", _PHIHONG_PRICE_SPLIT_KEY);
- strcpy(userPrice, price);
- LOG_INFO("*********** Standard User Price ************");
- LOG_INFO("*********** User Id: [%s]", UserId);
- LOG_INFO("*********** Current Rate: [%7.2f]", CurrentRate);
- LOG_INFO("*********** Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("*********** User Price: [%s]", userPrice);
- }
- #if 0
- LOG_INFO("********** User Id: %s **********", UserId);
- LOG_INFO("********** User Price: %s", price);
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Current Rate: %7.2f **********", CurrentRate);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- #endif
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StartUserId, UserId) == EQUAL)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice != CurrentRate ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance != AccountBalance)
- {
- LOG_INFO("********** Connector Id %d User Price %4.2f, Account Balance %7.2f **********",
- (i + 1), CurrentRate, AccountBalance);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice = CurrentRate;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance = AccountBalance;
- if(strlen(userPrice) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[i][0], userPrice);
- Set_Connector_MiscCommand(i, MISC_CONN_USER_PRICE_STRING);
- }
- if(chargingInfo[i]->SystemStatus == S_AUTHORIZING)
- {
- AnnounceAccountBalance(i, AccountBalance);
- }
- }
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].AuthInfo.AuthResult == _AuthResult_Valid)
- {
- if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].AuthInfo.AuthId, UserId) == EQUAL)
- {
- if(strlen(userPrice) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[i][0], userPrice);
- }
- }
- }
- }
- Clean_Ocpp_UserPrice();
- }
- }
- void RunningCostParsing(int gunIndex, char *strCost)
- {
- float ConnectionFee = 0, SessionFee = 0, OccupancyFee = -1, TotalCost = 0, EnergyCost = -1;
- float AccountBalance = 0;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- ConnectionFee = PriceParsing((char *)strCost, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- SessionFee = PriceParsing((char *)strCost, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
- OccupancyFee = PriceParsing((char *)strCost, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- TotalCost = PriceParsing((char *)strCost, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
- AccountBalance = PriceParsing((char *)strCost, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
- LOG_INFO("******** Customer Audi Gun %d Running Cost ********", (gunIndex + 1));
- LOG_INFO("******** Connection Fee: [%7.2f]", ConnectionFee);
- LOG_INFO("******** Session Fee: [%7.2f]", SessionFee);
- LOG_INFO("******** Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("******** Total Cost: [%7.2f]", TotalCost);
- LOG_INFO("******** Account Balance: [%7.2f]", AccountBalance);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- TotalCost = ShellRunningCostParsing(strCost);
- LOG_INFO("******** Customer Shell Gun %d Running Cost *******", (gunIndex + 1));
- LOG_INFO("******** Gun %d Running Cost", (gunIndex + 1));
- LOG_INFO("******** Total Cost: [%7.2f]", TotalCost);
- }
- else
- {
- EnergyCost = PriceParsing((char *)strCost, "chargingFee", _PHIHONG_PRICE_SPLIT_KEY);
- TotalCost = EnergyCost;
- OccupancyFee = PriceParsing((char *)strCost, "parkingFee", _PHIHONG_PRICE_SPLIT_KEY);
- LOG_INFO("********** Standard Gun %d Running Cost ***********", (gunIndex + 1));
- LOG_INFO("********** Energy Cost: [%7.2f]", EnergyCost);
- LOG_INFO("********** Occupancy Fee: [%7.2f]", OccupancyFee);
- LOG_INFO("********** Total Cost: [%7.2f]", TotalCost);
- }
- #if 0
- LOG_INFO("********** Connector Id: %d Running Cost **********", (gunIndex + 1));
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Session Fee: %7.2f **********", SessionFee);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Total Cost: %7.2f **********", TotalCost);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost != TotalCost ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance != AccountBalance)
- {
- LOG_INFO("********** Connector Id %d Total Cost %.2f, Account Balance %7.2f **********",
- (gunIndex + 1), TotalCost, AccountBalance);
- }
- #endif
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost = TotalCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance = AccountBalance;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].EnergyCost = EnergyCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParkingFee = OccupancyFee;
- }
- void RunningCostHandler(void)
- {
- char strCost[256];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- Get_Ocpp_RunningCost(i, strCost);
- if(strlen((char *)strCost) > 0)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.SystemStatus >= S_REASSIGN_CHECK &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.SystemStatus <= S_CHARGING)
- {
- RunningCostParsing(i, strCost);
- }
- Clean_Ocpp_RunningCost(i);
- }
- }
- }
- void EnableConnectorBillRequest(int gunIndex, ChargingBillInfoData *bill)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_MiscReq;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt = 0;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TxId = bill->TxId;
- memcpy(&ShmChargerInfo->AllBill.GunBill[gunIndex].FeeInfo, &bill->FeeInfo, sizeof(FeeInfoData));
- }
- void DisableConnectorBill(int gunIndex)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Idle;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt = 0;
- ShmChargerInfo->AllBill.GunBill[gunIndex].TxId = 0;
- memset(&ShmChargerInfo->AllBill.GunBill[gunIndex].FeeInfo, 0x00, sizeof(FeeInfoData));
- }
- void FinalCostParsing(int txId, char *strCost, ChargingBillInfoData *_bill)
- {
- memset(_bill, 0x00, sizeof(ChargingBillInfoData));
- _bill->TxId = txId;
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- _bill->FeeInfo.ConnectionFee = PriceParsing(strCost, "Connection Fee", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.SessionFee = PriceParsing(strCost, "Session Fee", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.ParkingFee = PriceParsing(strCost, "Occupancy Fee", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.TotalCost = PriceParsing(strCost, "Total Cost", _AUDI_PRICE_SPLIT_KEY);
- _bill->FeeInfo.AccountBalance = PriceParsing(strCost, "Account Balance", _AUDI_PRICE_SPLIT_KEY);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- _bill->FeeInfo.TotalCost = ShellFinalCostParsing(strCost);
- GetShellReceiptInfo(strCost, (char *)_bill->Receipt);
- }
- else
- {
- _bill->FeeInfo.TotalCost = PriceParsing(strCost, "chargingFee", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.ParkingFee = PriceParsing(strCost, "parkingFee", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.AccountBalance = PriceParsing(strCost, "accountBalance", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.CostDiscount = PriceParsing(strCost, "couponPoint", _PHIHONG_PRICE_SPLIT_KEY);
- _bill->FeeInfo.RemainAmount = PriceParsing(strCost, "farewellMessage", _PHIHONG_PRICE_SPLIT_KEY);
- if(strlen((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL) > 0)
- {
- sprintf(_bill->Receipt, "%s%d",
- (char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL[0],
- txId);
- }
- }
- }
- void UpdateCurrentFinalCost(int gunIndex, ChargingBillInfoData *_bill)
- {
- if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Audi)
- {
- LOG_INFO("********* Customer Audi Gun %d Final Cost *********", (gunIndex + 1));
- LOG_INFO("********* Connection Fee: [%7.2f]", _bill->FeeInfo.ConnectionFee);
- LOG_INFO("********* Session Fee: [%7.2f]", _bill->FeeInfo.SessionFee);
- LOG_INFO("********* Occupancy Fee: [%7.2f]", _bill->FeeInfo.ParkingFee);
- LOG_INFO("********* Total Cost: [%7.2f]", _bill->FeeInfo.TotalCost);
- LOG_INFO("********* Account Balance: [%7.2f]", _bill->FeeInfo.AccountBalance);
- }
- else if(ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_Shell)
- {
- LOG_INFO("********* Customer Shell Gun %d Final Cost ********", (gunIndex + 1));
- LOG_INFO("********* Total Cost: [%7.2f]", _bill->FeeInfo.TotalCost);
- LOG_INFO("********* Receipt: [%s]", _bill->Receipt);
- }
- else
- {
- LOG_INFO("*********** Standard Gun %d Final Cost ************", (gunIndex + 1));
- LOG_INFO("*********** Occupancy Fee: [%7.2f]", _bill->FeeInfo.ParkingFee);
- LOG_INFO("*********** Total Cost: [%7.2f]", _bill->FeeInfo.TotalCost);
- LOG_INFO("*********** Account Balance: [%7.2f]", _bill->FeeInfo.AccountBalance);
- LOG_INFO("*********** Coupon Point: [%7.2f]", _bill->FeeInfo.CostDiscount);
- LOG_INFO("*********** Remain Amount: [%7.2f]", _bill->FeeInfo.RemainAmount);
- LOG_INFO("*********** Receipt: [%s]", _bill->Receipt);
- }
- #if 0
- LOG_INFO("********** Connector Id: %d Final Cost **********", (gunIndex + 1));
- LOG_INFO("********** Connection Fee: %7.2f **********", ConnectionFee);
- LOG_INFO("********** Session Fee: %7.2f **********", SessionFee);
- LOG_INFO("********** Occupancy Fee: %7.2f **********", OccupancyFee);
- LOG_INFO("********** Total Cost: %7.2f **********", TotalCost);
- LOG_INFO("********** Account Balance: %7.2f **********", AccountBalance);
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost != TotalCost ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance != AccountBalance ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].CostDiscount != CostDiscount)
- {
- LOG_INFO("********** Connector Id %d Total Cost %.2f, Account Balance: %7.2f, Discount: %d.%02d **********",
- (gunIndex + 1), TotalCost, AccountBalance, (CostDiscount / 100), (CostDiscount % 100));
- }
- #endif
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].TotalCost = _bill->FeeInfo.TotalCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].AccountBalance = _bill->FeeInfo.AccountBalance;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].CostDiscount = _bill->FeeInfo.CostDiscount;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].EnergyCost = _bill->FeeInfo.EnergyCost;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParkingFee = _bill->FeeInfo.ParkingFee;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemainAmount = _bill->FeeInfo.RemainAmount;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_FINAL_COST);
- if(strlen(_bill->Receipt) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gunIndex][0], _bill->Receipt);
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_RECEIPT);
- }
- DB_Update_FinalCost_Status(localDb, _bill->TxId, BILL_SATAUS_Bypass_OK);
- }
- bool IsBillStatusChanged(int gunIndex)
- {
- return ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus == ShmChargerInfo->AllBill.GunBill[gunIndex].PreStatus ?
- false : true;
- }
- void SyncBillStatus(int gunIndex)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].PreStatus = ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus;
- }
- void EnableUndisposedBill(int dispenserIndex)
- {
- LOG_INFO("Enable Dispenser %d Undisposed ChargingBill", dispenserIndex + 1);
- _isUndisposedFinalCost[dispenserIndex] = true;
- }
- void FindUndisposedAndTrigger(int dispenserIndex)
- {
- int txId = 0;
- char strCost[256];
- ChargingBillInfoData _bill;
- bool find = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- txId = DB_Get_Undisposed_FinalCost(localDb, gun, strCost);
- if(txId >= 0)
- {
- LOG_INFO("Find Gun %d Undisposed ChargingBill, txId: [%d]", gun + 1, txId);
- FinalCostParsing(txId, (char *)strCost, &_bill);
- EnableConnectorBillRequest(gun, &_bill);
- find = true;
- break;
- }
- }
- if(!find)
- {
- //LOG_INFO("Dispenser %d Undisposed ChargingBill Not Found", dispenserIndex + 1);
- _isUndisposedFinalCost[dispenserIndex] = false;
- }
- }
- bool IsDispenserBillStatusBusy(int dispenserIndex)
- {
- bool busy = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- if(ShmChargerInfo->AllBill.GunBill[gun].BillStatus != _BillStatus_Idle)
- {
- busy = true;
- break;
- }
- }
- return busy;
- }
- void DispenserBillRequestProcess(int dispenserIndex)
- {
- if(IsDispenserIdle(dispenserIndex) && !IsDispenserBillStatusBusy(dispenserIndex))
- {
- if(!_canUpdateFinalCost[dispenserIndex])
- {
- _canUpdateFinalCost[dispenserIndex] = true;
- GetClockTime(&_DispenserBill_Time[dispenserIndex]);
- }
- if(_canUpdateFinalCost[dispenserIndex] && _isUndisposedFinalCost[dispenserIndex])
- {
- if(GetSecTimeoutValue(_DispenserBill_Time[dispenserIndex]) >= FINAL_COST_UPDATE_TIME)
- {
- //LOG_INFO("Try Find Dispenser %d Undisposed ChargingBill", dispenserIndex + 1);
- FindUndisposedAndTrigger(dispenserIndex);
- GetClockTime(&_DispenserBill_Time[dispenserIndex]);
- }
- }
- }
- else
- {
- _canUpdateFinalCost[dispenserIndex] = false;
- }
- }
- void GunBillRequestProcess(int gunIndex)
- {
- unsigned char _status = ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus;
- switch(_status)
- {
- case _BillStatus_Idle:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- }
- break;
- case _BillStatus_MiscReq:
- if(IsBillStatusChanged(gunIndex))
- {
- Database_INFO("Gun %d ChargingBill MiscRequest", gunIndex + 1);
- SyncBillStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_WaitMiscClean;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_CHARGING_BILL);
- break;
- case _BillStatus_WaitMiscClean:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- GetClockTime(&_ConnectorBill_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ConnectorBill_Time[gunIndex]) / uSEC_VAL) >= FINAL_COST_TIMEOUT)
- {
- Database_INFO("Gun %d ChargingBill WaitMisc Timeout", gunIndex + 1);
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Fail;
- }
- break;
- case _BillStatus_MiscClean:
- if(IsBillStatusChanged(gunIndex))
- {
- Database_INFO("Gun %d ChargingBill MiscClean", gunIndex + 1);
- SyncBillStatus(gunIndex);
- GetClockTime(&_ConnectorBill_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ConnectorBill_Time[gunIndex]) / uSEC_VAL) >= FINAL_COST_TIMEOUT)
- {
- Database_INFO("Gun %d ChargingBill Wait Dispenser Timeout", gunIndex + 1);
- ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt++;
- if(ShmChargerInfo->AllBill.GunBill[gunIndex].TryCnt >= MAX_FINAL_COST_MISC_COUNT)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Fail;
- }
- else
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_MiscReq;
- }
- }
- break;
- case _BillStatus_UpdateDone:
- if(IsBillStatusChanged(gunIndex))
- {
- Database_INFO("Gun %d ChargingBill UpdateDone", gunIndex + 1);
- SyncBillStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_Completed;
- break;
- case _BillStatus_Completed:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- GetClockTime(&_ConnectorBill_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ConnectorBill_Time[gunIndex]) / uSEC_VAL) >= FINAL_COST_TIMEOUT)
- {
- ShmChargerInfo->AllBill.GunBill[gunIndex].BillStatus = _BillStatus_End;
- }
- break;
- case _BillStatus_Fail:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- DB_Update_FinalCost_Status(localDb, ShmChargerInfo->AllBill.GunBill[gunIndex].TxId, BILL_SATAUS_UPDATED_FAIL);
- }
- DisableConnectorBill(gunIndex);
- break;
- case _BillStatus_End:
- if(IsBillStatusChanged(gunIndex))
- {
- SyncBillStatus(gunIndex);
- DB_Update_FinalCost_Status(localDb, ShmChargerInfo->AllBill.GunBill[gunIndex].TxId, BILL_SATAUS_UPDATED_OK);
- }
- DisableConnectorBill(gunIndex);
- break;
- default:
- DisableConnectorBill(gunIndex);
- break;
- }
- }
- void FinalCostHandler(void)
- {
- int txId = 0;
- char strCost[256];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- txId = Get_Ocpp_FinalCostTxId(i);
- Get_Ocpp_FinalCost(i, strCost);
- if(strlen((char *)strCost) > 0)
- {
- DB_Insert_FinalCost(localDb, i, txId, strCost);
- Database_INFO("Insert FinalCost: Gun %d TxId[%d]", i + 1, txId);
- if(ShmChargerInfo->UserTransaction[i].TransactionId == txId)
- {
- ChargingBillInfoData _bill;
- FinalCostParsing(txId, (char *)strCost, &_bill);
- UpdateCurrentFinalCost(i, &_bill);
- }
- else
- {
- EnableUndisposedBill(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].ParentDispensetIndex);
- }
- Clean_Ocpp_FinalCost(i);
- }
- }
- if(ShmChargerInfo->Control.TestCtrl.bits.TryUndisposedBill)
- {
- ShmChargerInfo->Control.TestCtrl.bits.TryUndisposedBill = false;
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- _isUndisposedFinalCost[i] = true;
- }
- }
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- DispenserBillRequestProcess(i);
- }
- else
- {
- _canUpdateFinalCost[i] = false;
- }
- }
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- GunBillRequestProcess(i);
- }
- }
- char MyTimeOffsetString[501];
- void TimeOffsetHandler(void)
- {
- char timeOffset[501];
- Get_Ocpp_TimeOffset((char *)timeOffset);
- if(strcmp(MyTimeOffsetString, (char *)timeOffset) != EQUAL)
- {
- BOOL trigger = FALSE;
- int offset = 0;
- offset = TimeOffsetKeyParsing(timeOffset);
- LOG_INFO("********** Time Offset String [%s] -> Value [%d] -> Time [%s%02d:%02d]",
- timeOffset, offset, offset >= 0 ? "+" : "-", (abs(offset) / 60), (abs(offset) % 60));
- ShmChargerInfo->CabinetMiscValue.TimeOffset = offset;
- #if 0
- time_t timep;
- struct tm *tm;
- time(&timep);
- tm = localtime(&timep);
- LOG_INFO(" NowTime: %d/%02d/%02d %02d:%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- timep += (offset * 60);
- tm = localtime(&timep);
- LOG_INFO("OffsetTime: %d/%02d/%02d %02d:%02d:%02d",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- #endif
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity > 0)
- {
- if(!Is_Dispenser_MiscCommand(i, MISC_DISP_TIME_OFFSET))
- {
- trigger = TRUE;
- Set_Dispenser_MiscCommand(i, MISC_DISP_TIME_OFFSET);
- }
- }
- }
- if(trigger)
- {
- LOG_INFO("********** Trigger Dispenser Time Offset **********");
- }
- strcpy(MyTimeOffsetString, timeOffset);
- }
- }
- struct timespec _Cost_Price_time;
- void CheckOcppCostAndPrice(void)
- {
- // 5s for reboot request timeout
- if((GetTimeoutValue(_Cost_Price_time) / uSEC_VAL) >= OCPP_COST_REQ_INTERVAL)
- {
- GetClockTime(&_Cost_Price_time);
- DefaultPriceHandler();
- UserPriceHandler();
- RunningCostHandler();
- TimeOffsetHandler();
- }
- FinalCostHandler();
- }
- void CheckRemoteStartNoIdRequest(void)
- {
- if(Is_Ocpp_RemoteStartWaitReq())
- {
- if(!ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- LOG_INFO("Ocpp remote start without connector id is trigger");
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = true;
- AnnounceRemoteStartNoID();
- GetClockTime(&_RemoteStartNoId_Time);
- }
- if(ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- // to avoid keep RemoteStartNoId state when ocpp is disconnected
- if((GetTimeoutValue(_RemoteStartNoId_Time) / uSEC_VAL) >= (ShmChargerInfo->CabinetMiscValue.ConnectionTimeout + CONNECTION_TIME_OFFSET))
- {
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = false;
- }
- }
- }
- else
- {
- if(ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId)
- {
- LOG_INFO("Ocpp remote start without connector id is expired");
- }
- ShmChargerInfo->Control.OcppCtrl.bits.RemoteStartNoId = false;
- }
- }
- void CheckOcppPageChangeRequest(void)
- {
- int gunId = 0, pageIndex = 0;
- if(Is_Ocpp_LcdOverideReq(&gunId, &pageIndex))
- {
- Clean_Ocpp_LcdOverideReq();
- LOG_INFO("Gun %d Ocpp Line Status [%d] is trigger", gunId, pageIndex);
- AnnounceLineStatusCode(gunId - 1, pageIndex);
- }
- }
- void CheckLcmPageChangeRequest(void)
- {
- bool isTrigger = false;
- CheckRemoteStartNoIdRequest();
- CheckOcppPageChangeRequest();
- for(int index = 0; index < CONNECTOR_QUANTITY; index++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].LocalStatus != _DS_Timeout)
- {
- isTrigger = false;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
- if(ShmChargerInfo->ConnectorPageReq[gun].CtrlValue != 0)
- {
- isTrigger = true;
- break;
- }
- }
- if(isTrigger)
- {
- Set_Dispenser_MiscCommand(index, MISC_DISP_CHANGE_LCM_INFO);
- }
- else
- {
- Clean_Dispenser_MiscCommand(index, MISC_DISP_CHANGE_LCM_INFO);
- }
- }
- }
- }
- void CheckStationInfo(void)
- {
- int station_id = 0;
- char station_name[64];
- if(Is_Ocpp_ChargerStationReq())
- {
- memset(station_name, 0x00, sizeof(station_name));
- Get_Ocpp_ChargerStationInfo(&station_id, station_name);
- if(strcmp(station_name, ShmChargerInfo->StationInfo.StationName) != EQUAL ||
- ShmChargerInfo->StationInfo.StationID != station_id)
- {
- strcpy(ShmChargerInfo->StationInfo.StationName, station_name);
- ShmChargerInfo->StationInfo.StationID = station_id;
- LOG_INFO("Station ID: %d, Name: %s", ShmChargerInfo->StationInfo.StationID, ShmChargerInfo->StationInfo.StationName);
- AnnounceStationInfo();
- }
- Clean_Ocpp_ChargerStationReq();
- }
- }
- void CheckWeatherInfo(void)
- {
- int weatherID = 0;
- float temperature = 0;
- char strWeather[16];
- char *str_weather_type[] = {STR_WEATHER_NONE, STR_WEATHER_SUNNY, STR_WEATHER_CLOUDY, STR_WEATHER_RAIN, STR_WEATHER_THUNDERSTORM, STR_WEATHER_SNOW, STR_WEATHER_MIST};
- if(Is_Ocpp_WeatherReq())
- {
- Get_Ocpp_WeatherInfo(&weatherID, &temperature);
- if(weatherID != ShmChargerInfo->StationInfo.WeatherID ||
- temperature != ShmChargerInfo->StationInfo.Temperature)
- {
- ShmChargerInfo->StationInfo.WeatherID = weatherID;
- ShmChargerInfo->StationInfo.Temperature = temperature;
- if(ShmChargerInfo->StationInfo.WeatherID <= _WEATHER_Mist)
- {
- strcpy(strWeather, str_weather_type[ShmChargerInfo->StationInfo.WeatherID]);
- }
- else
- {
- sprintf(strWeather, "%d", ShmChargerInfo->StationInfo.WeatherID);
- }
- LOG_INFO("Weather: [%s][%d], Temperature: %4.1f", strWeather, ShmChargerInfo->StationInfo.WeatherID, ShmChargerInfo->StationInfo.Temperature);
- AnnounceStationInfo();
- }
- Clean_Ocpp_WeatherReq();
- }
- }
- bool _WriteDeductBusy[CONNECTOR_QUANTITY] = {0};
- void CheckDeductResultRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_DeductResultReq(i))
- {
- if(!_WriteDeductBusy[i])
- {
- if(!Is_Ocpp_ReportCreditDeductReq() && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteDeductBusy[i] = true;
- //Set_Ocpp_DeductTransaction(_BackupDeductResult[i].TransactionId);
- //Set_Ocpp_DeductCreditNo((char *)&_BackupDeductResult[i].creditNo);
- //Set_Ocpp_DeductVemData("");
- //Set_Ocpp_DeductAmount(((double)_BackupDeductResult[i].DeductAmount / 100));
- //Set_Ocpp_DeductResult(_BackupDeductResult[i].DeductResult);
- //Set_Ocpp_DonateInvoice(_BackupDeductResult[i].IsDonateInvoice);
- if(Set_Ocpp_DeductInfo(&ShmChargerInfo->DeductResultReq[i]))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->DeductResultReq[i].creditNo[0], sizeof(ShmChargerInfo->DeductResultReq[i].creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->DeductResultReq[i].ApprovalNumber[0], sizeof(ShmChargerInfo->DeductResultReq[i].ApprovalNumber));
- Set_Ocpp_ReportCreditDeductReq();
- LOG_INFO("DeductReport Gun %d TxId: %d, UserId: %s, ApprovalNo: [%s], Amount: %d.%02d, [%s], Donate: %s",
- i + 1,
- ShmChargerInfo->DeductResultReq[i].TransactionId,
- cardNo,
- appNo,
- (ShmChargerInfo->DeductResultReq[i].DeductAmount / 100),
- (ShmChargerInfo->DeductResultReq[i].DeductAmount % 100),
- str_ReaderStatus[ShmChargerInfo->DeductResultReq[i].DeductResult],
- ShmChargerInfo->DeductResultReq[i].IsDonateInvoice ? "Yes" : "No");
- if(ShmChargerInfo->DeductResultReq[i].DeductResult == _Deduct_PreAuth_Pass)
- {
- memcpy(&ShmChargerInfo->ReaderStatus[i], &ShmChargerInfo->DeductResultReq[i], sizeof(DeductResultInfoData));
- ShmChargerInfo->ReaderStatus[i].ReaderStatusReq = YES;
- }
- }
- }
- }
- else
- {
- if(!Is_Ocpp_ReportCreditDeductReq())
- {
- Clean_DeductInfo(i);
- _WriteDeductBusy[i] = false;
- }
- }
- }
- else
- {
- _WriteDeductBusy[i] = false;
- }
- }
- }
- bool _WriteReDeductBusy = false;
- void CheckReDeductRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- if(ShmChargerInfo->ReDeductReq.DeductReq)
- {
- if(!_WriteReDeductBusy)
- {
- if(!Is_Ocpp_ReportCreditDeductReq() && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteReDeductBusy = true;
- if(Set_Ocpp_DeductInfo(&ShmChargerInfo->ReDeductReq))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->ReDeductReq.creditNo[0], sizeof(ShmChargerInfo->ReDeductReq.creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->ReDeductReq.ApprovalNumber[0], sizeof(ShmChargerInfo->ReDeductReq.ApprovalNumber));
- Set_Ocpp_ReportCreditDeductReq();
- LOG_INFO("ReDeductReport TxId: %d, UserId: %s, ApprovalNo: [%s], Amount: %d.%02d, [%s], Donate: %s",
- ShmChargerInfo->ReDeductReq.TransactionId,
- cardNo,
- appNo,
- (ShmChargerInfo->ReDeductReq.DeductAmount / 100),
- (ShmChargerInfo->ReDeductReq.DeductAmount % 100),
- str_ReaderStatus[ShmChargerInfo->ReDeductReq.DeductResult],
- ShmChargerInfo->ReDeductReq.IsDonateInvoice ? "Yes" : "No");
- if(ShmChargerInfo->ReDeductReq.DeductResult == _Deduct_PreAuth_Pass && ShmChargerInfo->ReDeductReq.ConnectorId != 0xFF)
- {
- int gunIndex = ShmChargerInfo->ReDeductReq.ConnectorId - 1;
- memcpy(&ShmChargerInfo->ReaderStatus[gunIndex], &ShmChargerInfo->ReDeductReq, sizeof(DeductResultInfoData));
- ShmChargerInfo->ReaderStatus[gunIndex].ReaderStatusReq = YES;
- }
- }
- }
- }
- else
- {
- if(!Is_Ocpp_ReportCreditDeductReq())
- {
- memset(&ShmChargerInfo->ReDeductReq, 0x00, sizeof(DeductResultInfoData));
- _WriteReDeductBusy = false;
- }
- }
- }
- else
- {
- _WriteReDeductBusy = false;
- }
- }
- bool _WriteReaderStatusBusy[CONNECTOR_QUANTITY] = {0};
- void CheckReaderStatusRequest(void)
- {
- char *str_ReaderStatus[] = {STR_DEDUCT_FAIL, STR_DEDUCT_PASS, STR_DEDUCT_CANCEL, STR_DEDUCT_PREAUTH};
- char cardNo[21];
- char appNo[10];
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_ReaderStatusReq(i))
- {
- if(!_WriteReaderStatusBusy[i])
- {
- if(!Is_Ocpp_TcciReaderStatusReq(i) && ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- _WriteReaderStatusBusy[i] = true;
- if(Set_Ocpp_TcciReaderStatus(i, &ShmChargerInfo->ReaderStatus[i]))
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memcpy(cardNo, (char *)&ShmChargerInfo->ReaderStatus[i].creditNo[0], sizeof(ShmChargerInfo->ReaderStatus[i].creditNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(appNo, (char *)&ShmChargerInfo->ReaderStatus[i].ApprovalNumber[0], sizeof(ShmChargerInfo->ReaderStatus[i].ApprovalNumber));
- Set_Ocpp_TcciReaderStatusReq(i);
- LOG_INFO("StatusReport Gun %d: [%s], CreditNo: [%s], ApprovalNo: [%s]",
- i + 1, str_ReaderStatus[ShmChargerInfo->ReaderStatus[i].DeductResult], cardNo, appNo);
- }
- }
- }
- else
- {
- if(!Is_Ocpp_TcciReaderStatusReq(i))
- {
- Clean_ReaderStatusInfo(i);
- _WriteReaderStatusBusy[i] = false;
- }
- }
- }
- else
- {
- _WriteReaderStatusBusy[i] = false;
- }
- }
- }
- void CheckOccupancyPrice(void)
- {
- float _price = 0;
- if(Is_Ocpp_TcciSetOccupancyPriceReq())
- {
- _price = Get_Ocpp_TcciOccupancyPrice();
- if(ShmChargerInfo->CabinetMiscValue.ParkingPrice != _price)
- {
- ShmChargerInfo->CabinetMiscValue.ParkingPrice = _price;
- LOG_INFO("Set OccupancyPrice: [%6.2f]", ShmChargerInfo->CabinetMiscValue.ParkingPrice);
- AnnounceOccupancyPrice();
- }
- Clean_Ocpp_TcciSetOccupancyPriceReq();
- }
- }
- bool IsParkingButtonStatusChanged(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus == ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.PreStatus ?
- false : true;
- }
- void SyncParkingButtonStatus(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.PreStatus = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus;
- }
- int OccupancyButtonSync(int gunIndex)
- {
- int _pass = FAIL;
- unsigned char _status = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus;
- switch(_status)
- {
- case _BillStatus_Idle:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- SyncParkingButtonStatus(gunIndex);
- }
- break;
- case _BillStatus_MiscReq:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyButton [MiscRequest]", gunIndex + 1);
- SyncParkingButtonStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_WaitMiscClean;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_PARKING_STATUS);
- break;
- case _BillStatus_WaitMiscClean:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- SyncParkingButtonStatus(gunIndex);
- GetClockTime(&_ParkingStatus_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ParkingStatus_Time[gunIndex]) / uSEC_VAL) >= PARKING_STATUS_TIMEOUT)
- {
- Occupancy_INFO("Gun %d OccupancyButton [WaitMisc Timeout]", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- break;
- case _BillStatus_MiscClean:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyButton [MiscClean]", gunIndex + 1);
- SyncParkingButtonStatus(gunIndex);
- GetClockTime(&_ParkingStatus_Time[gunIndex]);
- }
- if((GetTimeoutValue(_ParkingStatus_Time[gunIndex]) / uSEC_VAL) >= PARKING_STATUS_TIMEOUT)
- {
- LOG_INFO("Gun %d OccupancyButton [Wait Timeout]", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- break;
- case _BillStatus_UpdateDone:
- if(IsParkingButtonStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyButton [UpdateDone]", gunIndex + 1);
- SyncParkingButtonStatus(gunIndex);
- }
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_Idle;
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- _pass = PASS;
- break;
- default:
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- break;
- }
- return _pass;
- }
- int NotifyOccupancyFeeActRequest(int gunIndex, int action)
- {
- char *str_notify_occupancy_act[] = {STR_NOTIFY_NONE, STR_GET_OCCUPANCY_FEE, STR_CANCEL_OCCUPANCY_DEDUCT, STR_CANCEL_OCCUPANCY_FEE};
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_None)
- {
- if(!Is_Ocpp_TcciOccupancyFeeActReq(gunIndex))
- {
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- Set_Ocpp_TcciOccupancyFeeAct(gunIndex, &ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill, action);
- _notifyOccupancyFeeAct[gunIndex] = action;
- LOG_INFO("Gun %d Set OccupancyFee Action [%s] Request", gunIndex + 1, str_notify_occupancy_act[action]);
- }
- }
- else
- {
- if(!Is_Ocpp_TcciOccupancyFeeActReq(gunIndex))
- {
- if(Is_Ocpp_TcciOccupancyFeeActStatus(gunIndex, "Accepted"))
- {
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_GetOccupancyFee)
- {
- Get_Ocpp_TcciGetOccupancyFeeResponse(gunIndex, &ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill);
- LOG_INFO("Gun %d Get Occupancy Fee: [%.2f], Duration: [%d], StartTime: [%s]",
- gunIndex + 1,
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Fee,
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Duration,
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.StartTime);
- }
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_CancelLocalDeduction)
- {
- LOG_INFO("Gun %d Occupancy Deduction Stopped", gunIndex + 1);
- }
- if(_notifyOccupancyFeeAct[gunIndex] == _Notify_CancelOccupancyFee)
- {
- LOG_INFO("Gun %d Occupancy Fee Force Clean", gunIndex + 1);
- }
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- return PASS;
- }
- else
- {
- LOG_INFO("Gun %d OccupancyFee Action [%s] Rejected", gunIndex + 1, str_notify_occupancy_act[action]);
- return FAIL;
- }
- }
- if((GetTimeoutValue(_GetOccupancyFee_Time[gunIndex]) / uSEC_VAL) >= OCCUPANCY_FEE_TIMEOUT)
- {
- // shall not reach here
- Clean_Ocpp_TcciNotifyOccupancyFeeActReq(gunIndex);
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- LOG_INFO("Gun %d OccupancyFee Action [%s] Request Timeout", gunIndex + 1, str_notify_occupancy_act[action]);
- return FAIL;
- }
- }
- return WAIT;
- }
- bool IsParkingStatusChanged(int gunIndex)
- {
- return ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status == ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].PreStatus ?
- false : true;
- }
- void SyncParkingStatus(int gunIndex)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].PreStatus = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status;
- }
- bool Is_Occupancy_Cancel(int gunIndex)
- {
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParentDispensetIndex;
- if((!ShmSysConfigAndInfo->SysInfo.OcppConnStatus && !ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.SelfReq) ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus == _DS_None ||
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus == _DS_Timeout)
- {
- return true;
- }
- return false;
- }
- void OccupancyRequest(int gunIndex)
- {
- int _action = 0;
- bool feeRequest = false;
- bool keepCounting = false;
- int res = FAIL;
- char _sn[37];
- unsigned char _status = 0;
- char *str_action[] = {STR_OCCUPANCY_ACT_NONE, STR_OCCUPANCY_ACT_DISPLAY, STR_OCCUPANCY_ACT_CANCEL, STR_OCCUPANCY_ACT_PAID_OK, STR_OCCUPANCY_ACT_PAID_NG};
- _status = ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status;
- if(Is_Ocpp_TcciOccupancyDisplayReq(gunIndex))
- {
- memset(_sn, 0x00, sizeof(_sn));
- _action = Get_Ocpp_TcciOccupancyAction(gunIndex, sizeof(_sn) - 1, _sn);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ActionId = _action;
- LOG_INFO("Gun %d OccupancyAction is [%s]", gunIndex + 1, str_action[_action]);
- Clean_Ocpp_TcciOccupancyDisplayReq(gunIndex);
- }
- if(ShmChargerInfo->ConnectorActReq[gunIndex].Flag.bits.ParkingFeeRequest)
- {
- feeRequest = true;
- ShmChargerInfo->ConnectorActReq[gunIndex].Flag.bits.ParkingFeeRequest =false;
- }
- if(Is_OccupancyKeepCountingReq(gunIndex))
- {
- if(_status == _Parking_WaitToPay)
- {
- keepCounting = true;
- }
- else
- {
- Clean_OccupancyKeepCountingReq(gunIndex);
- }
- }
- if(_status != _Parking_NoOccupancy && chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- if(!Is_OccupancyFeeForceCancelReq(gunIndex))
- {
- Set_OccupancyFeeForceCancelReq(gunIndex);
- Occupancy_INFO("Gun %d Need Force Cancel OccupancyStatus", gunIndex + 1);
- }
- }
- if(Is_OccupancyFeeForceCancelReq(gunIndex))
- {
- res = NotifyOccupancyFeeActRequest(gunIndex, _Notify_CancelOccupancyFee);
- if(res == PASS || res == FAIL)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- Clean_OccupancyFeeForceCancelReq(gunIndex);
- return;
- }
- else
- {
- // wait response
- }
- }
- switch(_status)
- {
- case _Parking_NoOccupancy:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [Clean]", gunIndex + 1);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex], 0x00, sizeof(OccupancyInfoData));
- SyncParkingStatus(gunIndex);
- }
- if(_action == _ParkingAction_DisplayButton)
- {
- memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Sn, _sn, sizeof(_sn));
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_SyncOccupancy;
- }
- break;
- case _Parking_SyncOccupancy:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [Sync]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- if(_action == _ParkingAction_DisplayButton)
- {
- memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Sn, _sn, sizeof(_sn));
- }
- else if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Preparing &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Charging)
- {
- if(OccupancyButtonSync(gunIndex) == PASS)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_Occupied;
- }
- }
- }
- break;
- case _Parking_Occupied:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [Start]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus, 0x00, sizeof(MiscRequestStatus));
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].ButtonReqStatus.MiscStatus = _BillStatus_MiscReq;
- }
- if(_action == _ParkingAction_DisplayButton)
- {
- memcpy(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyBill.Sn, _sn, sizeof(_sn));
- }
- else if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else if(_action == _ParkingAction_PaidOnlineFail)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineFail;
- }
- else
- {
- if(feeRequest)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_RequestFee;
- }
- }
- break;
- case _Parking_RequestFee:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [RequestFee]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- }
- if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else if(_action == _ParkingAction_PaidOnlineFail)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineFail;
- }
- else
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].OccupancyReq.bits.SelfReq)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_WaitToPay;
- }
- else
- {
- res = NotifyOccupancyFeeActRequest(gunIndex, _Notify_GetOccupancyFee);
- if(res == PASS)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_WaitToPay;
- }
- else if(res == FAIL)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else
- {
- // wait response
- }
- }
- }
- break;
- case _Parking_WaitToPay:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [WaitToPay]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- memset(&ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].BillReqStatus, 0x00, sizeof(MiscRequestStatus));
- _notifyOccupancyFeeAct[gunIndex] = _Notify_None;
- }
- if(_action == _ParkingAction_CancelOccupancy ||
- Is_Occupancy_Cancel(gunIndex))
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- else if(_action == _ParkingAction_PaidOnlineOK)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineOK;
- }
- else if(_action == _ParkingAction_PaidOnlineFail)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_PaidOnlineFail;
- }
- else if(keepCounting)
- {
- res = NotifyOccupancyFeeActRequest(gunIndex, _Notify_CancelLocalDeduction);
- if(res == PASS)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_Occupied;
- Clean_OccupancyKeepCountingReq(gunIndex);
- }
- else if(res == FAIL)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- Clean_OccupancyKeepCountingReq(gunIndex);
- }
- else
- {
- // wait response
- }
- }
- break;
- case _Parking_PaidOnlineOK:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [PaidOnlineOK]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- }
- if((GetTimeoutValue(_GetOccupancyFee_Time[gunIndex]) / uSEC_VAL) >= OCCUPANCY_FEE_TIMEOUT)
- {
- LOG_INFO("Gun %d Reset OccupancyStatus via PaidOnlineOK", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_NoOccupancy;
- }
- break;
- case _Parking_PaidOnlineFail:
- if(IsParkingStatusChanged(gunIndex))
- {
- Occupancy_INFO("Gun %d OccupancyStatus [PaidOnlineFail]", gunIndex + 1);
- SyncParkingStatus(gunIndex);
- GetClockTime(&_GetOccupancyFee_Time[gunIndex]);
- }
- if((GetTimeoutValue(_GetOccupancyFee_Time[gunIndex]) / uSEC_VAL) >= OCCUPANCY_FEE_TIMEOUT)
- {
- LOG_INFO("Gun %d Return to Occupied via PaidOnlineFail", gunIndex + 1);
- ShmChargerInfo->AllBill.OccupancyInfo[gunIndex].Status = _Parking_Occupied;
- }
- break;
- default:
- DisableConnectorBill(gunIndex);
- break;
- }
- }
- void CheckOccupancyFee(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- OccupancyRequest(i);
- }
- }
- #define OCCUPANCY_DEDUCT_IDLE 0
- #define OCCUPANCY_DEDUCT_REQUEST 1
- unsigned char _OccupancyDeductStatus = OCCUPANCY_DEDUCT_IDLE;
- int _OccupancyReportGunId = 0;
- void CheckOccupancyDeduct(void)
- {
- char cardNo[21];
- char appNo[10];
- if(_OccupancyDeductStatus == OCCUPANCY_DEDUCT_IDLE)
- {
- if(!Is_Ocpp_TcciReportOccupancyDeductReq())
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(Is_OccupancyDeductReq(i))
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[i].OccupancyReq.bits.SelfReq &&
- ShmChargerInfo->AllBill.OccupancyInfo[i].Status == _Parking_WaitToPay)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[i].Status = _Parking_NoOccupancy;
- LOG_INFO("Gun %d Occupancy Concluded!", i + 1);
- break;
- }
- Set_Ocpp_OccupancyDeductResult(&ShmChargerInfo->AllBill.OccupancyInfo[i].OccupancyDeduct, YES);
- Set_Ocpp_TcciReportOccupancyDeductReq();
- _OccupancyDeductStatus = OCCUPANCY_DEDUCT_REQUEST;
- _OccupancyReportGunId = i + 1;
- Clean_OccupancyDeductReq(i);
- break;
- }
- }
- if(_OccupancyDeductStatus != OCCUPANCY_DEDUCT_IDLE)
- {
- memset(cardNo, 0x00, sizeof(cardNo));
- memset(appNo, 0x00, sizeof(appNo));
- memcpy(cardNo, ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.creditNo, sizeof(ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.creditNo));
- memcpy(appNo, ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.ApprovalNumber, sizeof(ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.ApprovalNumber));
- LOG_INFO("Gun %d Occupancy Deduct [Request] Sn: [%s], Fee: [%.2f], CreditNo: [%s], ApprovalNo: [%s]",
- _OccupancyReportGunId,
- ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.Sn,
- ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].OccupancyDeduct.Fee,
- cardNo,
- appNo);
- }
- }
- }
- else
- {
- if(!Is_Ocpp_TcciReportOccupancyDeductReq())
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].Status == _Parking_WaitToPay)
- {
- ShmChargerInfo->AllBill.OccupancyInfo[_OccupancyReportGunId - 1].Status = _Parking_NoOccupancy;
- LOG_INFO("Gun %d OccupancyDeduct Request Completed!", _OccupancyReportGunId);
- }
- _OccupancyDeductStatus = OCCUPANCY_DEDUCT_IDLE;
- }
- }
- }
- void CheckDiagnosticsReq(void)
- {
- bool _DiagnosticsCompleted = true;
- int _DispenserId = 0;
- char _IpAddress[32];
- char cmdBuf[256] = {0};
- if(Is_Ocpp_GetDiagnosticsReq() || ShmChargerInfo->Control.Diagnostics.DiagnosticsType != DIAGNOSTICS_TYPE_NONE ||
- ShmSysConfigAndInfo->SysInfo.isDispenserLog)
- {
- // check dispenser status and set diagnostics request
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
- {
- _DispenserId = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex + 1;
- if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[_DispenserId - 1].bits.Request)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[_DispenserId - 1].CtrlValue = 0;
- sprintf((char*)_IpAddress, "%d.%d.%d.%d",
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) & 0xFF),
- ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) & 0xFF));
- sprintf(cmdBuf, "/root/Module_Diagnostics %d %s &", _DispenserId, _IpAddress);
- system(cmdBuf);
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[_DispenserId - 1].bits.Request = true;
- }
- if(!_NeedDiagnostics)
- {
- GetClockTime(&_Diagnostics_Time);
- LOG_INFO("Dispenser Need Diagnostics!");
- }
- _NeedDiagnostics = true;
- }
- }
- if(_NeedDiagnostics)
- {
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Stop)
- {
- if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Confirm)
- {
- if(GetSecTimeoutValue(_Diagnostics_Time) >= WAIT_DIAGNOSTICS_CONFIRM)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Stop = true;
- LOG_INFO("Wait Dispenser %d diagnostics confirm timeout!", i + 1);
- }
- _DiagnosticsCompleted = false;
- }
- else if(!ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Completed)
- {
- if(GetSecTimeoutValue(_Diagnostics_Time) >= WAIT_DIAGNOSTICS_TIMEOUT)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].bits.Stop = true;
- LOG_INFO("Wait Dispenser %d diagnostics completed timeout!", i + 1);
- }
- _DiagnosticsCompleted = false;
- }
- }
- }
- }
- }
- if(_DiagnosticsCompleted)
- {
- // diagnostics completed, clean ocpp GetDiagnosticsReq
- for(int i = 0; i < MAX_DISPENSER_QUANTITY; i++)
- {
- ShmChargerInfo->Control.Diagnostics.DispenserDiagnostics[i].CtrlValue = 0;
- }
- if(Is_Ocpp_GetDiagnosticsReq())
- {
- Clean_Ocpp_GetDiagnosticsReq();
- }
- if(ShmChargerInfo->Control.Diagnostics.DiagnosticsType != DIAGNOSTICS_TYPE_NONE)
- {
- ShmChargerInfo->Control.Diagnostics.DiagnosticsType = DIAGNOSTICS_TYPE_NONE;
- }
- if(ShmSysConfigAndInfo->SysInfo.isDispenserLog)
- {
- ShmSysConfigAndInfo->SysInfo.isDispenserLog = false;
- }
- LOG_INFO("Dispenser Diagnostics Completed!");
- }
- }
- else
- {
- _NeedDiagnostics = false;
- }
- }
- //===============================================
- // OCPP
- //===============================================
- void CheckOcppStatus()
- {
- if (Is_Ocpp_BootNotification())
- {
- Clean_Ocpp_BootNotification();
- LOG_INFO("*********************OCPP Boot Notification****************************");
- }
- if (Is_Ocpp_ResetReq())
- {
- 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 &&
- chargingInfo[_index]->SystemStatus != S_FAULT &&
- !(chargingInfo[_index]->SystemStatus == S_COMPLETE && ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Parameter.bits.PsuReleasable) &&
- !(chargingInfo[_index]->SystemStatus == S_ALARM && ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Parameter.bits.PsuReleasable))
- {
- canReset = false;
- //if (chargingInfo[_index]->SystemStatus >= S_REASSIGN && chargingInfo[_index]->SystemStatus < S_TERMINATING)
- //{
- // ChargingTerminalProcess(_index);
- //}
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- chargingInfo[_index]->ChargingStopFlag.bits.HardResetStop = true;
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- chargingInfo[_index]->ChargingStopFlag.bits.SoftResetStop = true;
- }
- }
- }
- }
- if(canReset)
- {
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- //trigger dispenser to hardware reboot
- TriggerDispenserHardwareReboot();
- if(IsDispenserHardwareRebootResponsed())
- {
- Clean_Ocpp_ResetReq();
- LOG_INFO("****** Hard Reboot ******");
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- sleep(5);
- system("reboot -f");
- }
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- //trigger dispenser to software reset
- TriggerDispenserSoftwareReset();
- if(IsDispenserSoftwareResetResponsed())
- {
- Clean_Ocpp_ResetReq();
- LOG_INFO("****** Soft Reboot ******");
- for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- sleep(5);
- Kill_Ocpp_Service();
- KillAllTask();
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- }
- }
- }
- }
- CheckOcppCostAndPrice();
- CheckLcmPageChangeRequest();
- CheckStationInfo();
- CheckWeatherInfo();
- CheckDeductResultRequest();
- CheckReDeductRequest();
- CheckReaderStatusRequest();
- CheckOccupancyPrice();
- CheckOccupancyFee();
- CheckOccupancyDeduct();
- CheckDiagnosticsReq();
- }
- void CheckoutStartChargingSoc(byte gunIndex, bool force)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.GetStartChargingSoc)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc > 0 || force)
- {
- chargingInfo[gunIndex]->EvBatteryStartSoc = chargingInfo[gunIndex]->EvBatterySoc;
- LOG_INFO("Gun %d StartSoc = %d", chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->EvBatteryStartSoc);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.GetStartChargingSoc = true;
- }
- }
- }
- void UpdateChargingTimestamp(char *timestamp)
- {
- struct timeb SeqEndTime;
- struct tm *tm;
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm = localtime(&SeqEndTime.time);
- sprintf(timestamp, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
- }
- void OcppStartTransaction(byte gunIndex)
- {
- if(_triggerTransaction[gunIndex])
- {
- return;
- }
- // clean deduct info
- Clean_DeductInfo(gunIndex);
- // set deduct user id
- //Set_Deduct_UserId(gunIndex, (char *)&chargingInfo[gunIndex]->StartUserId);
- // initial start & stop datetime
- strcpy((char *)chargingInfo[gunIndex]->StartDateTime, "00:00:00");
- strcpy((char *)chargingInfo[gunIndex]->StopDateTime, "00:00:00");
- Update_PowerConsumption(gunIndex);
- _lsatGunMeterValue[gunIndex] = chargingInfo[gunIndex]->PowerConsumption;
- Set_Ocpp_StartTransactionIdTag(gunIndex, (char *)chargingInfo[gunIndex]->StartUserId);
- LOG_INFO("Gun %d Start Transaction IdTag = %s, MeterValue: %.4f",
- chargingInfo[gunIndex]->Index + 1, chargingInfo[gunIndex]->StartUserId, chargingInfo[gunIndex]->PowerConsumption);
- Clean_Ocpp_StartTransactionConf(gunIndex);
- UpdateChargingTimestamp(ShmChargerInfo->Timestamp[gunIndex].StartCharging);
- Set_Ocpp_StartTransactionReq(gunIndex);
- // set _triggerTransaction
- _triggerTransaction[gunIndex] = true;
- }
- void OcppStopTransaction(byte gunIndex)
- {
- if(!_triggerTransaction[gunIndex])
- {
- return;
- }
- Update_PowerConsumption(gunIndex);
- _lsatGunMeterValue[gunIndex] = chargingInfo[gunIndex]->PowerConsumption;
- Set_Ocpp_StopTransactionId(gunIndex, (char *)chargingInfo[gunIndex]->StartUserId);
- LOG_INFO("Gun %d Stop Transaction IdTag = %s, StopSoc = %d, MeterValue: %.4f",
- chargingInfo[gunIndex]->Index + 1,
- chargingInfo[gunIndex]->StartUserId,
- chargingInfo[gunIndex]->EvBatterySoc,
- chargingInfo[gunIndex]->PowerConsumption);
- UpdateChargingTimestamp(ShmChargerInfo->Timestamp[gunIndex].StopCharging);
- Set_Ocpp_StopTransactionReq(gunIndex);
- // clean _triggerTransaction
- _triggerTransaction[gunIndex] = false;
- }
- bool Is_DispenserStop(byte gunIndex)
- {
- bool _isStop = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Preparing &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteStatus != _CRS_Charging)
- {
- _isStop = true;
- }
- return _isStop;
- }
- void ChkOcppStatus(byte gunIndex)
- {
- Chk_Ocpp_Backup_ErrorCode(gunIndex);
- if(Is_Ocpp_ReserveNowReq(gunIndex))
- {
- Clean_Ocpp_ReserveNowReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_IDLE && !Is_Ocpp_ReserveNowExpired(gunIndex))
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d OcppReservedStatus********************", gunIndex + 1);
- chargingInfo[gunIndex]->ReservationId = Get_Ocpp_ReserveNowId(gunIndex);
- setChargerMode(gunIndex, MODE_RESERVATION);
- }
- Set_Ocpp_ReserveNowConf(gunIndex);
- }
- if(Is_Ocpp_CancelReservationReq(gunIndex))
- {
- Clean_Ocpp_CancelReservationReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_RESERVATION)
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d Cancel OcppReservedStatus********************", gunIndex + 1);
- chargingInfo[gunIndex]->ReservationId = -1;
- setChargerMode(gunIndex, MODE_IDLE);
- }
- Set_Ocpp_CancelReservationConf(gunIndex);
- }
- if (Is_Ocpp_ChangeAvailabilityReq(gunIndex) == YES)
- {
- LOG_INFO("***************ChkOcppStatus: Gun %d OcppChangeAvailability********************", gunIndex + 1);
- Clean_Ocpp_ChangeAvailabilityReq(gunIndex);
- if(Chk_Ocpp_Availability_Type(gunIndex, "Operative"))
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, true);
- chargingInfo[gunIndex]->IsAvailable = YES;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_AVAILABILITY);
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_IDLE);
- }
- }
- else if(Chk_Ocpp_Availability_Type(gunIndex, "Inoperative"))
- {
- if (isDb_ready)
- DB_Update_Operactive(localDb, gunIndex, false);
- chargingInfo[gunIndex]->IsAvailable = NO;
- Set_Connector_MiscCommand(gunIndex, MISC_CONN_AVAILABILITY);
- if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
- chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
- chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
- {
- setChargerMode(gunIndex, MODE_MAINTAIN);
- }
- }
- }
- if (Is_Ocpp_UnlockConnectorReq(gunIndex))
- {
- Clean_Ocpp_UnlockConnectorReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_PREPARNING ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- // 充電中,需停止充電
- Set_Ocpp_StopReason(gunIndex, "UnlockCommand");
- //Set_Connector_MiscCommand(gunIndex, MISC_CONN_UNLOCK);
- chargingInfo[gunIndex]->ChargingStopFlag.bits.UnlockStop = true;
- LOG_INFO("********** OcppUnlockStop Gun %d **********", gunIndex + 1);
- }
- Set_Ocpp_UnlockConnectorConf(gunIndex);
- }
- if (Is_Ocpp_RemoteStopReq(gunIndex))
- {
- Clean_Ocpp_RemoteStopReq(gunIndex);
- if(chargingInfo[gunIndex]->SystemStatus == S_PREPARNING ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EV ||
- chargingInfo[gunIndex]->SystemStatus == S_PREPARING_FOR_EVSE ||
- chargingInfo[gunIndex]->SystemStatus == S_CHARGING)
- {
- Set_Ocpp_StopReason(gunIndex, "Remote");
- //Set_Connector_MiscCommand(gunIndex, MISC_CONN_REMOTE_STOP);
- chargingInfo[gunIndex]->ChargingStopFlag.bits.RemoteStop = true;
- LOG_INFO("********** OcppRemoteStop Gun %d **********", gunIndex + 1);
- }
- }
- if(Is_Ocpp_StartTransactionConf(gunIndex))
- {
- char acceptId[128] = {0};
- char status[32] = {0};
- Get_Ocpp_StartTransaction_Status(gunIndex, status);
- Get_Ocpp_TransactionId(gunIndex, acceptId);
- Set_Deduct_TransactionId(gunIndex, atoi(acceptId));
- Set_UserTransactionId(gunIndex, atoi(acceptId));
- LOG_INFO("Gun %d OCPP Start Transaction %s, TransactionId [%s]", gunIndex + 1, status, acceptId);
- if(!Is_Ocpp_StartTransaction_Accepted(gunIndex))
- {
- if(Is_Ocpp_StopOnInvalidId_Enable())
- {
- if(Is_Invalid_StartTransactionId(gunIndex))
- {
- chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop = true;
- LOG_INFO("Gun %d OCPP StopOnInvalidId", gunIndex + 1);
- }
- }
- LOG_INFO("Gun %d Transaction [%s] Not Accepted, %s",
- gunIndex + 1, acceptId,
- chargingInfo[gunIndex]->ChargingStopFlag.bits.InvalidIdStop > 0 ? "And Stop Charging" : "But StopOnInvalidId is Disable");
- }
- Clean_Ocpp_StartTransactionConf(gunIndex);
- }
- }
- 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;
- }
- bool IsReachConfigMaxChargingSoc(byte gunIndex)
- {
- bool result = false;
- if(ShmSysConfigAndInfo->SysConfig.MaxChargingSoc > 0)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc >= ShmSysConfigAndInfo->SysConfig.MaxChargingSoc)
- {
- LOG_INFO("Gun %d MaxChargingSoc: [%d%%] Stop", gunIndex + 1, ShmSysConfigAndInfo->SysConfig.MaxChargingSoc);
- result = true;
- }
- }
- return result;
- }
- bool CheckSessionTargetStop(byte gunIndex)
- {
- bool stop = false;
- struct StructSessionTarget target;
- Get_Ocpp_SessionTarget(gunIndex, &target);
- if(target.targetDuration > 0)
- {
- if(chargingInfo[gunIndex]->PresentChargedDuration >= (target.targetDuration * 60))
- {
- LOG_INFO("Gun %d SessionTarget(Duration) Stop, Present: %d (sec), Target: %d (min)",
- gunIndex + 1,
- chargingInfo[gunIndex]->PresentChargedDuration,
- target.targetDuration);
- stop = true;
- }
- }
- if(target.targetSoc > 0)
- {
- if(chargingInfo[gunIndex]->EvBatterySoc >= target.targetSoc)
- {
- LOG_INFO("Gun %d SessionTarget(SOC) Stop, Present: %d (%%), Target: %d (%%)",
- gunIndex + 1,
- chargingInfo[gunIndex]->EvBatterySoc,
- target.targetSoc);
- stop = true;
- }
- }
- if(target.targetEnergy > 0)
- {
- if(chargingInfo[gunIndex]->PresentChargedEnergy >= target.targetEnergy)
- {
- LOG_INFO("Gun %d SessionTarget(Energy) Stop, Present: %8.3f (kWh), Target: %4d (kWh)",
- gunIndex + 1,
- chargingInfo[gunIndex]->PresentChargedEnergy,
- target.targetEnergy);
- stop = true;
- }
- }
- if(stop)
- {
- chargingInfo[gunIndex]->ChargingStopFlag.bits.SessionTargetStop = true;
- }
- return stop;
- }
- 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++)
- {
- SetOcppErrorCode(gun_index, _error);
- }
- }
- void SetOcppErrorCode(unsigned char _index, char *errCode)
- {
- Set_Ocpp_StatusNotificationErrorCode(_index, errCode);
- strcpy((char *)_BackupStatusNotification[_index].ErrorCode, errCode);
- }
- void SetOcppVendorErrorCode(unsigned char _index, char *vendorCode)
- {
- Set_Ocpp_StatusNotificationVendorCode(_index, vendorCode);
- strcpy((char *)_BackupStatusNotification[_index].VendorErrorCode, vendorCode);
- }
- //===============================================
- // SQLite3 related routine
- //===============================================
- int NetworkDB_Open(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char* createNerRecordSql="CREATE TABLE IF NOT EXISTS network_record("
- "idx integer primary key AUTOINCREMENT, "
- "occurDatetime text NOT NULL, "
- "isInternet text NOT NULL, "
- "isOcppConnected text NOT NULL, "
- "isEth0Internet text NOT NULL, "
- "isMlan0Internet text NOT NULL, "
- "isPpp0Internet text NOT NULL, "
- "rssiMlan0 text NOT NULL, "
- "rssiPpp0 text NOT NULL"
- ");";
- //sqlite3_config(SQLITE_CONFIG_URI, 1);
- if(sqlite3_open(NETWORK_DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database (Net) : %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO("Local network status record database open successfully.");
- if (sqlite3_exec(db, createNerRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Create local network status record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("Opened local network status record table successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- 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, "
- "connector INTEGER"
- ");";
- 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* creatererrecordSql="CREATE TABLE IF NOT EXISTS `event_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`occurDatetime` TEXT NOT NULL, "
- "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
- char* createrebootSql="CREATE TABLE IF NOT EXISTS `reboot_record` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`rebootDatetime` TEXT NOT NULL, "
- "`model_name` TEXT, "
- "`serial_number` TEXT"
- "`version` TEXT, unique(rebootDatetime) on conflict replace);";
- char * createconsumptionSql = "CREATE TABLE IF NOT EXISTS `power_consumption` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
- char *createGunConsumptionSql = "CREATE TABLE IF NOT EXISTS `gun_consumption` ( "
- "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
- "`connector` INTEGER NOT NULL, "
- "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
- char *createFinalCostSql = "CREATE TABLE IF NOT EXISTS `final_cost` ( "
- "idx integer primary key AUTOINCREMENT, "
- "gun text, "
- "transactionId text, "
- "occurDatetime text, "
- "updateDatetime text, "
- "description text, "
- "updateStatus integer"
- ");";
- char *createOcmfRecordSql = "CREATE TABLE IF NOT EXISTS `ocmf_record` ( "
- "idx integer primary key AUTOINCREMENT, "
- "gun text, "
- "transactionId text, "
- "publicKey text, "
- "ocmfInfo text, "
- "updateStatus integer, "
- "occurDatetime text, "
- "updateDatetime text"
- ");";
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local charging record database open successfully.");
- if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local charging record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local charging record table successfully");
- }
- if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local config table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local config table successfully");
- }
- if (sqlite3_exec(db, creatererrecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create local record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened local record table successfully");
- }
- if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create reboot record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened reboot record table successfully");
- }
- if (sqlite3_exec(db, createconsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create power consumption record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened power consumption record table successfully");
- }
- if (sqlite3_exec(db, createGunConsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create gun consumption record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened gun consumption record table successfully");
- }
- if (sqlite3_exec(db, createFinalCostSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR( "Create final cost table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO( "Opened final cost table successfully");
- }
- if(sqlite3_exec(db, createOcmfRecordSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Create OCMF record table error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("Opened OCMF record table successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Record(sqlite3 *db, int gun_index)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- char transactionId[128];
- char reason[32];
- Get_Ocpp_TransactionId(gun_index, transactionId);
- Get_Ocpp_StopReason(gun_index, reason);
- sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, connector) "
- "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', %d);",
- chargingInfo[gun_index]->ReservationId,
- transactionId,
- 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,
- reason,
- gun_index + 1);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO( "Local charging record database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert local charging record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert local charging record successfully");
- }
- 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;
- LOG_ERROR("delete local charging error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete local charging record successfully");
- }
- 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;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local charging record database open successfully (%d).", IsAvailable);
- sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
- LOG_INFO("sqlStr= %s", sqlStr);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_INFO( "update config error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("update connector-%d config item isOperactive to %d", 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;
- LOG_ERROR( "Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO( "Local config query database open successfully.");
- 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;
- }
- LOG_INFO("Query connector-%d isOperactive: %s", gun_index, rs[(idxRow*cols)+3]);
- }
- }
- else
- {
- LOG_INFO("Query connector-%d fail, set default value to operactive.", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- void DB_Update_LocalConsumption(sqlite3 *db, uint8_t gun_index, float value)
- {
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sprintf(sqlStr, "insert or replace into power_consumption (connector, val) values(%d, %f);", gun_index, value);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update power_consumption error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
- }
- sqlite3_close(db);
- }
- }
- void DB_Update_GunConsumption(sqlite3 *db, uint8_t gun_index, float value)
- {
- char* errMsg = NULL;
- char sqlStr[1024];
- srand(time(NULL));
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sprintf(sqlStr, "insert or replace into gun_consumption (connector, val) values(%d, %f);", gun_index, value);
- if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update gun_consumption error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
- }
- sqlite3_close(db);
- }
- }
- float DB_Get_LocalConsumption(sqlite3 *db, uint8_t gun_index)
- {
- float result = 0;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from power_consumption where connector=%d;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("Local config query database open successfully.");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atof(rs[(idxRow * cols) + 2]);
- }
- }
- else
- {
- LOG_INFO("Query connector-%d fail, set default value to consumption.", gun_index);
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- float DB_Get_GunConsumption(sqlite3 *db, uint8_t gun_index)
- {
- float result = 0;
- char* errMsg = NULL;
- char sqlStr[1024];
- char **rs;
- int rows, cols;
- sprintf(sqlStr, "select * from gun_consumption where connector=%d;", gun_index);
- if (sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("Local config query database open successfully.");
- sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
- if (rows > 0)
- {
- for (int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atof(rs[(idxRow * cols) + 2]);
- }
- }
- else
- {
- LOG_INFO("Query gun %d fail, set -1 to gun consumption.", gun_index + 1);
- result = -1;
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- float Get_PowerConsumption(uint8_t gun_index)
- {
- float value = 0;
- //value = ShmChargerInfo->MeterValue[gun_index].GunConsumption >= 0 ?
- // ShmChargerInfo->MeterValue[gun_index].GunConsumption : ShmChargerInfo->MeterValue[gun_index].LocalConsumption;
- if(ShmChargerInfo->MeterValue[gun_index].GunConsumption >= 0)
- {
- if(!_useGunMeterValue[gun_index])
- {
- LOG_INFO("***** Gun %d Use GunMeterValue *****", gun_index + 1);
- }
- _useGunMeterValue[gun_index] = true;
- value = ShmChargerInfo->MeterValue[gun_index].GunConsumption;
- }
- else
- {
- value = ShmChargerInfo->MeterValue[gun_index].LocalConsumption;
- }
- return value;
- }
- void Update_PowerConsumption(uint8_t gun_index)
- {
- chargingInfo[gun_index]->PowerConsumption = Get_PowerConsumption(gun_index);
- }
- int DB_Insert_FinalCost(sqlite3 *db, uint8_t gun_index, int txId, char *description)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[1024];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(insertSql, "insert into final_cost(gun, transactionId, occurDatetime, updateDatetime, description, updateStatus) "
- "values('%d', '%d', '%s', '%s', '%s', '%d');",
- gun_index + 1,
- txId,
- timeBuf,
- "",
- description,
- BILL_SATAUS_UNDISPOSED);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("FinalCost database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert final_cost error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert final_cost successfully");
- }
- sprintf(insertSql, "delete from final_cost where idx < (select idx from final_cost order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete final_cost error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete final_cost successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_FinalCost_Status(sqlite3 *db, int txId, int status)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char updateSql[1024];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(updateSql, "update final_cost set updateStatus = %d, updateDatetime = '%s' where transactionId = '%d';",
- status,
- timeBuf,
- txId);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if(sqlite3_exec(db, updateSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update final_cost status error message: %s", errMsg);
- result = FAIL;
- }
- else
- {
- //LOG_INFO("update final_cost txId[%d] status %d ok", txId, status);
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Get_Undisposed_FinalCost(sqlite3 *db, int gunIndex, char *costString)
- {
- int txId = -1;
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- sprintf(sqlString, "select * from final_cost where updateStatus = -1 and gun = '%d' order by idx asc limit 1;",
- gunIndex + 1);
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- txId = atoi(rs[(idxRow * cols) + 2]);
- strcpy(costString, rs[(idxRow * cols) + 5]);
- }
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return txId;
- }
- void CheckInProgress(uint8_t gun_index)
- {
- if((ShmChargerInfo->Connector[gun_index].Status > S_IDLE && ShmChargerInfo->Connector[gun_index].Status <= S_FAULT) ||
- (ShmChargerInfo->Connector[gun_index].Status >= S_CCS_PRECHARGE_ST0 && ShmChargerInfo->Connector[gun_index].Status <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gun_index]->InProgress == NO)
- {
- LOG_INFO("Gun %d In Progress", gun_index + 1);
- }
- chargingInfo[gun_index]->InProgress = YES;
- }
- else
- {
- if(chargingInfo[gun_index]->InProgress == YES)
- {
- LOG_INFO("Gun %d Real Idle", gun_index + 1);
- }
- chargingInfo[gun_index]->InProgress = NO;
- }
- }
- void CheckDebugMode(uint8_t gun_index)
- {
- if(ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay)
- {
- if(chargingInfo[gun_index]->SystemStatus != S_DEBUG)
- {
- setChargerMode(gun_index, MODE_DEBUG);
- }
- }
- }
- int DB_Reboot_Record(sqlite3 *db)
- {
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[256];
- sprintf(insertSql, "insert into reboot_record(rebootDatetime, model_name, serial_number, version) values(CURRENT_TIMESTAMP, '%s', '%s', '%s_%s');",
- (char *)ShmSysConfigAndInfo->SysConfig.ModelName,
- (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber,
- fwVersion,
- subVersion);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- LOG_INFO("Local charging record database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert reboot record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert reboot record successfully");
- }
- sprintf(insertSql, "delete from reboot_record where idx < (select idx from reboot_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete reboot record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete reboot record successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Insert_Ocmf(sqlite3 *db, int gun_index, char *txId, char *ocmfKey, char *ocmfInfo)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char insertSql[3072];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(insertSql, "insert into ocmf_record(gun, transactionId, publicKey, ocmfInfo, updateStatus, occurDatetime, updateDatetime) "
- "values('%d', '%s', '%s', '%s', '%d', '%s', '%s');",
- gun_index + 1,
- txId,
- ocmfKey,
- ocmfInfo,
- OCMF_SATAUS_INSERTED,
- timeBuf,
- "");
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- //LOG_INFO("OCMF database open successfully.");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("Insert ocmf_record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("Insert ocmf_record successfully");
- }
- sprintf(insertSql, "delete from ocmf_record where idx < (select idx from ocmf_record order by idx desc limit 1)-2000;");
- if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("delete ocmf_record error message: %s", errMsg);
- }
- else
- {
- //LOG_INFO("delete ocmf_record successfully");
- }
- sqlite3_close(db);
- }
- return result;
- }
- int DB_Update_Ocmf_Status(sqlite3 *db, char *txId, int status)
- {
- char timeBuf[32];
- int result = PASS;
- char* errMsg = NULL;
- char updateSql[1024];
- getNowDatetime((unsigned char *)timeBuf);
- sprintf(updateSql, "update ocmf_record set updateStatus = %d, updateDatetime = '%s' where transactionId = '%s';",
- status,
- timeBuf,
- txId);
- if(sqlite3_open(DB_FILE, &db))
- {
- result = FAIL;
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- if(sqlite3_exec(db, updateSql, 0, 0, &errMsg) != SQLITE_OK)
- {
- LOG_ERROR("update updateStatus status error message: %s", errMsg);
- result = FAIL;
- }
- else
- {
- //LOG_INFO("update updateStatus txId[%s] status %d ok", txId, status);
- }
- sqlite3_close(db);
- }
- return result;
- }
- // return YES if exist undisposed ocmf
- int DB_Get_Undisposed_Ocmf(sqlite3 *db, int *gunIndex, char *txId, char *ocmfKey, char *ocmfInfo)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = NO;
- sprintf(sqlString, "select * from ocmf_record where updateStatus = 0 order by idx asc limit 1;");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- *gunIndex = atoi(rs[(idxRow * cols + 1)]) - 1;
- strncpy(txId, rs[(idxRow * cols) + 2], 36);
- strncpy(ocmfKey, rs[(idxRow * cols) + 3], 200);
- strcpy(ocmfInfo, rs[(idxRow * cols) + 4]);
- }
- result = YES;
- }
- sqlite3_free_table(rs);
- sqlite3_close(db);
- }
- return result;
- }
- void DB_TryAddRebootRecordColumn_Model(sqlite3 *db)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = 0;
- strcpy(sqlString, "select count(*) from pragma_table_info('reboot_record') where name = 'model_name';");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atoi(rs[(idxRow * cols) + 0]);
- }
- }
- sqlite3_free_table(rs);
- if(result == 0)
- {
- strcpy(sqlString, "ALTER TABLE 'reboot_record' ADD COLUMN 'model_name' TEXT;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("reboot_record add column 'model_name' error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("reboot_record ADD COLUMN 'model_name' successfully");
- }
- strcpy(sqlString, "ALTER TABLE 'reboot_record' ADD COLUMN 'serial_number' TEXT;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("reboot_record add column 'serial_number' error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("reboot_record ADD COLUMN 'serial_number' successfully");
- }
- }
- sqlite3_close(db);
- }
- }
- void DB_TryAddRebootRecordColumn_Version(sqlite3 *db)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = 0;
- strcpy(sqlString, "select count(*) from pragma_table_info('reboot_record') where name = 'version';");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atoi(rs[(idxRow * cols) + 0]);
- }
- }
- sqlite3_free_table(rs);
- if(result == 0)
- {
- strcpy(sqlString, "ALTER TABLE 'reboot_record' ADD COLUMN 'version' TEXT;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("reboot_record add column 'version' error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("reboot_record ADD COLUMN 'version' successfully");
- }
- }
- sqlite3_close(db);
- }
- }
- void DB_TryAddChargingRecordColumn(sqlite3 *db)
- {
- char **rs;
- int rows, cols;
- char* errMsg = NULL;
- char sqlString[1024];
- int result = 0;
- strcpy(sqlString, "select count(*) from pragma_table_info('charging_record') where name = 'connector';");
- if(sqlite3_open(DB_FILE, &db))
- {
- LOG_ERROR("Can't open database: %s", sqlite3_errmsg(db));
- sqlite3_close(db);
- }
- else
- {
- sqlite3_get_table(db, sqlString, &rs, &rows, &cols, &errMsg);
- if(rows > 0)
- {
- for(int idxRow = 1; idxRow <= rows; idxRow++)
- {
- result = atoi(rs[(idxRow * cols) + 0]);
- }
- }
- sqlite3_free_table(rs);
- if(result == 0)
- {
- strcpy(sqlString, "ALTER TABLE 'charging_record' ADD COLUMN 'connector' INTEGER;");
- if(sqlite3_exec(db, sqlString, 0, 0, &errMsg) != SQLITE_OK)
- {
- result = FAIL;
- LOG_ERROR("charging_record add column connector error message: %s", errMsg);
- }
- else
- {
- LOG_INFO("charging_record ADD COLUMN connector successfully");
- }
- }
- sqlite3_close(db);
- }
- }
- //===============================================
- // 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);
- // LOG_INFO("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))
- {
- LOG_INFO("tar file name : %s", 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);
- LOG_INFO("zip = %s \n", file);
- system(file);
- }
- }
- }
- }
- }
- // Close folder
- closedir(pDir);
- }
- void StopProcessingLoop()
- {
- for (;;)
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
- {
- ChkPrimaryStatus();
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 0)
- {
- LOG_INFO("Soft reboot for retry self-tets (Primary).");
- KillAllTask();
- sleep(3);
- TryCloseWatchdog();
- system("/usr/bin/run_evse_restart.sh");
- return;
- }
- }
- if(Is_Ocpp_ResetReq())
- {
- if(Chk_Ocpp_Reset_Type("Hard") || Chk_Ocpp_Reset_Type("Immediate"))
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
- }
- if(Chk_Ocpp_Reset_Type("Soft") || Chk_Ocpp_Reset_Type("OnIdle"))
- {
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
- }
- }
- CheckSoftHardReset();
- sleep(1);
- }
- }
- void CreateWatchdog(void)
- {
- wtdFd = InitWatchDog();
- if(wtdFd < 0)
- {
- LOG_INFO("Watchdog Initial Fail");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- else
- {
- LOG_INFO("Watchdog Initial Success");
- }
- }
- void TryCloseWatchdog(void)
- {
- if(wtdFd > 0)
- {
- write(wtdFd, "V", 1);
- close(wtdFd);
- }
- }
- void TryFeedWatchdog(void)
- {
- if(wtdFd > 0)
- {
- write(wtdFd, "a", 1);
- }
- }
- bool IsParallelCabinetIdle(void)
- {
- bool result = true;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- result = false;
- }
- return result;
- }
- bool IsStandbyEnable(void)
- {
- bool result = true;
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisableForTcc)
- {
- time_t timep;
- struct tm *tm;
- time(&timep);
- timep += (ShmChargerInfo->CabinetMiscValue.TimeOffset * 60);
- tm = localtime(&timep);
- if(tm->tm_hour >= 0 && tm->tm_hour < 8)
- {
- if(!_isStandbyEnable)
- {
- LOG_INFO("[TCC]Customer Enable Standby Function This Time[%02d:%02d:%02d], Offset[%d]",
- tm->tm_hour, tm->tm_min, tm->tm_sec, ShmChargerInfo->CabinetMiscValue.TimeOffset);
- }
- _isStandbyEnable = true;
- result = true;
- }
- else
- {
- if(_isStandbyEnable)
- {
- LOG_INFO("[TCC]Customer Disable Standby Function This Time[%02d:%02d:%02d], Offset[%d]",
- tm->tm_hour, tm->tm_min, tm->tm_sec, ShmChargerInfo->CabinetMiscValue.TimeOffset);
- }
- _isStandbyEnable = false;
- result = false;
- }
- }
- if(ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisable)
- {
- result = false;
- }
- return result;
- }
- bool IsGunIdle(int gunIndex, int idleType)
- {
- bool idle = true;
- if(chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
- chargingInfo[gunIndex]->ConnectorPlugIn &&
- idleType == GUN_IDLE_TYPE_WHOLE)
- {
- idle = false;
- }
- else if (chargingInfo[gunIndex]->SystemStatus != S_IDLE &&
- chargingInfo[gunIndex]->SystemStatus != S_RESERVATION &&
- chargingInfo[gunIndex]->SystemStatus != S_FAULT &&
- chargingInfo[gunIndex]->SystemStatus != S_MAINTAIN)
- {
- idle = false;
- }
- return idle;
- }
- bool IsDispenserIdle(int dispenserIndex)
- {
- bool dispenserIdle = true;
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- if(!IsGunIdle(gun, GUN_IDLE_TYPE_NORMAL))
- {
- dispenserIdle = false;
- break;
- }
- }
- return dispenserIdle;
- }
- bool IsConnectorWholeIdle(void)
- {
- bool result = true;
- for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if(!IsGunIdle(count, GUN_IDLE_TYPE_WHOLE))
- {
- result = false;
- break;
- }
- }
- return result;
- }
- bool IsUpgradeAvailable(void)
- {
- bool result = true;
- for(int count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
- {
- if(!IsGunIdle(count, GUN_IDLE_TYPE_NORMAL))
- {
- 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' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES)
- {
- if(system("pidof -s Module_4g > /dev/null") != 0 && ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable == false)
- {
- LOG_ERROR("Module_4g not running, restart it.");
- system("/root/Module_4g &");
- }
- }
- }
- if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
- {
- if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
- {
- if(system("pidof -s Module_Wifi > /dev/null") != 0 && ShmChargerInfo->Control.SysCtrl.bits.Wifi4gResetEnable == false)
- {
- LOG_ERROR("Module_Wifi not running, restart it.");
- system("/root/Module_Wifi &");
- }
- }
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
- {
- ShmChargerInfo->Control.SysCtrl.bits.BackendEnable = true;
- if((time((time_t*)NULL) - Get_Ocpp_procDogTime()) > 180)
- {
- LOG_ERROR("OcppBackend watch dog timeout task restart.");
- Clean_Ocpp_procDogTime();
- Kill_Ocpp_Service();
- }
- if(!Is_Ocpp_Task_Alive())
- {
- LOG_ERROR("OcppBackend not running, restart it.");
- Run_Ocpp_Service();
- }
- }
- else
- {
- ShmChargerInfo->Control.SysCtrl.bits.BackendEnable = false;
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE &&
- strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
- {
- if(!Is_MaintainOcpp_Task_Alive())
- {
- LOG_ERROR("Maintain Backend not running, restart it.");
- Run_MaintainOcpp_Service();
- }
- }
- if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
- {
- LOG_ERROR("Module_ProduceUtils not running, restart it.");
- system("/root/Module_ProduceUtils &");
- }
- if(system("pidof -s Module_EvComm > /dev/null") != 0)
- {
- LOG_ERROR("Module_EvComm not running, restart it.");
- system("/root/Module_EvComm &");
- }
- if(system("pidof -s Module_InternalComm > /dev/null") != 0)
- {
- LOG_ERROR("Module_InternalComm not running, restart it.");
- system("/root/Module_InternalComm &");
- }
- if(system("pidof -s Module_Firewall > /dev/null") != 0)
- {
- LOG_ERROR("Module_Firewall not running, restart it.");
- system("/root/Module_Firewall &");
- }
- if(!Is_WebServer_Alive())
- {
- LOG_ERROR("lighttpd not running, restart it.");
- Run_WebServer_Service();
- }
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE)
- {
- if(!Is_LocalPowerSharing_Alive())
- {
- LOG_ERROR("Module_PowerSharing not running, restart it.");
- Run_LocalPowerSharing_Service();
- }
- }
- }
- 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);
- }
- void InitialDispenserDhcpServerConfig(void)
- {
- system("echo 'start 192.168.100.10' > /etc/udhcpd_eth1.conf");
- system("echo 'end 192.168.100.20' >> /etc/udhcpd_eth1.conf");
- system("echo 'interface eth1' >> /etc/udhcpd_eth1.conf");
- system("echo 'opt dns 8.8.8.8' >> /etc/udhcpd_eth1.conf");
- system("echo 'option subnet 255.255.255.0' >> /etc/udhcpd_eth1.conf");
- system("echo 'opt router 192.168.100.1' >> /etc/udhcpd_eth1.conf");
- system("echo 'option domain local' >> /etc/udhcpd_eth1.conf");
- system("echo 'option lease 86400' >> /etc/udhcpd_eth1.conf");
- usleep(1000);
- }
- void StartDispenserDhcpServer(void)
- {
- system("pgrep -f \"udhcpd /etc/udhcpd_eth1.conf\" | xargs kill");
- system("/usr/sbin/udhcpd /etc/udhcpd_eth1.conf > /dev/null &");
- }
- //==========================================
- // Check Smart Charging Profile
- //==========================================
- void Ocpp_ProfileReq_Cmd(byte gunIndex)
- {
- if(!Is_Ocpp_ChargingProfileConf(gunIndex))
- {
- if(!Is_Ocpp_ChargingProfileReq(gunIndex))
- {
- Set_Ocpp_ChargingProfileReq(gunIndex);
- }
- }
- }
- 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 Ocpp_ChargingProfile_Process(byte _index)
- {
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- float _limit = 0;
- int _numberPhases = 0;
- if(Is_Ocpp_ChargingProfileKind(_index, "Absolute") && Is_Ocpp_ChargingProfileId(_index))
- {
- _maxCount = Get_Ocpp_ChargingProfileScheduleCount(_index);
- _startCount = Get_Ocpp_ChargingProfileStartIndex(_index);
- if(_startCount < _maxCount)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(_index, _startCount);
- _numberPhases = Get_Ocpp_ChargingProfileScheduleNumberPhases(_index, _startCount);
- chargingInfo[_index]->ChargingProfilePower = _limit * AC_OUTPUT_VOL * _numberPhases;
- if(chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
- (int)chargingInfo[_index]->PresentChargingVoltage > 0)
- {
- chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
- }
- else
- {
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- }
- else
- {
- chargingInfo[_index]->ChargingProfilePower = -1;
- chargingInfo[_index]->ChargingProfileCurrent = -1;
- }
- if((int)_lastProfilePower[_index] != (int)chargingInfo[_index]->ChargingProfilePower ||
- (int)_lastProfileCurrent[_index] != (int)chargingInfo[_index]->ChargingProfileCurrent)
- {
- _limit = Get_Ocpp_ChargingProfileScheduleLimit(_index, _startCount);
- LOG_INFO("Gun %d Get Profile - Index = %d, Limit = %f",
- _index + 1, _startCount, _limit);
- LOG_INFO("Max: %d kW, Gun %d ChargingProfile Power = %d, Current = %d",
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : ((int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000),
- _index + 1, (int)chargingInfo[_index]->ChargingProfilePower, (int)chargingInfo[_index]->ChargingProfileCurrent);
- }
- _lastProfilePower[_index] = chargingInfo[_index]->ChargingProfilePower;
- _lastProfileCurrent[_index] = chargingInfo[_index]->ChargingProfileCurrent;
- }
- void Ocpp_MaxChargingProfile_Process(void)
- {
- int _startCount = NO_DEFINE;
- int _maxCount = 0;
- float _limit = 0;
- int _numberPhases = 0;
- if(Is_Ocpp_MaxChargingProfileKind("Absolute") && Is_Ocpp_MaxChargingProfileId())
- {
- _maxCount = Get_Ocpp_MaxProfileScheduleCount();
- _startCount = Get_Ocpp_MaxProfileStartIndex();
- if(_startCount < _maxCount)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(_startCount);
- _numberPhases = Get_Ocpp_MaxProfileScheduleNumberPhases(_startCount);
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = _limit * AC_OUTPUT_VOL * _numberPhases;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
- }
- if((int)_lastMaxProfilePower != (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
- {
- _limit = Get_Ocpp_MaxProfileScheduleLimit(_startCount);
- LOG_INFO("Charger Get Max Profile - Index = %d, Limit = %f",
- _startCount, _limit);
- LOG_INFO("Charger Max Profile Power = %d", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower);
- }
- _lastMaxProfilePower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
- }
- void CheckSmartChargeProfile(byte _index)
- {
- if(Is_Ocpp_ChargingProfileConf(_index))
- {
- Clean_Ocpp_ChargingProfileConf(_index);
- Ocpp_MaxChargingProfile_Process();
- Ocpp_ChargingProfile_Process(_index);
- }
- }
- void GetLocalPowerLimit(byte gunIndex)
- {
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE)
- {
- if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer)
- {
- float _localLimitPower = ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent[gunIndex] * AC_OUTPUT_VOL;
- if(chargingInfo[gunIndex]->EvBatterytargetVoltage > 0 && (int)chargingInfo[gunIndex]->PresentChargingVoltage > 0)
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = _localLimitPower / chargingInfo[gunIndex]->PresentChargingVoltage;
- }
- else
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = -1;
- }
- }
- else
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = 0;
- }
- }
- else
- {
- chargingInfo[gunIndex]->LocalPowerLimitCurrent = -1;
- }
- }
- void TheEndCharging(byte gun_index)
- {
- chargingInfo[gun_index]->isRemoteStart = NO;
- if(strlen((char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL) > 0 && ShmChargerInfo->UserTransaction[gun_index].TransactionId > 0)
- {
- char receiptString[512];
- sprintf(receiptString, "%s%d",
- (char *)&ShmSysConfigAndInfo->SysConfig.OcppReceiptrURL[0], ShmChargerInfo->UserTransaction[gun_index].TransactionId);
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.ReceiptUrl[gun_index][0], receiptString);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_RECEIPT);
- LOG_INFO("Gun %d ReceiptrURL: [%s]", gun_index + 1, receiptString);
- }
- ChangeStartOrStopDateTime(NO, gun_index);
- DB_Insert_Record(localDb, gun_index);
- }
- void UpdateErrorCodeToOcpp(byte index)
- {
- //printf("ConnectorAlarmCode = %s \n", chargingInfo[index]->ConnectorAlarmCode);
- if (strcmp((char *)chargingInfo[index]->ConnectorAlarmCode, "") != EQUAL)
- {
- SetOcppErrorCode(index, "InternalError");
- SetOcppVendorErrorCode(index, (char *)chargingInfo[index]->ConnectorAlarmCode);
- }
- else if (strcmp((char *)chargingInfo[index]->EvConnAlarmCode, "") != EQUAL)
- {
- SetOcppErrorCode(index, "OtherError");
- SetOcppVendorErrorCode(index, (char *)chargingInfo[index]->EvConnAlarmCode);
- }
- }
- void CheckMiscCommandRequirement(void)
- {
- BOOL NeedAnnouncement = FALSE;
- unsigned char connector = 0;
- if(ShmSysConfigAndInfo->SysInfo.FirmwareUpdate != YES)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- NeedAnnouncement = FALSE;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
- {
- if(ShmChargerInfo->DispenserMiscReq[i].CtrlValue != 0)
- {
- NeedAnnouncement = TRUE;
- }
- for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
- {
- connector = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j] - 1;
- if(ShmChargerInfo->ConnectorMiscReq[connector].CtrlValue != 0)
- {
- NeedAnnouncement = TRUE;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.MiscNeedAnnouncement != NeedAnnouncement)
- {
- if(NeedAnnouncement)
- {
- //LOG_INFO("********** Dispenser %d Misc Command Need Announcement **********", i + 1);
- }
- else
- {
- //LOG_INFO("********** Dispenser %d Misc Command Announced **********", i + 1);
- }
- }
- }
- ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.MiscNeedAnnouncement = NeedAnnouncement;
- }
- }
- }
- void CheckDispenserVersionUpdateRequirement(void)
- {
- }
- bool IsReadyParalleling(void)
- {
- bool ready = true;
- for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
- {
- if(chargingInfo[i]->SystemStatus != S_IDLE && chargingInfo[i]->SystemStatus != S_MAINTAIN)
- {
- ready = false;
- break;
- }
- }
- return ready;
- }
- void SetParallelingStart(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(chargingInfo[i]->SystemStatus == S_IDLE)
- {
- setChargerMode(i, MODE_MAINTAIN);
- }
- }
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Wait;
- }
- void SetParallelingDone(void)
- {
- unsigned short totalPow = 0;
- totalPow = GetTotalParallelCabinetPower();
- if(totalPow != ShmChargerInfo->ParallelCabinet.TotalParallelPower)
- {
- LOG_INFO("Total Parallel Cabinet Power: %d.%d kW", (totalPow / 10), (totalPow % 10));
- }
- ShmChargerInfo->ParallelCabinet.TotalParallelPower = totalPow;
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_None;
- }
- void SetPCabinetOutputRelay(unsigned char index, unsigned char OnOff)
- {
- unsigned char relay = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle &&
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm)
- {
- relay = OnOff == YES ? YES : NO;
- if(ShmChargerInfo->ParallelCabinet.PCabinet[index].OutputRelaySetting[index] != relay)
- {
- LOG_INFO("Set Parallel Cabinet Gun %d Output Relay %s", index + 1, relay == YES ? "ON" : "OFF");
- }
- ShmChargerInfo->ParallelCabinet.PCabinet[i].OutputRelaySetting[index] = relay;
- }
- }
- }
- }
- void SetParallelCabinetAcContactor(unsigned char OnOff)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle &&
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm)
- {
- ShmChargerInfo->ParallelCabinet.PCabinet[i].AcContactorSetting = OnOff == YES ? YES : NO;
- }
- }
- }
- unsigned short GetTotalParallelCabinetPower(void)
- {
- unsigned short power = 0, slavePow = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- for(int i = 0; i < MAX_SLAVE_CABINET_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Idle ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Alarm ||
- ShmChargerInfo->ParallelCabinet.PCabinet[i].LocalStatus == _DS_Charging)
- {
- slavePow = ParsingRatingPower((char *)ShmChargerInfo->ParallelCabinet.PCabinet[i].ModelName);
- power += slavePow;
- }
- }
- }
- return power;
- }
- unsigned char preParallelStatus = 0;
- void MCabinetParallelingProcess(void)
- {
- bool PsuReInitial = false;
- unsigned char status = 0;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- if(IsReadyParalleling())
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelRequest)
- {
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelRequest = false;
- ShmChargerInfo->ParallelCabinet.PCabinet[i].ParallelConfirm = true;
- PsuReInitial = true;
- }
- }
- if(PsuReInitial)
- {
- SetParallelingStart();
- }
- }
- status = ShmChargerInfo->ParallelCabinet.ParallelStatus;
- switch(status)
- {
- case _Parallel_None:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [None]");
- GetClockTime(&_Parallel_Time);
- }
- unsigned short totalPow = 0;
- totalPow = GetTotalParallelCabinetPower();
- if(totalPow != ShmChargerInfo->ParallelCabinet.TotalParallelPower)
- {
- LOG_INFO("Total Parallel Cabinet Power: %d.%d kW", (totalPow / 10), (totalPow % 10));
- }
- ShmChargerInfo->ParallelCabinet.TotalParallelPower = totalPow;
- break;
- case _Parallel_Wait:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Wait]");
- SetAcContactor(OFF);
- SetParallelCabinetAcContactor(OFF);
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- SetPCabinetOutputRelay(i, OFF);
- }
- GetClockTime(&_Parallel_Time);
- }
- if((GetTimeoutValue(_Parallel_Time) / uSEC_VAL) >= PARALLEL_WAIT_TIME)
- {
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Working;
- }
- break;
- case _Parallel_Working:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Working]");
- SetAcContactor(ON);
- SetParallelCabinetAcContactor(ON);
- GetClockTime(&_Parallel_Time);
- }
- if(ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- ShmChargerInfo->ParallelCabinet.ParallelStatus = _Parallel_Done;
- }
- break;
- case _Parallel_Done:
- if(preParallelStatus != status)
- {
- LOG_INFO("MCabinet Parallel Status [Done]");
- GetClockTime(&_Parallel_Time);
- }
- if((GetTimeoutValue(_Parallel_Time) / uSEC_VAL) >= PARALLEL_WAIT_TIME)
- {
- SetParallelingDone();
- }
- break;
- }
- preParallelStatus = status;
- }
- }
- void SCabinetControllProcess(void)
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- if(ShmChargerInfo->SCabinetControl.SAcContactor)
- {
- SetAcContactor(ON);
- }
- else
- {
- SetAcContactor(OFF);
- }
- unsigned short _parallelRelay = 0;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- _parallelRelay = ShmChargerInfo->SCabinetControl.SParallelRelay[i] > 0 ? (1 < i) : 0;
- }
- if(_parallelRelay != ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue)
- {
- LOG_INFO("SCabinet Set Parallel Relay %X -> %X", ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue, _parallelRelay);
- }
- ShmChargerInfo->PsuGrouping.ParallelRelayConfig.CtrlValue = _parallelRelay;
- }
- }
- void CheckConnectorDisconnectionRecovery(unsigned char connector)
- {
- unsigned char dispenser = 0;
- dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].ParentDispensetIndex;
- if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
- {
- LOG_INFO("Connector %d Disconnection Recovery", connector + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].Parameter.bits.Disconnection = false;
- }
- }
- bool IsPsuResourceAvailable(unsigned char connector)
- {
- bool _available = true;
- if(ShmPsuGrouping->GroupCollection[connector].Role == _GROLE_NO_RESOURCE)
- {
- _available = false;
- }
- return _available;
- }
- int ConnectorRequestToCharging(unsigned char connector)
- {
- unsigned char role = 0;
- int result = WAIT;
- role = ShmPsuGrouping->GroupCollection[connector].Role;
- switch(role)
- {
- case _GROLE_IDLE:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.ChargingRequest)
- {
- LOG_INFO("Request Gun %d To Start Charging", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.ChargingRequest = true;
- break;
- case _GROLE_MASTER:
- result = PASS;
- break;
- case _GROLE_SLAVE:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.SlaveChargingRequest)
- {
- LOG_INFO("Gun %d Wait For Re-Grouping", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.SlaveChargingRequest = true;
- break;
- case _GROLE_REQUEST_TO_CHARGING:
- result = PASS;
- break;
- case _GROLE_DUMMY_MASTER:
- if(!ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.DummyMasterRequest)
- {
- LOG_INFO("Gun %d Wait For Dummy Master", connector + 1);
- }
- ShmPsuGrouping->GroupCollection[connector].GroupCtrl.bits.DummyMasterRequest = true;
- break;
- case _GROLE_DUMMY_FAULT:
- result = FAIL;
- break;
- default:
- break;
- }
- return result;
- }
- bool IsConnectorGroupingCompleted(unsigned char connector)
- {
- unsigned char role = 0;
- bool completed = false;
- role = ShmPsuGrouping->GroupCollection[connector].Role;
- switch(role)
- {
- case _GROLE_MASTER:
- completed = true;
- break;
- default:
- break;
- }
- return completed;
- }
- void SelfTestFailReason(void)
- {
- char reason[50];
- memset(reason, 0x00, sizeof(reason));
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip)
- {
- StatusCodeCompose(reason, "042251");
- }
- else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail)
- {
- StatusCodeCompose(reason, "042280");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail)
- {
- StatusCodeCompose(reason, "042281");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail)
- {
- StatusCodeCompose(reason, "042282");
- }
- }
- else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail ||
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail)
- {
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail)
- {
- StatusCodeCompose(reason, "042285");
- }
- if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail)
- {
- StatusCodeCompose(reason, "042286");
- }
- }
- else
- {
- StatusCodeCompose(reason, "Self Test Fail");
- }
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- SetOcppErrorCode(gun_index, "InternalError");
- SetOcppVendorErrorCode(gun_index, reason);
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- }
- bool IsAvailableBackToIdle(int gun_index)
- {
- if(_plugInHold[gun_index] == false &&
- (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable == false || chargingInfo[gun_index]->ConnectorPlugIn == false))
- {
- _plugInHold[gun_index] = true;
- GetClockTime(&_PlugInHold_Time[gun_index]);
- LOG_INFO ("Gun %d Plug In Hold Delay", gun_index + 1);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Idle ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable == false ||
- (!chargingInfo[gun_index]->ConnectorPlugIn && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm) ||
- isResetStopChargeFlag(gun_index) == YES)
- {
- if(!_plugInHold[gun_index])
- {
- _plugInHold[gun_index] = true;
- GetClockTime(&_PlugInHold_Time[gun_index]);
- LOG_INFO ("Force Gun %d Plug In Hold Delay", gun_index + 1);
- }
- if((GetTimeoutValue(_PlugInHold_Time[gun_index]) / uSEC_VAL) >= PLUG_IN_HOLD_TIME)
- {
- return true;
- }
- }
- return false;
- }
- void CheckGunAvailable(void)
- {
- if(ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- ShmChargerInfo->Control.GunAvailable[i] = IsPsuResourceAvailable(i) ? YES : NO;
- }
- }
- }
- int presentChargedEnergyClear(unsigned char gun_index)
- {
- int result = FAIL;
- chargingInfo[gun_index]->PresentChargedEnergy = 0;
- memset(chargingInfo[gun_index]->presentChargedEnergyPeriod, 0x00, ARRAY_SIZE(chargingInfo[gun_index]->presentChargedEnergyPeriod) * sizeof(float));
- result = PASS;
- return result;
- }
- float presentChargedEnergyTotal(unsigned char gun_index)
- {
- float result = 0.0f;
- for(int idx = 0; idx < ARRAY_SIZE(chargingInfo[gun_index]->presentChargedEnergyPeriod); idx++)
- {
- result += chargingInfo[gun_index]->presentChargedEnergyPeriod[idx];
- }
- return result;
- }
- int presentChargedEnergyUpdate(unsigned char gun_index, float kwh)
- {
- int result = FAIL;
- time_t CurrentTime;
- struct tm *tm;
- CurrentTime = time(NULL);
- tm=localtime(&CurrentTime);
- chargingInfo[gun_index]->presentChargedEnergyPeriod[tm->tm_hour] += kwh;
- return result;
- }
- void ChargedEnergySummation(unsigned char gun_index)
- {
- unsigned long time = 0;
- time = GetSecTimeoutValue(_ChargedEnergy_Time[gun_index]);
- if(time >= (chargingInfo[gun_index]->PresentChargedDuration + ENERAGY_INTERVAL))
- {
- chargingInfo[gun_index]->PresentChargedDuration++;
- float changedEnergy = 0;
- float _meterEnergy = 0;
- float _calChangingEnergy = (chargingInfo[gun_index]->PresentChargingPower) / 3600;
- if(ShmChargerInfo->MeterValue[gun_index].GunConsumption >= 0)
- {
- if(ShmChargerInfo->MeterValue[gun_index].GunConsumption >= _lsatGunMeterValue[gun_index])
- {
- _meterEnergy = ShmChargerInfo->MeterValue[gun_index].GunConsumption - _lsatGunMeterValue[gun_index];
- }
- else
- {
- _meterEnergy = 0;
- }
- changedEnergy = _meterEnergy;
- _lsatGunMeterValue[gun_index] = ShmChargerInfo->MeterValue[gun_index].GunConsumption;
- }
- else
- {
- changedEnergy = _calChangingEnergy;
- }
- if(ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
- {
- chargingInfo[gun_index]->ChargingFee += changedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
- }
- presentChargedEnergyUpdate(gun_index, changedEnergy);
- chargingInfo[gun_index]->PresentChargedEnergy += changedEnergy;
- ShmChargerInfo->MeterValue[gun_index].LocalConsumption += changedEnergy;
- }
- }
- void ChkConnectorAction(void)
- {
- for(int i = 0; i < CONNECTOR_QUANTITY; i++)
- {
- if(ShmChargerInfo->ConnectorActReq[i].Flag.bits.ChargingCancel)
- {
- if(ShmChargerInfo->AllBill.OccupancyInfo[i].Status != _Parking_WaitToPay)
- {
- LOG_INFO("Gun %d Charging Canceled", i + 1);
- Clean_Ocpp_TcciSerialNo(i);
- }
- else
- {
- LOG_INFO("Gun %d Occupancy Keep Counting", i + 1);
- Set_OccupancyKeepCountingReq(i);
- }
- ShmChargerInfo->ConnectorActReq[i].Flag.bits.ChargingCancel = false;
- }
- }
- }
- void Update_DispenserAvailability(int dispenserIndex)
- {
- for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
- {
- int gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
- Set_Connector_MiscCommand(gun, MISC_CONN_AVAILABILITY);
- }
- }
- void InitialDataBaseValue(void)
- {
- // Local DB
- if(DB_Open(localDb) != PASS)
- {
- LOG_INFO("DB_Open fail.");
- isDb_ready = false;
- }
- else
- {
- isDb_ready = true;
- DB_TryAddRebootRecordColumn_Model(localDb);
- DB_TryAddRebootRecordColumn_Version(localDb);
- DB_TryAddChargingRecordColumn(localDb);
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
- LOG_INFO("Gun %d IsAvailable Initial: [%s]", _index + 1, chargingInfo[_index]->IsAvailable == YES ? "Enable" : "Disable");
- }
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- ShmChargerInfo->MeterValue[_index].LocalConsumption = DB_Get_LocalConsumption(localDb, _index);
- LOG_INFO("Local Gun %d Consumption Initial: [%.4f kWh]", _index + 1, ShmChargerInfo->MeterValue[_index].LocalConsumption);
- }
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- ShmChargerInfo->MeterValue[_index].GunConsumption = DB_Get_GunConsumption(localDb, _index);
- LOG_INFO("Remote Gun %d Consumption Initial: [%.4f kWh]", _index + 1, ShmChargerInfo->MeterValue[_index].GunConsumption);
- }
- for(int _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- Update_PowerConsumption(_index);
- LOG_INFO("Gun %d Power Consumption Initial: [%.4f kWh]", _index + 1, chargingInfo[_index]->PowerConsumption);
- }
- DB_Reboot_Record(localDb);
- }
- if (NetworkDB_Open(networkDb) != PASS)
- {
- LOG_ERROR("NetworkDB_Open fail.");
- }
- }
- float CalculateMaxOutputRatio(int gunIndex)
- {
- float ratio = 0;
- int inUsingCnt = 0;
- for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
- {
- if(ShmChargerInfo->PsuGrouping.GroupCollection[i].Role == _GROLE_MASTER)
- {
- inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
- }
- }
- if(inUsingCnt != 0)
- {
- ratio = ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].Role == _GROLE_MASTER ?
- ((float)ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].GunPsuQuantity / inUsingCnt) : 0;
- }
- ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio = ratio;
- return ratio;
- }
- // return unit: 0.1kW
- unsigned short GetModelNameLimitPower(int gunIndex)
- {
- unsigned short limitPower = 0;
- float fPower = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmChargerInfo->Control.ChargerRatingPower != 0)
- {
- fPower = (float)ShmChargerInfo->Control.ChargerRatingPower / 10;
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_MASTER)
- {
- fPower += (float)ShmChargerInfo->ParallelCabinet.TotalParallelPower / 10;
- }
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- }
- return limitPower;
- }
- void GetWebPageConfigPowerLimit(int gunIndex)
- {
- unsigned short limitPower = 0;
- float fPower = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower != 0)
- {
- fPower = (float)ShmSysConfigAndInfo->SysConfig.MaxChargingPower;
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower = limitPower;
- }
- void GetWebPageConfigCurrentLimit(int gunIndex)
- {
- unsigned short limitCurrent = 0;
- float fCurrent = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent != 0)
- {
- fCurrent = (float)ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent;
- fCurrent = fCurrent * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitCurrent = (unsigned short)(fCurrent * 10);
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent = limitCurrent;
- }
- void GetOffLineMaxChargingPowerLimit(int gunIndex)
- {
- unsigned short limitPower = 0;
- float fPower = 0;
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmChargerInfo->OutputLimit.Offline_MaxChargingPower != 0 &&
- ShmStatusCodeData->InfoCode.InfoEvents.bits.BackendDisconnectedViaEthernet == YES)
- {
- fPower = ShmChargerInfo->OutputLimit.Offline_MaxChargingPower / 1000;
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- }
- ShmChargerInfo->OutputLimit.GunOfflineMaxPower[gunIndex] = limitPower * 100;
- }
- void GetMaxChargingProfileLimit(int gunIndex)
- {
- unsigned short limitPower = 0, limitCurrent = 0;
- float fPower = 0;
- // max charging profile
- if(ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio != 0 &&
- ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower >= 0)
- {
- fPower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000;
- fPower = fPower * ShmChargerInfo->PsuGrouping.GroupCollection[gunIndex].MaxOutputRatio;
- limitPower = (unsigned short)(fPower * 10);
- if (chargingInfo[gunIndex]->EvBatterytargetVoltage > 0 &&
- (int)chargingInfo[gunIndex]->PresentChargingVoltage > 0)
- {
- limitCurrent = (limitPower * 100 / chargingInfo[gunIndex]->PresentChargingVoltage) * 10;
- }
- }
- ShmChargerInfo->OutputLimit.GunMaxProfilePower[gunIndex] = limitPower * 100;
- ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex] = limitCurrent;
- }
- void GetMaxChargingLimit(int gunIndex)
- {
- GetWebPageConfigPowerLimit(gunIndex);
- GetWebPageConfigCurrentLimit(gunIndex);
- GetOffLineMaxChargingPowerLimit(gunIndex);
- GetMaxChargingProfileLimit(gunIndex);
- }
- void GetGunOtpDerating(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.deratingByConnOtp.isNeedDerating &&
- chargingInfo[gunIndex]->SystemStatus > S_IDLE &&
- chargingInfo[gunIndex]->SystemStatus <= S_CHARGING)
- {
- struct DERATING_BY_OTP *_derating;
- _derating = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.deratingByConnOtp;
- if(_derating->deratingIndex < GUN_DERATING_COUNT)
- {
- int _connectorTemp = (int)chargingInfo[gunIndex]->ConnectorTemp - 60;
- int _chillerTemp = (int)chargingInfo[gunIndex]->ChillerTemp - 60;
- if(_connectorTemp >= GunDeratingTemp[_derating->deratingIndex] &&
- chargingInfo[gunIndex]->ConnectorTemp != 0xFF &&
- _derating->deratingTargetCurrent[_derating->deratingIndex + 1] > 0)
- {
- LOG_INFO("Gun %d GunTemp %d is Derating(%d) to %d A",
- gunIndex + 1,
- _connectorTemp,
- GunDeratingTemp[_derating->deratingIndex],
- ((int)_derating->deratingTargetCurrent[_derating->deratingIndex + 1] / 10));
- _derating->deratingIndex++;
- }
- else if(_chillerTemp >= GunDeratingTemp[_derating->deratingIndex] &&
- chargingInfo[gunIndex]->ChillerTemp != 0xFF &&
- _derating->deratingTargetCurrent[_derating->deratingIndex + 1] > 0)
- {
- LOG_INFO("Gun %d ChillerTemp %d is Derating(%d) to %d A",
- gunIndex + 1,
- _chillerTemp,
- GunDeratingTemp[_derating->deratingIndex],
- ((int)_derating->deratingTargetCurrent[_derating->deratingIndex + 1] / 10));
- _derating->deratingIndex++;
- }
- }
- if(chargingInfo[gunIndex]->ConnectorTemp != 0xFF || chargingInfo[gunIndex]->ChillerTemp != 0xFF)
- {
- ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] = (int)_derating->deratingTargetCurrent[_derating->deratingIndex];
- ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] = 0;
- }
- else
- {
- ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] = 0;
- ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] = 0;
- }
- }
- else
- {
- ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] = 0;
- ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] = 0;
- }
- }
- void CalculateGunAbsMaxPower(int gunIndex)
- {
- int maxValue = 0;
- maxValue = (int)GetModelNameLimitPower(gunIndex);
- ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] = maxValue != 0 ? (maxValue * 100) : 0;
- }
- void CalculateGunAbsMaxVoltage(int gunIndex)
- {
- int maxValue = 0;
- maxValue = (int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalVoltage;
- ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex] = maxValue;
- }
- void CalculateGunAbsMaxCurrent(int gunIndex)
- {
- int maxValue = 0;
- maxValue = (int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalCurrent;
- ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex] = maxValue;
- }
- void RestrictChargingCapability(int gunIndex, unsigned short *power, unsigned short *voltage, unsigned short *current)
- {
- unsigned short limitPower = 0;
- int _limitPowerResult = 0;
- int _limitVoltageResult = 0;
- int _limitCurrentResult = 0;
- int _IndividualLimit = NO;
- _limitPowerResult = ShmPsuData->SystemAvailablePower;
- _limitVoltageResult = MAX_OUTPUT_VOLTAGE;
- _limitCurrentResult = ShmPsuData->SystemAvailableCurrent;
- if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunAbsoluteMaxPower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex] != 0 &&
- _limitVoltageResult > ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex])
- {
- _limitVoltageResult = ShmChargerInfo->OutputLimit.GunAbsoluteMaxVoltage[gunIndex];
- }
- if(ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex] != 0 &&
- _limitCurrentResult > ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex])
- {
- _limitCurrentResult = ShmChargerInfo->OutputLimit.GunAbsoluteMaxCurrent[gunIndex];
- }
- // restrict from WebPageConfig power
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower != 0)
- {
- if(_limitPowerResult > ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower)
- {
- _limitPowerResult = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingPower;
- }
- }
- // restrict from WebPageConfig current
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent != 0)
- {
- if(_limitCurrentResult > ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent)
- {
- _limitCurrentResult = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].MaxTotalChargingCurrent;
- }
- }
- // restrict from Offline_MaxChargingPower
- if(ShmChargerInfo->OutputLimit.GunOfflineMaxPower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunOfflineMaxPower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- // restrict from MaxChargingProfile
- if(ShmChargerInfo->OutputLimit.GunMaxProfilePower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunMaxProfilePower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- }
- }
- // restrict from MaxChargingProfile
- if(ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex] != 0)
- {
- if(_limitCurrentResult > ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex])
- {
- _limitCurrentResult = ShmChargerInfo->OutputLimit.GunMaxProfileCurrent[gunIndex];
- }
- }
- // restrict from ChargingProfile
- if((chargingInfo[gunIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gunIndex]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gunIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gunIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gunIndex]->ChargingProfilePower >= 0 && _limitPowerResult > ((int)chargingInfo[gunIndex]->ChargingProfilePower / 100))
- {
- _limitPowerResult = (int)chargingInfo[gunIndex]->ChargingProfilePower / 100;
- _IndividualLimit = true;
- }
- if(chargingInfo[gunIndex]->ChargingProfileCurrent >= 0 && _limitCurrentResult > (int)chargingInfo[gunIndex]->ChargingProfileCurrent)
- {
- _limitCurrentResult = (int)chargingInfo[gunIndex]->ChargingProfileCurrent;
- _IndividualLimit = true;
- }
- }
- // restrict from local power limit
- if(ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing > _SYS_POWER_SHARING_MODE_DISABLE)
- {
- if(chargingInfo[gunIndex]->LocalPowerLimitCurrent >= 0 && _limitCurrentResult > (int)(chargingInfo[gunIndex]->LocalPowerLimitCurrent * 10))
- {
- _limitCurrentResult = (int)(chargingInfo[gunIndex]->LocalPowerLimitCurrent * 10);
- _IndividualLimit = true;
- }
- }
- // restrict after otp
- if(ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] != 0)
- {
- limitPower = ShmChargerInfo->OutputLimit.GunOtpMaxPower[gunIndex] / 100;
- if(limitPower != 0 && _limitPowerResult > limitPower)
- {
- _limitPowerResult = limitPower;
- _IndividualLimit = true;
- }
- }
- // restrict after otp
- if(ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex] != 0 &&
- _limitCurrentResult > ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex])
- {
- _limitCurrentResult = ShmChargerInfo->OutputLimit.GunOtpMaxCurrent[gunIndex];
- _IndividualLimit = true;
- }
- ShmChargerInfo->OutputLimit.GunLimitPower[gunIndex] = _limitPowerResult;
- ShmChargerInfo->OutputLimit.GunLimitVoltage[gunIndex] = _limitVoltageResult;
- ShmChargerInfo->OutputLimit.GunLimitCurrent[gunIndex] = _limitCurrentResult;
- ShmChargerInfo->OutputLimit.IndividualLimit[gunIndex] = _IndividualLimit;
- if(_limitPowerResult != 0 && *power > _limitPowerResult)
- {
- *power = _limitPowerResult;
- }
- if(_limitVoltageResult != 0 && *voltage > _limitVoltageResult)
- {
- *voltage = _limitVoltageResult;
- }
- if(_limitCurrentResult != 0 && *current > _limitCurrentResult)
- {
- *current = _limitCurrentResult;
- }
- }
- void UpdateChargingCapability(void)
- {
- unsigned short voltage = 0, current = 0, power = 0;
- ShmChargerInfo->OutputLimit.Offline_MaxChargingPower = Get_Ocpp_OffLineMaxChargingPower();
- for(int i = 0; i < MAX_GUN_QUANTITY; i++)
- {
- voltage = (unsigned short)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.MaximumChargingVoltage;
- current = (unsigned short)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.AvailableChargingCurrent;
- power = (unsigned short)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.AvailableChargingPower;
- CalculateGunAbsMaxPower(i);
- CalculateGunAbsMaxVoltage(i);
- CalculateGunAbsMaxCurrent(i);
- CalculateMaxOutputRatio(i);
- GetMaxChargingLimit(i);
- GetLocalPowerLimit(i);
- GetGunOtpDerating(i);
- RestrictChargingCapability(i, &power, &voltage, ¤t);
- if((chargingInfo[i]->SystemStatus >= S_CHARGING && chargingInfo[i]->SystemStatus <= S_ALARM) ||
- (chargingInfo[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[i]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
- (chargingInfo[i]->SystemStatus == S_PREPARING_FOR_EVSE && ShmPsuGrouping->GroupCollection[i].GroupCtrl.bits.CableCheckDone))
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityVoltage = voltage;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityCurrent = current;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityPower = power;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityVoltage = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage > 0 ?
- (float)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage : (float)voltage;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityCurrent = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent > 0 ?
- (float)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent : (float)current;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].CapabilityPower = ShmPsuData->SystemAvailablePower > 0 ?
- (float)ShmPsuData->SystemAvailablePower : (float)power;
- }
- }
- }
- void GunErrorCollection(void)
- {
- bool _PsuNoResource = false;
- bool _ParallelRelayWelding = false;
- bool _ParallelRelayDrivingFault = false;
- bool _OutputRelayWelding = false;
- bool _OutputRelayDrivingFault = false;
- for(int i = 0; i < MAX_GUN_QUANTITY; i++)
- {
- if(ShmPsuData->Work_Step == INITIAL_START)
- {
- ShmChargerInfo->GunError[i].ErrFlag.bits.PsuGroupNoResource = false;
- }
- else
- {
- if(ShmChargerInfo->GunError[i].ErrFlag.bits.PsuGroupNoResource)
- {
- _PsuNoResource = true;
- }
- }
- if(ShmChargerInfo->GunError[i].ErrFlag.bits.ParallelRelayWelding)
- {
- _ParallelRelayWelding = true;
- }
- if(ShmChargerInfo->GunError[i].ErrFlag.bits.ParallelRelayDrivingFault)
- {
- _ParallelRelayDrivingFault = true;
- }
- if(ShmChargerInfo->GunError[i].ErrFlag.bits.OutputRelayWelding)
- {
- _OutputRelayWelding = true;
- }
- if(ShmChargerInfo->GunError[i].ErrFlag.bits.OutputRelayDrivingFault)
- {
- _OutputRelayDrivingFault = true;
- }
- }
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = _PsuNoResource;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = _ParallelRelayWelding;
- ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = _ParallelRelayDrivingFault;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.NormalOutputRelayWelding = _OutputRelayWelding;
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.NormalOutputRelayDrivingFault = _OutputRelayDrivingFault;
- }
- void UpdateGunPresentChargingPower(int gunIndex)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Enable)
- {
- chargingInfo[gunIndex]->PresentChargingPower = (((float)((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteChargingVoltage) * (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteChargingCurrent))) / 1000 / 100);
- }
- else
- {
- chargingInfo[gunIndex]->PresentChargingPower = ((float)((chargingInfo[gunIndex]->PresentChargingVoltage) * (chargingInfo[gunIndex]->PresentChargingCurrent)) / 1000);
- }
- }
- void CheckPsuLostQuantity(void)
- {
- if(ShmPsuData->Work_Step == _WORK_CHARGING)
- {
- if(ShmChargerInfo->Control.PsuQuantityByModel == ShmPsuData->SystemPresentPsuQuantity)
- {
- ShmStatusCodeData->InfoCode.InfoEvents.bits.PsuQuantityNotMatch = false;
- ShmSysConfigAndInfo->SysInfo.PsuLostQuantity = 0;
- }
- else
- {
- ShmSysConfigAndInfo->SysInfo.PsuLostQuantity = ShmChargerInfo->Control.PsuQuantityByModel > ShmPsuData->SystemPresentPsuQuantity ?
- (ShmChargerInfo->Control.PsuQuantityByModel - ShmPsuData->SystemPresentPsuQuantity) : 0;
- if(!ShmStatusCodeData->InfoCode.InfoEvents.bits.PsuQuantityNotMatch ||
- _psuLostQuantity != ShmSysConfigAndInfo->SysInfo.PsuLostQuantity)
- {
- LOG_INFO("Psu Quantity is %d, it should be %d, Psu Lost: %d",
- ShmPsuData->SystemPresentPsuQuantity, ShmChargerInfo->Control.PsuQuantityByModel,
- ShmSysConfigAndInfo->SysInfo.PsuLostQuantity);
- }
- ShmStatusCodeData->InfoCode.InfoEvents.bits.PsuQuantityNotMatch = true;
- _psuLostQuantity = ShmSysConfigAndInfo->SysInfo.PsuLostQuantity;
- }
- }
- }
- void CheckOcmfHandler(void)
- {
- bool _newOcmf = false;
- int _ocmfLength = 0;
- int _gunIndex = 0;
- char _txId[37];
- char _ocmfKey[201];
- char _ocmfInfo[2048];
- // check new ocmf info
- for(int i = 0; i < MAX_GUN_QUANTITY; i++)
- {
- if(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfFlag.bits.OcmfReceived)
- {
- _newOcmf = false;
- char fileName[256] = {0};
- sprintf(fileName, "/mnt/Gun_%d_%s_OCMF", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId);
- if(access(fileName, F_OK) != -1)
- {
- _newOcmf = true;
- }
- if(_newOcmf)
- {
- int fd = 0;
- fd = open(fileName, O_RDONLY);
- if(fd < 0)
- {
- LOG_INFO("Gun %d TxId[%s] OCMF file [%s] open fail", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, fileName);
- }
- else
- {
- memset(_txId, 0x00, sizeof(_txId));
- memset(_ocmfKey, 0x00, sizeof(_ocmfKey));
- memset(_ocmfInfo, 0x00, sizeof(_ocmfInfo)); //-48 is take out the header
- _ocmfLength = read(fd, _ocmfInfo, sizeof(_ocmfInfo) - 1);
- close(fd);
- memcpy(_txId, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId));
- memcpy(_ocmfKey, ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey));
- DB_Insert_Ocmf(localDb, i, _txId, _ocmfKey, _ocmfInfo);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfPending = true;
- char cmdBuf[256] = {0};
- sprintf(cmdBuf, "rm -f %s", fileName);
- system(cmdBuf);
- LOG_INFO("Gun %d TxId[%s] insert OCMF info ok, length: %d", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, _ocmfLength);
- }
- }
- else
- {
- LOG_INFO("Gun %d TxId[%s] OCMF info [%s] access fail", i + 1, ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, fileName);
- }
- memset(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId, 0x00, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfTxId));
- memset(ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey, 0x00, sizeof(ShmChargerInfo->OcmfInfo.GunOcmf[i].PublicKey));
- ShmChargerInfo->OcmfInfo.GunOcmf[i].OcmfFlag.bits.OcmfReceived = false;
- }
- }
- // try to find ocmf pending in database
- if(ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfPending && !ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload)
- {
- _gunIndex = 0;
- memset(_txId, 0x00, sizeof(_txId));
- memset(_ocmfKey, 0x00, sizeof(_ocmfKey));
- memset(_ocmfInfo, 0x00, sizeof(_ocmfInfo));
- ShmChargerInfo->OcmfInfo.SysOcmfIndex = 0;
- memset(ShmChargerInfo->OcmfInfo.SysOcmfTxId, 0x00, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfTxId));
- memset(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey, 0x00, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey));
- memset(ShmChargerInfo->OcmfInfo.SysOcmfInfo, 0x00, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfInfo));
- if(DB_Get_Undisposed_Ocmf(localDb, &_gunIndex, _txId, _ocmfKey, _ocmfInfo))
- {
- ShmChargerInfo->OcmfInfo.SysOcmfIndex = _gunIndex;
- memcpy(ShmChargerInfo->OcmfInfo.SysOcmfTxId, _txId, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfTxId));
- memcpy(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey, _ocmfKey, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfPublicKey));
- memcpy(ShmChargerInfo->OcmfInfo.SysOcmfInfo, _ocmfInfo, sizeof(ShmChargerInfo->OcmfInfo.SysOcmfInfo));
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload = true;
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = false;
- LOG_INFO("Gun %d TxId[%s] OCMF info need upload", _gunIndex + 1, _txId);
- }
- else
- {
- LOG_INFO("There is no ocmf info pending");
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.CtrlValue = 0;
- }
- }
- // try to upload ocmf to backend
- if(ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload)
- {
- if(ShmSysConfigAndInfo->SysInfo.OcppConnStatus)
- {
- if(!ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading)
- {
- if(!Is_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex))
- {
- Set_Ocpp_OcmfData(ShmChargerInfo->OcmfInfo.SysOcmfIndex, ShmChargerInfo->OcmfInfo.SysOcmfPublicKey, ShmChargerInfo->OcmfInfo.SysOcmfInfo);
- Set_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex);
- LOG_INFO("Set Gun %d TxId[%s] update OCMF request", ShmChargerInfo->OcmfInfo.SysOcmfIndex + 1, ShmChargerInfo->OcmfInfo.SysOcmfTxId);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = true;
- }
- }
- else
- {
- if(!Is_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex))
- {
- DB_Update_Ocmf_Status(localDb, ShmChargerInfo->OcmfInfo.SysOcmfTxId, OCMF_SATAUS_UPDATED_OK);
- LOG_INFO("Gun %d TxId[%s] update OCMF info to backend ok", ShmChargerInfo->OcmfInfo.SysOcmfIndex + 1, ShmChargerInfo->OcmfInfo.SysOcmfTxId);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfNeedUpload = false;
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = false;
- }
- }
- }
- else
- {
- if(ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading)
- {
- Clean_Ocpp_SendOcmfDataReq(ShmChargerInfo->OcmfInfo.SysOcmfIndex);
- LOG_INFO("Backend disconnected, Gun %d TxId[%s] ocmf will update later", ShmChargerInfo->OcmfInfo.SysOcmfIndex + 1, ShmChargerInfo->OcmfInfo.SysOcmfTxId);
- }
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfUploading = false;
- }
- }
- }
- int main(void)
- {
- unsigned long time = 0;
- int _dispenser = 0;
- _isStandbyEnable = true;
- if(CreateShareMemory() == 0)
- {
- #ifdef SystemLogMessage
- LOG_ERROR("CreatShareMemory NG");
- #endif
- if(ShmStatusCodeData!=NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- LOG_INFO("\n");
- LOG_INFO("===== Boot and Initialization start =====");
- LOG_INFO("Main Fork PID = %d", getpid());
- if (!InitialSystemDefaultConfig())
- {
- LOG_INFO("InitialSystemDefaultConfig NG");
- StopProcessingLoop();
- }
- LOG_INFO("ModelName: [%s], SN: [%s], SW Version: [%s][%s]",
- ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, fwVersion, subVersion);
- LOG_INFO("InitialShareMemoryInfo");
- InitialShareMemoryInfo();
- LOG_INFO("ChargerType (IEC or UL) = %d", ShmSysConfigAndInfo->SysInfo.ChargerType);
- if(!InitialChargerSetting())
- {
- isModelNameMatch = false;
- }
- Initialization();
- InitialDataBaseValue();
- LOG_INFO("Spawn all Task.");
- SpawnTask();
- if (!isModelNameMatch)
- {
- LOG_INFO("Module Name & HW info none match.");
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
- // Module Name 與硬體對應不正確
- LOG_ERROR("Module Name & HW info none match.");
- sleep(3);
- KillAllTask();
- StopProcessingLoop();
- }
- LOG_INFO("Module Name & HW info correct. Initialize.......");
- CreateTimeoutFork();
- SelfTestRun();
- while(ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
- {
- sleep(1);
- }
- if(ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
- {
- sleep(1);
- SelfTestFailReason();
- }
- else
- {
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_IDLE);
- CheckGunAvailable();
- }
- }
- if(ShmChargerInfo->Control.CabinetRole != _CROLE_SLAVE)
- {
- SetAcContactor(ON);
- SpawnOcppService();
- SpawnMaintainOcppService();
- }
- else
- {
- InitSlaveCabinetEthernet();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- }
- }
- sleep(1);
- CreateWatchdog();
- // Main loop
- LOG_INFO("%s \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_COMPLETE ?
- "****************************Main Loop**********************************" :
- "********************** SelfTest Fail **********************");
- GetClockTime(&_cmdMainPriority_time);
- ShmChargerInfo->OcmfInfo.SysOcmfFlag.bits.OcmfPending = true;
- for (;;)
- {
- CheckGunAvailable();
- CheckOcppStatus();
- ChkPrimaryStatus();
- ChkPsuStatus();
- PsuFailureResume();
- ChkConnectorAction();
- if(IsUpgradeAvailable())
- {
- CheckFactoryConfigFunction();
- CheckFwUpdateFunction();
- }
- if(CheckFlashUpdate() != YES)
- {
- // return fork process
- return 0;
- }
- CheckSoftHardReset();
- StandbyCheck();
- AuthorizeTimeoutProcess();
- // check ocmf request
- CheckOcmfHandler();
- // 當 AC 沒有搭上時,清除一些錯誤碼
- //ClearAlarmCodeWhenAcOff();
- if ((GetTimeoutValue(_cmdMainPriority_time) / uSEC_VAL) > MAIN_PRIORITY_INTERVAL)
- {
- CheckTask();
- for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
- {
- if((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if (chargingInfo[_index]->SystemStatus == S_CHARGING && _ocppProfileChkFlag[_index] == 12)
- {
- Ocpp_ProfileReq_Cmd(_index);
- gunOutputVol[_index] = chargingInfo[_index]->PresentChargingVoltage;
- _ocppProfileChkFlag[_index] = 0;
- }
- else if (chargingInfo[_index]->SystemStatus != S_CHARGING)
- {
- Ocpp_ProfileReq_Cmd(_index);
- _ocppProfileChkFlag[_index] = 0;
- }
- else
- {
- _ocppProfileChkFlag[_index]++;
- }
- }
- if (chargingInfo[_index]->SystemStatus >= SYS_MODE_CHARGING &&
- chargingInfo[_index]->SystemStatus <= SYS_MODE_ALARM)
- {
- DB_Update_LocalConsumption(localDb, _index, ShmChargerInfo->MeterValue[_index].LocalConsumption);
- if(ShmChargerInfo->MeterValue[_index].GunConsumption >= 0)
- {
- DB_Update_GunConsumption(localDb, _index, ShmChargerInfo->MeterValue[_index].GunConsumption);
- }
- }
- }
- CheckPsuLostQuantity();
- GetClockTime(&_cmdMainPriority_time);
- }
- CheckMiscCommandRequirement();
- CheckDispenserVersionUpdateRequirement();
- MCabinetParallelingProcess();
- SCabinetControllProcess();
- UpdateChargingCapability();
- GunErrorCollection();
- for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
- {
- //CheckGpioInStatus();
- CheckErrorOccurStatus(gun_index);
- ChkOcppStatus(gun_index);
- if((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
- (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
- {
- if(chargingInfo[gun_index]->SystemStatus == S_CHARGING)
- {
- // 進充電後,如果輸出電壓落差大於 10V 則直接繼續看 ChargingProfile
- if (chargingInfo[gun_index]->PresentChargingVoltage >= gunOutputVol[gun_index] + 10 ||
- chargingInfo[gun_index]->PresentChargingVoltage <= gunOutputVol[gun_index] - 10)
- {
- _ocppProfileChkFlag[gun_index] = 12;
- gunOutputVol[gun_index] = chargingInfo[gun_index]->PresentChargingVoltage;
- }
- }
- }
- CheckSmartChargeProfile(gun_index);
- Update_PowerConsumption(gun_index);
- CheckInProgress(gun_index);
- CheckDebugMode(gun_index);
- //LOG_INFO("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
- switch(chargingInfo[gun_index]->SystemStatus)
- {
- case S_MAINTAIN:
- if(isModeChange(gun_index))
- {
- if(ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- LOG_INFO("================== Slave Cabinet %d ==================", ShmChargerInfo->Control.CabinetSwitch - 1);
- }
- LOG_INFO("================== S_MAINTAIN (%x) ================== \n", gun_index + 1);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_AVAILABILITY);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- if(ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE ||
- ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE ||
- ShmChargerInfo->Control.CabinetRole == _CROLE_SLAVE)
- {
- break;
- }
- if(chargingInfo[gun_index]->IsAvailable == YES &&
- ShmChargerInfo->Control.GunAvailable[gun_index] == YES &&
- ShmChargerInfo->ParallelCabinet.ParallelStatus == _Parallel_None)
- {
- if(time >= MAINTAIN_RECOVERY_TIME)
- {
- Set_Connector_MiscCommand(gun_index, MISC_CONN_AVAILABILITY);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_RESERVATION:
- if(isModeChange(gun_index))
- {
- LOG_INFO("================== S_RESERVATION (%x) ================== \n", gun_index + 1);
- char expiryDate[128];
- Get_Ocpp_ReserveNowExpiryDate(gun_index, expiryDate);
- Get_Ocpp_ReserveNowIdTag(gun_index, &ShmChargerInfo->Control.ResevedIdTag[gun_index][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_RESERVATION);
- LOG_INFO("****** Reservation IdTag: [%s], Expiry: [%s]", &ShmChargerInfo->Control.ResevedIdTag[gun_index][0], expiryDate);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- if(chargingInfo[gun_index]->ConnectorPlugIn)
- {
- SetAcContactor(ON);
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Alarm ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- UpdateErrorCodeToOcpp(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- continue;
- }
- if(Is_Ocpp_ReserveNowExpired(gun_index))
- {
- chargingInfo[gun_index]->ReservationId = -1;
- LOG_INFO("Gun %d reservation is expired...", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else
- {
- if(IsConnectorAuthorizeSuccess(gun_index))
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- LOG_INFO("Gun %d remote start reserve charging", gun_index + 1);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RFID)
- {
- LOG_INFO("Gun %d swipe rfid start reserve charging", gun_index + 1);
- }
- setChargerMode(gun_index, MODE_AUTHORIZING);
- }
- else if(IsAutoGunSelectionAuthorizeSuccess(gun_index))
- {
- _dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
- if(Is_Ocpp_ReserveNowIdTag(gun_index, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId))
- {
- SetAcContactor(ON);
- if(chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId);
- LOG_INFO("Gun %d reserve Auto Selection, CardNumber = %s", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- if(strlen((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun_index], (char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_USER_PRICE_STRING);
- }
- DispenserAuthInitial(_dispenser);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- }
- }
- }
- else
- {
- if(chargingInfo[gun_index]->ReservationId == -1)
- {
- LOG_INFO("Gun %d reservation is clean", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- }
- break;
- case S_IDLE:
- case S_FAULT:
- {
- // clean PermissionRequest flag
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- if(isModeChange(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- LOG_INFO("================== S_IDLE (%x) ================== \n", gun_index + 1);
- chargingInfo[gun_index]->ReservationId = -1;
- _triggerTransaction[gun_index] = false;
- _plugInHold[gun_index] = false;
- 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, "");
- memset(ShmChargerInfo->Timestamp[gun_index].StartCharging, 0x00, sizeof(ShmChargerInfo->Timestamp[gun_index].StartCharging));
- memset(ShmChargerInfo->Timestamp[gun_index].StopCharging, 0x00, sizeof(ShmChargerInfo->Timestamp[gun_index].StopCharging));
- Clean_Ocpp_StopReason(gun_index);
- ReleaseAlarmCode(gun_index);
- // clean connector information
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingVoltage = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingCurrent = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteRemainChargingDuration = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteSoc = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].UserPrice = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].TotalCost = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AccountBalance = -65535;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].CostDiscount = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemainAmount = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].EnergyCost = -1;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParkingFee = -1;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AnnounceBalance = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.GetStartChargingSoc = false;
- memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo, 0x00, sizeof(AuthorizingInfoData));
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.OutputLimitEnable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].GeneralChargingData.deratingByConnOtp.deratingIndex = 0;
- chargingInfo[gun_index]->EvBatterytargetVoltage = 0;
- chargingInfo[gun_index]->EvBatterytargetCurrent = 0;
- chargingInfo[gun_index]->EvBatteryMaxVoltage = 0;
- chargingInfo[gun_index]->EvBatterySoc = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetVoltage = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetCurrent = 0;
- // clean RemoteStart & RemoteStop flag
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_REMOTE_START);
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_REMOTE_STOP);
- Clean_Connector_MiscCommand(gun_index, MISC_CONN_UNLOCK);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStopConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.UnlockStopConfirm = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NormalStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AlarmStopRequest = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest = false;
- ShmChargerInfo->GunError[gun_index].ErrFlag.ErrorValue = 0;
- memset(chargingInfo[gun_index]->ConnectorAlarmCode, 0x00, sizeof(chargingInfo[gun_index]->ConnectorAlarmCode));
- Clean_Ocpp_RunningCost(gun_index);
- Clean_Ocpp_FinalCost(gun_index);
- Clean_DeductInfo(gun_index);
- Clean_Ocpp_TcciSerialNo(gun_index);
- Clean_UserTransaction(gun_index);
- Clean_UserPriceAndReceipt(gun_index);
- presentChargedEnergyClear(gun_index);
- chargingInfo[gun_index]->PresentChargingPower = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower = 0;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent = 0;
- chargingInfo[gun_index]->ChargingProfilePower = -1;
- chargingInfo[gun_index]->ChargingProfileCurrent = -1;
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging = false;
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger = false;
- // reset dispenser availability
- Update_DispenserAvailability(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- }
- // clean force charging info
- memset(&ShmChargerInfo->Control.FCharging[gun_index], 0x00, sizeof(ForceCharging));
- }
- else if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- LOG_INFO("================== S_FAULT (%x) ================== \n", gun_index + 1);
- }
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- if (chargingInfo[gun_index]->IsAvailable == NO ||
- ShmChargerInfo->Control.GunAvailable[gun_index] == NO)
- {
- setChargerMode(gun_index, MODE_MAINTAIN);
- continue;
- }
- if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2 ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Alarm ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest ||
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest)
- {
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemotenAlarmCode, 6);
- }
- }
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.FaultStatusRequest = false;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "042304", 6);
- LOG_INFO("Connector %d Disconnect Occur", gun_index + 1);
- }
- }
- if(chargingInfo[gun_index]->SystemStatus != S_FAULT)
- {
- UpdateErrorCodeToOcpp(gun_index);
- setChargerMode(gun_index, MODE_FAULT);
- }
- else
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.Disconnection)
- {
- CheckConnectorDisconnectionRecovery(gun_index);
- }
- }
- }
- else
- {
- if (chargingInfo[gun_index]->SystemStatus == S_FAULT)
- {
- time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
- if(time >= FAULT_RELEASE_TIME)
- {
- ReleaseAlarmCode(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- break;
- }
- // clean stop charge flag
- chargingInfo[gun_index]->StopChargeFlag = false;
- chargingInfo[gun_index]->ChargingStopFlag.ChargingStopValue = 0;
- if(chargingInfo[gun_index]->ConnectorPlugIn || ShmChargerInfo->Control.CustomizedInfo.Flag.bits.StandbyTimeDisable)
- {
- SetAcContactor(ON);
- }
- { // Idle 正常程序起點
- // 判斷是否有啟用檢查插槍
- if(IsConnectorAuthorizeSuccess(gun_index))
- {
- if(chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE)
- {
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- LOG_INFO("Gun %d remote start charging", gun_index + 1);
- Clean_Ocpp_TcciCreditInfo(gun_index);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RFID)
- {
- LOG_INFO("Gun %d swipe rfid start charging", gun_index + 1);
- }
- Set_StartIdType(gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthIdType);
- setChargerMode(gun_index, MODE_AUTHORIZING);
- continue;
- }
- }
- else if(IsAutoGunSelectionAuthorizeSuccess(gun_index))
- {
- SetAcContactor(ON);
- if(chargingInfo[gun_index]->IsAvailable &&
- chargingInfo[gun_index]->SystemStatus == S_IDLE &&
- chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- _dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthId);
- LOG_INFO("Gun %d Auto Selection, CardNumber = %s", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- if(strlen((char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]) > 0)
- {
- strcpy((char *)&ShmChargerInfo->PriceAndReceiptInfo.UserPriceString[gun_index], (char *)&ShmChargerInfo->PriceAndReceiptInfo.DispenserPriceString[_dispenser][0]);
- Set_Connector_MiscCommand(gun_index, MISC_CONN_USER_PRICE_STRING);
- }
- Set_StartIdType(gun_index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[_dispenser].AuthInfo.AuthIdType);
- DispenserAuthInitial(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- continue;
- }
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging &&
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.StartForceCharging)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.StartForceCharging = false;
- strcpy((char *)chargingInfo[gun_index]->StartUserId, "ChargingTest");
- LOG_INFO("Gun %d Start Force Charging%s",
- gun_index + 1,
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger > 0 ? ", Triggered by WebAPI" : "");
- if(ShmChargerInfo->Control.TestCtrl.bits.FChargingReleaseExtend)
- {
- ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableReleaseAndExtend = true;
- LOG_INFO("Gun %d Enable ReleaseAndExtend At Force Charging", gun_index + 1);
- }
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.WebApiTrigger)
- {
- LOG_INFO("Set Dispenser %d Inoperative",
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex + 1);
- Update_DispenserAvailability(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ParentDispensetIndex);
- }
- Set_StartIdType(gun_index, _Type_Local);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- continue;
- }
- else
- {
- }
- } // Idle 正常程序終點
- }
- }
- break;
- case S_AUTHORIZING:
- if(isModeChange(gun_index))
- {
- LOG_INFO("================== S_AUTHORIZING (%x) ================== \n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- //StopSystemTimeoutDet();
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- SetAcContactor(ON);
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- }
- if(!_triggerTransaction[gun_index] &&
- ShmChargerInfo->Control.CustomerCode == _CUSTOMER_CODE_TCC &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].AuthInfo.AuthType == _AuthType_RemoteStart)
- {
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= STARTTRANSATION_TIME)
- {
- OcppStartTransaction(gun_index);
- }
- }
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= FORCE_BALANCE_TIME)
- {
- FouceAnnounceAccountBalance(gun_index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm)
- {
- // sync with dispenser
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.RemoteStartConfirm = false;
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- LOG_INFO("Sync with Gun %d through remote start", gun_index + 1);
- FouceAnnounceAccountBalance(gun_index);
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.SwipeRfidConfirm)
- {
- // sync with dispenser
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.SwipeRfidConfirm = false;
- GetClockTime(&_ConnectorAuthorizing_Time[gun_index]);
- LOG_INFO("Sync with Connector %d through swipe rfid", gun_index + 1);
- }
- if(GetTimeoutValue(_ConnectorAuthorizing_Time[gun_index]) / uSEC_VAL >= ShmChargerInfo->CabinetMiscValue.ConnectionTimeout)
- {
- if(!chargingInfo[gun_index]->ConnectorPlugIn)
- {
- LOG_INFO("*********** Gun %d Plug In Timeout ***********", gun_index + 1);
- }
- else
- {
- LOG_INFO("*********** Gun %d Preparing State Timeout ***********", gun_index + 1);
- }
- OcppStopTransaction(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else
- {
- if(chargingInfo[gun_index]->ConnectorPlugIn &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
- {
- AddPlugInTimes(gun_index);
- LOG_INFO("Gun %d CardNumber = [%s]", gun_index + 1, chargingInfo[gun_index]->StartUserId);
- setChargerMode(gun_index, MODE_REASSIGN_CHECK);
- GunAuthInitial(gun_index);
- }
- else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo)
- {
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
- LOG_INFO("*********** Gun %d User Stop Plug In ***********", gun_index + 1);
- OcppStopTransaction(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- else if(isEvBoardStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Alarm Stop (S_AUTHORIZING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_AUTHORIZING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_REASSIGN_CHECK:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_REASSIGN_CHECK (%x) ================== \n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
- if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
- ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
- //StopSystemTimeoutDet();
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy = ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy;
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration = ShmSysConfigAndInfo->SysConfig.MaxChargingDuration;
- LOG_INFO("Max Total Current %d A, Max Total Power %d kW, Total Energy %d kWh, Total Duration %d",
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
- ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy,
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration);
- SetAcContactor(ON);
- SetPCabinetOutputRelay(gun_index, ON);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- int isRequestOK = ConnectorRequestToCharging(gun_index);
- if(isRequestOK == PASS)
- {
- setChargerMode(gun_index, MODE_REASSIGN);
- }
- else if(time >= WAIT_REASSIGN_TIME || isRequestOK == FAIL)
- {
- if(isRequestOK == FAIL)
- {
- LOG_INFO("Gun %d Request To Charging Fail", gun_index + 1);
- }
- else if(ShmPsuData->Work_Step != _WORK_CHARGING)
- {
- LOG_INFO("Gun %d Wait PSU Work Step Timeout", gun_index + 1);
- }
- else
- {
- LOG_INFO("Gun %d Request Charging Timeout", gun_index + 1);
- }
- ShmChargerInfo->GunError[gun_index].ErrFlag.bits.PsuGroupNoResource = true;
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "042279", 6);
- LOG_INFO("Gun %d No Psu Resource", gun_index + 1);
- }
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingAlarmProcess(gun_index);
- //setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_REASSIGN:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_REASSIGN (%x) ================== \n", gun_index + 1);
- //gettimeofday(&_toAverage_time, NULL);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(IsConnectorGroupingCompleted(gun_index))
- {
- setChargerMode(gun_index, MODE_PRECHARGE);
- }
- else if(time >= MAX_REQUEST_CHARGING_TIME)
- {
- LOG_INFO("Gun %d Grouping Timeout", gun_index + 1);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_PREPARNING:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARNING (%x) ================== \n", gun_index + 1);
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
- SetAcContactor(ON);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if ((chargingInfo[gun_index]->AvailableChargingPower > 10) && time >= MIN_WAIT_PREPARNING_TIME)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
- break;;
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARNING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARNING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARNING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_PREPARNING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- if(time > GUN_PREPARE_TIMEOUT)
- {
- LOG_INFO("********** Gun %d PrepareTimeout **********", gun_index + 1);
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
- if(strncmp((char *)chargingInfo[gun_index]->ConnectorAlarmCode, "", 6) == EQUAL)
- {
- memcpy(chargingInfo[gun_index]->ConnectorAlarmCode, "042279", 6);
- LOG_INFO("Gun %d No Psu Resource", gun_index + 1);
- }
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingAlarmProcess(gun_index);
- }
- }
- break;
- case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARING_FOR_EV (%x) ================== \n", gun_index + 1);
- //strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest)
- {
- setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- LOG_INFO("Gun %d [Force Charging] S_PREPARING_FOR_EV OK", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PermissionRequest = true;
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARING_FOR_EV) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARING_FOR_EV) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARING_FOR_EV) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_PREPARING_FOR_EV) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- if(time >= GUN_EV_WAIT_TIMEOUT)
- {
- LOG_INFO("********** Gun %d Wait Dispenser Timeout **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_PREPARING_FOR_EVSE (%x) ================== \n", gun_index + 1);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- #ifdef STARTTRANSATION_IMMEDIATELY
- OcppStartTransaction(gun_index);
- #endif
- }
- CheckoutStartChargingSoc(gun_index, NO);
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- // only for test & debug purpose
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- if(time >= FORCE_CHARGING_CMD_DELAY)
- {
- float voltage = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetVoltage / 10;
- float current = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetCurrent / 10;
- if(chargingInfo[gun_index]->EvBatterytargetVoltage != voltage || chargingInfo[gun_index]->EvBatterytargetCurrent != current)
- {
- LOG_INFO("Gun %d Set Force Charging Voltage %4d V, Current: %4d A", gun_index + 1, (int)voltage, (int)current);
- }
- chargingInfo[gun_index]->EvBatterytargetVoltage = voltage;
- chargingInfo[gun_index]->EvBatterytargetCurrent = current;
- }
- }
- if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Charging)
- {
- setChargerMode(gun_index, MODE_CHARGING);
- }
- // only for test & debug purpose
- else if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- if(time >= FORCE_CHARGING_WAIT_EVSE)
- {
- LOG_INFO("Gun %d [Charging Simulation] S_PREPARING_FOR_EVSE OK", gun_index + 1);
- setChargerMode(gun_index, MODE_CHARGING);
- }
- }
- if (isEvBoardStopChargeFlag(gun_index) == YES)
- {
- // 板端或後臺要求停止
- LOG_INFO("********** Gun %d Alarm Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_PREPARING_FOR_EVSE) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_PREPARING_FOR_EVSE) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isInvalidIdStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d InvalidId Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "DeAuthorized");
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_PREPARING_FOR_EVSE) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- if(time >= GUN_EV_WAIT_TIMEOUT)
- {
- LOG_INFO("********** Gun %d GFD timeout **********", gun_index + 1);
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_CHARGING (%x) ================== \n", gun_index + 1);
- //StopGunInfoTimeoutDet(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- GetClockTime(&_ChargedEnergy_Time[gun_index]);
- CheckoutStartChargingSoc(gun_index, YES);
- chargingInfo[gun_index]->PresentChargedDuration = 0;
- ChangeStartOrStopDateTime(YES, gun_index);
- #ifndef STARTTRANSATION_IMMEDIATELY
- OcppStartTransaction(gun_index);
- #endif
- }
- // only for test & debug purpose
- if(ShmChargerInfo->Control.FCharging[gun_index].FCtrl.bits.EnableForceCharging)
- {
- float voltage = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetVoltage / 10;
- float current = (float)ShmChargerInfo->Control.FCharging[gun_index].FTargetCurrent / 10;
- if(chargingInfo[gun_index]->EvBatterytargetVoltage != voltage || chargingInfo[gun_index]->EvBatterytargetCurrent != current)
- {
- LOG_INFO("Gun %d Set Force Charging Voltage %4d V, Current: %4d A", gun_index + 1, (int)voltage, (int)current);
- }
- chargingInfo[gun_index]->EvBatterytargetVoltage = voltage;
- chargingInfo[gun_index]->EvBatterytargetCurrent = current;
- }
- // 計算 Power
- //chargingInfo[gun_index]->PresentChargingPower = ((float)((chargingInfo[gun_index]->PresentChargingVoltage) * (chargingInfo[gun_index]->PresentChargingCurrent)) / 1000);
- //chargingInfo[gun_index]->PresentChargingPower = (((float)((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingVoltage) * (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteChargingCurrent))) / 1000 / 100);
- UpdateGunPresentChargingPower(gun_index);
- ChargedEnergySummation(gun_index);
- CheckSessionTargetStop(gun_index);
- if (isEvBoardStopChargeFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Alarm Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "EVDisconnected");
- ChargingAlarmProcess(gun_index);
- }
- else if(isNormalStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Normal Stop (S_CHARGING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.ManualStop ? "(ManualStop)" : "");
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- else if(isResetStopChargeFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d Reset Stop (S_CHARGING) %s**********", gun_index + 1,
- chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "(Hard)" : "(Soft)");
- char *reason[16];
- strcpy((char *)&reason[0], chargingInfo[gun_index]->ChargingStopFlag.bits.HardResetStop ? "HardReset" : "SoftReset");
- Set_Ocpp_StopReason(gun_index, (char *)&reason[0]);
- ChargingTerminalProcess(gun_index);
- }
- else if(isInvalidIdStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d InvalidId Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "DeAuthorized");
- ChargingTerminalProcess(gun_index);
- }
- else if(CheckBackendChargingTimeout(gun_index) ||
- CheckBackendChargingEnergy(gun_index) ||
- IsReachConfigMaxChargingSoc(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Condition Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- else if(isSessionTargetStopFlag(gun_index) == YES)
- {
- LOG_INFO("********** Gun %d SessionTarget Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Other");
- ChargingTerminalProcess(gun_index);
- }
- else if(isBackendStopFlag(gun_index))
- {
- LOG_INFO("********** Gun %d Backend Stop (S_CHARGING) **********", gun_index + 1);
- Set_Ocpp_StopReason(gun_index, "Local");
- ChargingTerminalProcess(gun_index);
- }
- }
- break;
- case S_ALARM:
- case S_TERMINATING:
- {
- if (isModeChange(gun_index))
- {
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- Set_Ocpp_StopReason(gun_index, "Other");
- LOG_INFO("================== S_ALARM (%x) ================== \n", gun_index + 1);
- UpdateErrorCodeToOcpp(gun_index);
- TheEndCharging(gun_index);
- }
- else
- {
- Set_Ocpp_StopReason(gun_index, "Local");
- LOG_INFO("================== S_TERMINATING (%x) ================== \n", gun_index + 1);
- }
- //StopGunInfoTimeoutDet(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if((Is_DispenserStop(gun_index) && time >= STOP_TARTTRANSATION_DELAY) ||
- time >= WAIT_DISPENSER_STOP_TIMEOUT)
- {
- OcppStopTransaction(gun_index);
- }
- else
- {
- ChargedEnergySummation(gun_index);
- }
- if (chargingInfo[gun_index]->SystemStatus == S_ALARM)
- {
- if(time >= GUN_COMP_WAIT_TIMEOUT)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- LOG_INFO ("********** Gun %d psu is releasable **********\n", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- }
- }
- if(IsAvailableBackToIdle(gun_index) == YES &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- ReleaseAlarmCode(gun_index);
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- else
- {
- setChargerMode(gun_index, MODE_COMPLETE);
- }
- }
- break;
- case S_COMPLETE:
- {
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_COMPLETE (%x) ================== \n", gun_index + 1);
- TheEndCharging(gun_index);
- GetClockTime(&_SystemStatus_Time[gun_index]);
- }
- UpdateGunPresentChargingPower(gun_index);
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
- if((Is_DispenserStop(gun_index) && time >= STOP_TARTTRANSATION_DELAY) ||
- time >= WAIT_DISPENSER_STOP_TIMEOUT)
- {
- OcppStopTransaction(gun_index);
- }
- else
- {
- ChargedEnergySummation(gun_index);
- }
- if(time >= GUN_COMP_WAIT_TIMEOUT)
- {
- if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- LOG_INFO ("********** Gun %d psu is releasable **********", gun_index + 1);
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = true;
- }
- }
- if(IsAvailableBackToIdle(gun_index) == YES &&
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- }
- break;
- case S_CCS_PRECHARGE_ST0:
- if (isModeChange(gun_index))
- {
- LOG_INFO("CCS Precharge Processing 1....................%x \n", gun_index);
- //StopGunInfoTimeoutDet(gun_index);
- //StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
- }
- break;
- case S_CCS_PRECHARGE_ST1:
- if (isModeChange(gun_index))
- {
- LOG_INFO("CCS Precharge Processing 2....................%x \n", gun_index);
- }
- break;
- case S_DEBUG:
- if (isModeChange(gun_index))
- {
- LOG_INFO("================== S_DEBUG (%x) ================== \n", gun_index + 1);
- }
- if(!ShmChargerInfo->Control.RelayCtrl.bits.AbnormalRelay &&
- !ShmChargerInfo->Control.FanCtrl.bits.AbnormalFan)
- {
- setChargerMode(gun_index, MODE_IDLE);
- }
- break;
- }
- }
- TryFeedWatchdog();
- usleep(whileLoopTime);
- }
- return FAIL;
- }
|