MessageHandler.c 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *SecurityEventEnumTypeStr[] = {
  50. MACROSTR(FirmwareUpdated),
  51. MACROSTR(FailedToAuthenticateAtCsms),
  52. MACROSTR(CsmsFailedToAuthenticate),
  53. MACROSTR(SettingSystemTime),
  54. MACROSTR(StartupOfTheDevice),
  55. MACROSTR(ResetOrReboot),
  56. MACROSTR(SecurityLogWasCleared),
  57. MACROSTR(ReconfigurationOfSecurityParameters),
  58. MACROSTR(MemoryExhaustion),
  59. MACROSTR(InvalidMessages),
  60. MACROSTR(AttemptedReplayAttacks),
  61. MACROSTR(TamperDetectionActivated),
  62. MACROSTR(InvalidFirmwareSignature),
  63. MACROSTR(InvalidFirmwareSigningCertificate),
  64. MACROSTR(InvalidCsmsCertificate),
  65. MACROSTR(InvalidChargingStationCertificate),
  66. MACROSTR(InvalidTLSVersion),
  67. MACROSTR(InvalidTLSCipherSuite)
  68. };
  69. static char *CancelReservationStatusEnumTypeStr[] = {
  70. MACROSTR(Accepted),
  71. MACROSTR(Rejected)
  72. };
  73. static char *CertificateActionEnumTypeStr[] = {
  74. MACROSTR(Install),
  75. MACROSTR(Update)
  76. };
  77. static char *CertificateSignedStatusEnumTypeStr[] = {
  78. MACROSTR(Accepted),
  79. MACROSTR(Rejected)
  80. };
  81. static char *CertificateSigningUseEnumTypeStr[] = {
  82. MACROSTR(ChargingStationCertificate),
  83. MACROSTR(V2GCertificate)
  84. };
  85. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  86. MACROSTR(Accepted),
  87. MACROSTR(Rejected),
  88. MACROSTR(Scheduled)
  89. };
  90. #if 0
  91. static char *ChargingLimitSourceEnumTypeStr[] = {
  92. MACROSTR(EMS),
  93. MACROSTR(Other),
  94. MACROSTR(SO),
  95. MACROSTR(CSO)
  96. };
  97. #endif
  98. static char *ChargingProfileKindEnumTypeStr[] = {
  99. MACROSTR(Absolute),
  100. MACROSTR(Recurring),
  101. MACROSTR(Relative)
  102. };
  103. static char *ChargingProfilePurposeEnumTypeStr[] = {
  104. MACROSTR(ChargingStationExternalConstraints),
  105. MACROSTR(ChargingStationMaxProfile),
  106. MACROSTR(TxDefaultProfile),
  107. MACROSTR(TxProfile)
  108. };
  109. static char *ChargingProfileStatusEnumTypeStr[] = {
  110. MACROSTR(Accepted),
  111. MACROSTR(Rejected)
  112. };
  113. static char *ChargingRateUnitEnumTypeStr[] = {
  114. MACROSTR(W),
  115. MACROSTR(A)
  116. };
  117. static char *ChargingStateEnumTypeStr[] = {
  118. MACROSTR(Charging),
  119. MACROSTR(EVConnected),
  120. MACROSTR(SuspendedEV),
  121. MACROSTR(SuspendedEVSE),
  122. MACROSTR(Idle)
  123. };
  124. static char *ClearCacheStatusEnumTypeStr[] = {
  125. MACROSTR(Accepted),
  126. MACROSTR(Rejected)
  127. };
  128. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  129. MACROSTR(Accepted),
  130. MACROSTR(Unknown)
  131. };
  132. static char *ClearMessageStatusEnumTypeStr[] = {
  133. MACROSTR(Accepted),
  134. MACROSTR(Unknown)
  135. };
  136. static char *ClearMonitoringStatusEnumTypeStr[] = {
  137. MACROSTR(Accepted),
  138. MACROSTR(Rejected),
  139. MACROSTR(NotFound)
  140. };
  141. static char *ComponentCriterionEnumTypeStr[] = {
  142. MACROSTR(Active),
  143. MACROSTR(Available),
  144. MACROSTR(Enabled),
  145. MACROSTR(Problem)
  146. };
  147. #if 0
  148. static char *ConnectorEnumTypeStr[] = {
  149. MACROSTR(cCCS1),
  150. MACROSTR(cCCS2),
  151. MACROSTR(cG105),
  152. MACROSTR(cTesla),
  153. MACROSTR(cType1),
  154. MACROSTR(cType2),
  155. MACROSTR(s309-1P-16A),
  156. MACROSTR(s309-1P-32A),
  157. MACROSTR(s309-3P-16A),
  158. MACROSTR(s309-3P-32A),
  159. MACROSTR(sBS1361),
  160. MACROSTR(sCEE-7-7),
  161. MACROSTR(sType2),
  162. MACROSTR(sType3),
  163. MACROSTR(Other1PhMax16A),
  164. MACROSTR(Other1PhOver16A),
  165. MACROSTR(Other3Ph),
  166. MACROSTR(Pan),
  167. MACROSTR(wInductive),
  168. MACROSTR(wResonant),
  169. MACROSTR(Undetermined),
  170. MACROSTR(Unknown)
  171. };
  172. #endif
  173. static char *ConnectorStatusEnumTypeStr[] = {
  174. MACROSTR(Available),
  175. MACROSTR(Occupied),
  176. MACROSTR(Reserved),
  177. MACROSTR(Unavailable),
  178. MACROSTR(Faulted)
  179. };
  180. #if 0
  181. static char *CostKindEnumTypeStr[] = {
  182. MACROSTR(CarbonDioxideEmission),
  183. MACROSTR(RelativePricePercentage),
  184. MACROSTR(RenewableGenerationPercentage)
  185. };
  186. #endif
  187. static char *CustomerInformationStatusEnumTypeStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(Invalid)
  191. };
  192. static char *DataEnumTypeStr[] = {
  193. MACROSTR(string),
  194. MACROSTR(decimal),
  195. MACROSTR(integer),
  196. MACROSTR(dateTime),
  197. MACROSTR(boolean),
  198. MACROSTR(OptionList),
  199. MACROSTR(SequenceList),
  200. MACROSTR(MemberList)
  201. };
  202. static char *DataTransferStatusEnumTypeStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected),
  205. MACROSTR(UnknownMessageId),
  206. MACROSTR(UnknownVendorId)
  207. };
  208. static char *DeleteCertificateStatusEnumTypeStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotFound)
  212. };
  213. static char *DisplayMessageStatusEnumTypeStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(NotSupportedMessageFormat),
  216. MACROSTR(Rejected),
  217. MACROSTR(NotSupportedPriority),
  218. MACROSTR(NotSupportedState),
  219. MACROSTR(UnknownTransaction)
  220. };
  221. #if 0
  222. static char *EnergyTransferModeEnumTypeStr[] = {
  223. MACROSTR(DC),
  224. MACROSTR(AC_single_phase),
  225. MACROSTR(AC_two_phase),
  226. MACROSTR(AC_three_phase)
  227. };
  228. #endif
  229. static char *EventNotificationEnumTypeStr[] = {
  230. MACROSTR(HardWiredNotification),
  231. MACROSTR(HardWiredMonitor),
  232. MACROSTR(PreconfiguredMonitor),
  233. MACROSTR(CustomMonitor)
  234. };
  235. static char *EventTriggerEnumTypeStr[] = {
  236. MACROSTR(Alerting),
  237. MACROSTR(Delta),
  238. MACROSTR(Periodic)
  239. };
  240. static char *FirmwareStatusEnumTypeStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(DownloadScheduled),
  245. MACROSTR(DownloadPaused),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed),
  250. MACROSTR(InstallRebooting),
  251. MACROSTR(InstallScheduled),
  252. MACROSTR(InstallVerificationFailed),
  253. MACROSTR(InvalidSignature),
  254. MACROSTR(SignatureVerified)
  255. };
  256. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotSupported),
  260. MACROSTR(EmptyResultSet)
  261. };
  262. static char *GenericStatusEnumTypeStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected)
  265. };
  266. static char *GetCertificateIdUseEnumTypeStr[] = {
  267. MACROSTR(V2GRootCertificate),
  268. MACROSTR(MORootCertificate),
  269. MACROSTR(CSMSRootCertificate),
  270. MACROSTR(V2GCertificateChain),
  271. MACROSTR(ManufacturerRootCertificate)
  272. };
  273. static char *GetCertificateStatusEnumTypeStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Failed)
  276. };
  277. static char *GetChargingProfileStatusEnumTypeStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(NoProfiles)
  280. };
  281. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Unknown)
  284. };
  285. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(NotFound)
  288. };
  289. static char *GetVariableStatusEnumTypeStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected),
  292. MACROSTR(UnknownComponent),
  293. MACROSTR(UnknownVariable),
  294. MACROSTR(NotSupportedAttributeType)
  295. };
  296. static char *HashAlgorithmEnumTypeStr[] = {
  297. MACROSTR(SHA256),
  298. MACROSTR(SHA384),
  299. MACROSTR(SHA512)
  300. };
  301. static char *IdTokenEnumTypeStr[] = {
  302. MACROSTR(Central),
  303. MACROSTR(eMAID),
  304. MACROSTR(ISO14443),
  305. MACROSTR(ISO15693),
  306. MACROSTR(KeyCode),
  307. MACROSTR(Local),
  308. MACROSTR(MacAddress),
  309. MACROSTR(NoAuthorization),
  310. };
  311. static char *InstallCertificateUseEnumTypeStr[] = {
  312. MACROSTR(V2GRootCertificate),
  313. MACROSTR(MORootCertificate),
  314. MACROSTR(CSMSRootCertificate),
  315. MACROSTR(ManufacturerRootCertificate)
  316. };
  317. static char *InstallCertificateStatusEnumTypeStr[]={
  318. MACROSTR(Accepted),
  319. MACROSTR(Failed),
  320. MACROSTR(Rejected)
  321. };
  322. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  323. MACROSTR(Accepted),
  324. MACROSTR(Failed)
  325. };
  326. static char *LocationEnumTypeStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char *LogEnumTypeStr[] = {
  334. MACROSTR(DiagnosticsLog),
  335. MACROSTR(SecurityLog)
  336. };
  337. static char *LogStatusEnumTypeStr[] = {
  338. MACROSTR(Accepted),
  339. MACROSTR(Rejected),
  340. MACROSTR(AcceptedCanceled)
  341. };
  342. static char *MeasurandEnumTypeStr[] = {
  343. MACROSTR(Current.Export),
  344. MACROSTR(Current.Import),
  345. MACROSTR(Current.Offered),
  346. MACROSTR(Energy.Active.Export.Register),
  347. MACROSTR(Energy.Active.Import.Register),
  348. MACROSTR(Energy.Reactive.Export.Register),
  349. MACROSTR(Energy.Reactive.Import.Register),
  350. MACROSTR(Energy.Active.Export.Interval),
  351. MACROSTR(Energy.Active.Import.Interval),
  352. MACROSTR(Energy.Active.Net),
  353. MACROSTR(Energy.Reactive.Export.Interval),
  354. MACROSTR(Energy.Reactive.Import.Interval),
  355. MACROSTR(Energy.Reactive.Net),
  356. MACROSTR(Energy.Apparent.Net),
  357. MACROSTR(Energy.Apparent.Import),
  358. MACROSTR(Energy.Apparent.Export),
  359. MACROSTR(Frequency),
  360. MACROSTR(Power.Active.Export),
  361. MACROSTR(Power.Active.Import),
  362. MACROSTR(Power.Factor),
  363. MACROSTR(Power.Offered),
  364. MACROSTR(Power.Reactive.Export),
  365. MACROSTR(Power.Reactive.Import),
  366. MACROSTR(SoC),
  367. MACROSTR(Voltage)
  368. };
  369. static char *MessageFormatEnumTypeStr[] = {
  370. MACROSTR(ASCII),
  371. MACROSTR(HTML),
  372. MACROSTR(URI),
  373. MACROSTR(UTF8)
  374. };
  375. static char *MessagePriorityEnumTypeStr[] = {
  376. MACROSTR(AlwaysFront),
  377. MACROSTR(InFront),
  378. MACROSTR(NormalCycle)
  379. };
  380. static char *MessageStateEnumTypeStr[] = {
  381. MACROSTR(Charging),
  382. MACROSTR(Faulted),
  383. MACROSTR(Idle),
  384. MACROSTR(Unavailable)
  385. };
  386. static char *MessageTriggerEnumTypeStr[] = {
  387. MACROSTR(BootNotification),
  388. MACROSTR(LogStatusNotification),
  389. MACROSTR(FirmwareStatusNotification),
  390. MACROSTR(Heartbeat),
  391. MACROSTR(MeterValues),
  392. MACROSTR(SignChargingStationCertificate),
  393. MACROSTR(SignV2GCertificate),
  394. MACROSTR(StatusNotification),
  395. MACROSTR(TransactionEvent),
  396. MACROSTR(SignCombinedCertificate),
  397. MACROSTR(PublishFirmwareStatusNotification)
  398. };
  399. static char *MonitorEnumTypeStr[] = {
  400. MACROSTR(UpperThreshold),
  401. MACROSTR(LowerThreshold),
  402. MACROSTR(Delta),
  403. MACROSTR(Periodic),
  404. MACROSTR(PeriodicClockAligned)
  405. };
  406. static char *MonitoringBaseEnumTypeStr[] = {
  407. MACROSTR(All),
  408. MACROSTR(FactoryDefault),
  409. MACROSTR(HardWiredOnly)
  410. };
  411. static char *MonitoringCriterionEnumTypeStr[] = {
  412. MACROSTR(ThresholdMonitoring),
  413. MACROSTR(DeltaMonitoring),
  414. MACROSTR(PeriodicMonitoring)
  415. };
  416. static char *MutabilityEnumTypeStr[] = {
  417. MACROSTR(ReadOnly),
  418. MACROSTR(WriteOnly),
  419. MACROSTR(ReadWrite)
  420. };
  421. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected),
  424. MACROSTR(Processing)
  425. };
  426. static char *OCPPInterfaceEnumTypeStr[] = {
  427. MACROSTR(Wired0),
  428. MACROSTR(Wired1),
  429. MACROSTR(Wired2),
  430. MACROSTR(Wired3),
  431. MACROSTR(Wireless0),
  432. MACROSTR(Wireless1),
  433. MACROSTR(Wireless2),
  434. MACROSTR(Wireless3)
  435. };
  436. static char *OCPPTransportEnumTypeStr[] = {
  437. MACROSTR(JSON),
  438. MACROSTR(SOAP)
  439. };
  440. static char *OCPPVersionEnumTypeStr[] = {
  441. MACROSTR(OCPP12),
  442. MACROSTR(OCPP15),
  443. MACROSTR(OCPP16),
  444. MACROSTR(OCPP20)
  445. };
  446. static char *OperationalStatusEnumTypeStr[] = {
  447. MACROSTR(Inoperative),
  448. MACROSTR(Operative)
  449. };
  450. static char *PhaseEnumTypeStr[] = {
  451. MACROSTR(L1),
  452. MACROSTR(L2),
  453. MACROSTR(L3),
  454. MACROSTR(N),
  455. MACROSTR(L1-N),
  456. MACROSTR(L2-N),
  457. MACROSTR(L3-N),
  458. MACROSTR(L1-L2),
  459. MACROSTR(L2-L3),
  460. MACROSTR(L3-L1)
  461. };
  462. static char *PublishFirmwareStatusEnumTypeStr[] = {
  463. MACROSTR(Downloaded),
  464. MACROSTR(DownloadFailed),
  465. MACROSTR(Downloading),
  466. MACROSTR(DownloadScheduled),
  467. MACROSTR(DownloadPaused),
  468. MACROSTR(PublishFailed),
  469. MACROSTR(Published),
  470. MACROSTR(InvalidChecksum),
  471. MACROSTR(ChecksumVerified)
  472. };
  473. static char *ReadingContextEnumTypeStr[] = {
  474. MACROSTR(Interruption.Begin),
  475. MACROSTR(Interruption.End),
  476. MACROSTR(Other),
  477. MACROSTR(Sample.Clock),
  478. MACROSTR(Sample.Periodic),
  479. MACROSTR(Transaction.Begin),
  480. MACROSTR(Transaction.End),
  481. MACROSTR(Trigger)
  482. };
  483. #if 0
  484. static char *ReasonEnumTypeStr[] = {
  485. MACROSTR(DeAuthorized),
  486. MACROSTR(EmergencyStop),
  487. MACROSTR(EnergyLimitReached),
  488. MACROSTR(EVDisconnected),
  489. MACROSTR(GroundFault),
  490. MACROSTR(ImmediateReset),
  491. MACROSTR(Local),
  492. MACROSTR(LocalOutOfCredit),
  493. MACROSTR(MasterPass),
  494. MACROSTR(Other),
  495. MACROSTR(OvercurrentFault),
  496. MACROSTR(PowerLoss),
  497. MACROSTR(PowerQuality),
  498. MACROSTR(Reboot),
  499. MACROSTR(Remote),
  500. MACROSTR(SOCLimitReached),
  501. MACROSTR(StoppedByEV),
  502. MACROSTR(TimeLimitReached),
  503. MACROSTR(TimeLimitReached)
  504. };
  505. #endif
  506. static char *RecurrencyKindEnumTypeStr[] = {
  507. MACROSTR(Daily),
  508. MACROSTR(Weekly)
  509. };
  510. static char *RegistrationStatusEnumTypeStr[] = {
  511. MACROSTR(Accepted),
  512. MACROSTR(Pending),
  513. MACROSTR(Rejected)
  514. };
  515. static char *ReportBaseEnumTypeStr[] = {
  516. MACROSTR(ConfigurationInventory),
  517. MACROSTR(FullInventory),
  518. MACROSTR(SummaryInventory)
  519. };
  520. static char *RequestStartStopStatusEnumTypeStr[] = {
  521. MACROSTR(Accepted),
  522. MACROSTR(Rejected)
  523. };
  524. static char *ReservationUpdateStatusEnumTypeStr[] = {
  525. MACROSTR(Expired),
  526. MACROSTR(Removed)
  527. };
  528. static char *ReserveNowStatusEnumTypeStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Faulted),
  531. MACROSTR(Occupied),
  532. MACROSTR(Rejected),
  533. MACROSTR(Unavailable)
  534. };
  535. static char *ResetEnumTypeStr[] = {
  536. MACROSTR(Immediate),
  537. MACROSTR(OnIdle)
  538. };
  539. static char *ResetStatusEnumTypeStr[] = {
  540. MACROSTR(Accepted),
  541. MACROSTR(Rejected),
  542. MACROSTR(Scheduled)
  543. };
  544. static char *SetMonitoringStatusEnumTypeStr[] = {
  545. MACROSTR(Accepted),
  546. MACROSTR(UnknownComponent),
  547. MACROSTR(UnknownVariable),
  548. MACROSTR(UnsupportedMonitorType),
  549. MACROSTR(Rejected),
  550. MACROSTR(OutOfRange),
  551. MACROSTR(Duplicate)
  552. };
  553. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  554. MACROSTR(Accepted),
  555. MACROSTR(Rejected),
  556. MACROSTR(Failed)
  557. };
  558. static char *SetVariableStatusEnumTypeStr[] = {
  559. MACROSTR(Accepted),
  560. MACROSTR(Rejected),
  561. MACROSTR(InvalidValue),
  562. MACROSTR(UnknownComponent),
  563. MACROSTR(UnknownVariable),
  564. MACROSTR(NotSupportedAttributeType),
  565. MACROSTR(OutOfRange),
  566. MACROSTR(RebootRequired)
  567. };
  568. static char *TransactionEventEnumTypeStr[] = {
  569. MACROSTR(Ended),
  570. MACROSTR(Started),
  571. MACROSTR(Updated)
  572. };
  573. static char *TriggerMessageStatusEnumTypeStr[] = {
  574. MACROSTR(Accepted),
  575. MACROSTR(Rejected),
  576. MACROSTR(NotImplemented)
  577. };
  578. static char *TriggerReasonEnumTypeStr[] = {
  579. MACROSTR(Authorized),
  580. MACROSTR(CablePluggedIn),
  581. MACROSTR(ChargingRateChanged),
  582. MACROSTR(ChargingStateChanged),
  583. MACROSTR(Deauthorized),
  584. MACROSTR(EnergyLimitReached),
  585. MACROSTR(EVCommunicationLost),
  586. MACROSTR(EVConnectTimeout),
  587. MACROSTR(MeterValueClock),
  588. MACROSTR(MeterValuePeriodic),
  589. MACROSTR(TimeLimitReached),
  590. MACROSTR(Trigger),
  591. MACROSTR(UnlockCommand),
  592. MACROSTR(StopAuthorized),
  593. MACROSTR(EVDeparted),
  594. MACROSTR(EVDetected),
  595. MACROSTR(RemoteStop),
  596. MACROSTR(RemoteStart),
  597. MACROSTR(AbnormalCondition),
  598. MACROSTR(SignedDataReceived),
  599. MACROSTR(ResetCommand)
  600. };
  601. static char *UnlockStatusEnumTypeStr[] = {
  602. MACROSTR(Unlocked),
  603. MACROSTR(UnlockFailed),
  604. MACROSTR(OngoingAuthorizedTransaction),
  605. MACROSTR(UnknownConnector)
  606. };
  607. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  608. MACROSTR(DownloadOngoing),
  609. MACROSTR(NoFirmware),
  610. MACROSTR(Unpublished)
  611. };
  612. static char *UpdateEnumTypeStr[] = {
  613. MACROSTR(Differential),
  614. MACROSTR(Full)
  615. };
  616. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  617. MACROSTR(Accepted),
  618. MACROSTR(Rejected),
  619. MACROSTR(AcceptedCanceled),
  620. MACROSTR(InvalidCertificate),
  621. MACROSTR(RevokedCertificate)
  622. };
  623. static char *UpdateStatusEnumTypeStr[] = {
  624. MACROSTR(Accepted),
  625. MACROSTR(Failed),
  626. MACROSTR(VersionMismatch)
  627. };
  628. static char *UploadLogStatusEnumTypeStr[] = {
  629. MACROSTR(BadMessage),
  630. MACROSTR(Idle),
  631. MACROSTR(NotSupportedOperation),
  632. MACROSTR(PermissionDenied),
  633. MACROSTR(Uploaded),
  634. MACROSTR(UploadFailure),
  635. MACROSTR(Uploading),
  636. MACROSTR(AcceptedCanceled)
  637. };
  638. static char *VPNEnumTypeStr[] = {
  639. MACROSTR(IKEv2),
  640. MACROSTR(IPSec),
  641. MACROSTR(L2TP),
  642. MACROSTR(PPTP)
  643. };
  644. #if 0
  645. static char *ChargePointErrorCodeEnumTypeStr[] = {
  646. MACROSTR(ConnectorLockFailure),
  647. MACROSTR(EVCommunicationError),
  648. MACROSTR(GroundFailure),
  649. MACROSTR(HighTemperature),
  650. MACROSTR(InternalError),
  651. MACROSTR(LocalListConflict),
  652. MACROSTR(NoError),
  653. MACROSTR(OtherError),
  654. MACROSTR(OverCurrentFailure),
  655. MACROSTR(OverVoltage),
  656. MACROSTR(PowerMeterFailure),
  657. MACROSTR(PowerSwitchFailure),
  658. MACROSTR(ReaderFailure),
  659. MACROSTR(ResetFailure),
  660. MACROSTR(UnderVoltage),
  661. MACROSTR(WeakSignal)
  662. };
  663. #endif
  664. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  665. MACROSTR(Accepted),
  666. MACROSTR(Rejected)
  667. };
  668. static char *RemoteStartStopStatusEnumTypeStr[] = {
  669. MACROSTR(Accepted),
  670. MACROSTR(Rejected)
  671. };
  672. #if 0
  673. static char * StopTransactionReasonEnumTypeStr[] = {
  674. MACROSTR(EmergencyStop),
  675. MACROSTR(EVDisconnected),
  676. MACROSTR(HardReset),
  677. MACROSTR(Local),
  678. MACROSTR(Other),
  679. MACROSTR(PowerLoss),
  680. MACROSTR(Reboot),
  681. MACROSTR(Remote),
  682. MACROSTR(SoftReset),
  683. MACROSTR(UnlockCommand),
  684. MACROSTR(DeAuthorized)
  685. };
  686. #endif
  687. //ChargePointMaxProfile
  688. #define ChargingStationMaxProfile_JSON "/Storage/OCPP/ChargingStationMaxProfile_OCPP20.json"
  689. //TxDefaultProfile
  690. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  691. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  692. struct StatusCodeData *ShmStatusCodeData;
  693. struct PsuData *ShmPsuData ;
  694. struct OCPP20Data *ShmOCPP20Data;
  695. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  696. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  697. //===============================
  698. // Gun Total Numbers
  699. //===============================
  700. static ParsingRatedCur modelnameInfo = {0};
  701. static int gunTotalNumber = 0;
  702. static uint8_t gunType[4] = {0};
  703. //===============================
  704. // Local List Version
  705. //===============================
  706. static int localversion=0;
  707. //===============================
  708. // Variable Version
  709. //===============================
  710. static int variableVersion=9;
  711. //===============================
  712. // OCPP sign variable
  713. //===============================
  714. static int server_sign = FALSE;
  715. int server_pending = FALSE;
  716. static int BootNotificationInterval = 10;
  717. //===============================
  718. // OCPP auth variable
  719. //===============================
  720. static int authorizeRetryTimes = 0; //number of Retry times
  721. //===============================
  722. // OCPP other variables
  723. //===============================
  724. static int HeartBeatWaitTime = 10;
  725. static int FirstHeartBeat = 0;
  726. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  727. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  728. static char CurrentChargingProfileScheduleStr[30] = {0};
  729. static int isCancelUploadLog = FALSE;
  730. pthread_t th_GetLog;
  731. //========================================
  732. // OCPP status/previous related variables
  733. //========================================
  734. static int GunStatusInterval = 10;
  735. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  736. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  737. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  738. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  739. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  740. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  741. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  742. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  743. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  744. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  745. static int TransactionMessageAttemptsValue = 0;
  746. static int TransactionMessageRetryIntervalValue = 0;
  747. static struct AuthorizationData idTagQuery;
  748. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  749. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  750. //=============================================
  751. // OCPP HeartBeat Response Not Receive Counts
  752. //============================================
  753. static int HeartBeatWithNOResponse = 0;
  754. static int HeartBeatCountPerHour = 0;
  755. sqlite3 *db;
  756. int TransactionMessageAttemptsGet(void);
  757. int TransactionMessageRetryIntervalGet(void);
  758. int GetOcppConnStatus(void);
  759. void SetOcppConnStatus(uint8_t status);
  760. int setKeyValue(char *key, char *value);
  761. void OCPP_get_TableAuthlocalAllData(void);
  762. void processUnkownKey(void);
  763. struct InterLock
  764. {
  765. unsigned char isGetLogGoing:1;
  766. unsigned char isUpdateFirmwareGoing:1;
  767. }interLock;
  768. struct ClientTime
  769. {
  770. struct timespec Heartbeat;
  771. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  772. struct timespec StartTransaction;
  773. struct timespec StopTransaction;
  774. struct timespec MeterValues[CONNECTOR_QUANTITY];
  775. struct timespec SampledDataTxEnded[CONNECTOR_QUANTITY];
  776. struct timespec RemoteStartWait;
  777. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  778. }clientTime;
  779. typedef union
  780. {
  781. //Operations Initiated by Central System
  782. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  783. struct
  784. {
  785. //CsMsgValue[0]
  786. unsigned char StatusNotificationReq:1; //bit 0,
  787. unsigned char StatusNotificationConf:1; //bit 1,
  788. unsigned char TriggerMeterValueReq:1; //bit 2,
  789. unsigned char SampleMeterReq:1; //bit 3,
  790. unsigned char ClockAlignMeterReq:1; //bit 4,
  791. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  792. unsigned char isOnCharging:1; //bit 6,
  793. unsigned char TriggerTransactionEventReq:1; //bit 7
  794. }bits[CONNECTOR_QUANTITY];
  795. }CpinitiateMsg;
  796. CpinitiateMsg cpinitateMsg;
  797. //=========================================
  798. // Meter buffer process
  799. //=========================================
  800. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContextEnumType dataType)
  801. {
  802. uint32_t result = 0;
  803. char sqlCmd[8192];
  804. char zErrMsg[200];
  805. int rows, cols;
  806. char **resultData;
  807. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContextEnumType_Sample_Periodic?0:1));
  808. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  809. {
  810. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  811. }
  812. else
  813. {
  814. if(rows >= 1)
  815. {
  816. result = atoi(resultData[1]);
  817. }
  818. }
  819. return result;
  820. }
  821. int meterValueBufferClear(uint8_t gun_index)
  822. {
  823. int result = PASS;
  824. char sqlCmd[512];
  825. char *errMsg = 0;
  826. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  827. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  828. {
  829. DEBUG_INFO("SQL error: %s\n",errMsg);
  830. result = FAIL;
  831. }
  832. return result;
  833. }
  834. int meterValueBufferInsert(uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  835. {
  836. int result = PASS;
  837. char sqlCmd[8192];
  838. char *errMsg = 0;
  839. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", gun_index
  840. , transactionId
  841. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  842. , meterValue);
  843. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  844. {
  845. result = FAIL;
  846. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  847. }
  848. return result;
  849. }
  850. int meterValueBufferReplace(int bufferIdx, uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  851. {
  852. int result = PASS;
  853. char sqlCmd[8192];
  854. char *errMsg = 0;
  855. sprintf(sqlCmd, "replace into meterValuesBuffer(idx, occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values('%d', CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", bufferIdx
  856. , gun_index
  857. , transactionId
  858. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  859. , meterValue);
  860. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  861. {
  862. result = FAIL;
  863. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  864. }
  865. return result;
  866. }
  867. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  868. {
  869. int result = PASS;
  870. char sqlCmd[8192];
  871. char zErrMsg[200];
  872. int rows, cols;
  873. char **resultData;
  874. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  875. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  876. {
  877. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  878. result = FAIL;
  879. }
  880. else
  881. {
  882. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  883. {
  884. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  885. json_object_array_add(MeterValues, MeterValue);
  886. }
  887. }
  888. return result;
  889. }
  890. //=========================================
  891. // Certificate related routine
  892. //=========================================
  893. int certVerify(char *privateKey, char *cert)
  894. {
  895. int result = PASS;
  896. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  897. // Load certificate file
  898. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  899. {
  900. DEBUG_ERROR("Load certificate error!\n");
  901. result = FAIL;
  902. }
  903. // Load private key file
  904. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  905. {
  906. DEBUG_ERROR("Load private key error!\n");
  907. result = FAIL;
  908. }
  909. if(!SSL_CTX_check_private_key(ctx))
  910. {
  911. result = FAIL;
  912. }
  913. SSL_CTX_free(ctx);
  914. return result;
  915. }
  916. //==========================================
  917. // Parse certificate content
  918. //==========================================
  919. int parseCertInfo(char *certPath, int parseType, char *data)
  920. {
  921. int result = FAIL;
  922. int count = 0;
  923. int showupLine = 0;
  924. memset(data, 0, ARRAY_SIZE(data));
  925. if(access(certPath,F_OK) != -1)
  926. {
  927. char temp[512] = {0};
  928. char capturedData[256] = {0};
  929. char hashType[10] = "SHA256";
  930. FILE *fp;
  931. // Need to get hash type first
  932. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  933. fp = popen(temp, "r");
  934. if(fp)
  935. {
  936. while(fgets(temp, sizeof(temp), fp) != NULL)
  937. {
  938. if(strstr(temp, "Signature Algorithm:") != NULL)
  939. {
  940. result = PASS;
  941. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  942. sprintf((char*)hashType, "SHA256");
  943. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  944. sprintf((char*)hashType, "SHA384");
  945. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  946. sprintf((char*)hashType, "SHA512");
  947. else
  948. {
  949. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  950. result = FAIL;
  951. }
  952. break;
  953. }
  954. }
  955. }
  956. switch(parseType)
  957. {
  958. case CERT_PARSE_HashAlgorithm:
  959. sprintf((char*)data, hashType);
  960. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  961. break;
  962. case CERT_PARSE_SerialNumber:
  963. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  964. fp = popen(temp, "r");
  965. if(fp)
  966. {
  967. while(fgets(temp, sizeof(temp), fp) != NULL)
  968. {
  969. if(strstr(temp, "serial=") != NULL)
  970. {
  971. sscanf(temp, "%*[^=]=%s", capturedData);
  972. result = PASS;
  973. break;
  974. }
  975. }
  976. DEBUG_INFO("serialNumber: %s\n", capturedData);
  977. sprintf((char*)data, capturedData);
  978. }
  979. break;
  980. case CERT_PARSE_IssuerNameHash:
  981. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  982. fp = popen(temp, "r");
  983. if(fp)
  984. {
  985. while(fgets(temp, sizeof(temp), fp) != NULL)
  986. {
  987. if(strstr(temp, "SEQUENCE") != NULL)
  988. {
  989. count++;
  990. if(count==4)
  991. {
  992. sscanf(temp, "%[^:]", capturedData);
  993. showupLine = atoi(capturedData);
  994. break;
  995. }
  996. }
  997. }
  998. }
  999. if(showupLine > 0)
  1000. {
  1001. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1002. system(temp);
  1003. }
  1004. else
  1005. {
  1006. break;
  1007. }
  1008. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1009. {
  1010. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1011. fp = popen(temp, "r");
  1012. if(fp)
  1013. {
  1014. while(fgets(temp, sizeof(temp), fp) != NULL)
  1015. {
  1016. if(strstr(temp, "(stdin)=") != NULL)
  1017. {
  1018. sscanf(temp, "%*[^=]=%s", capturedData);
  1019. result = PASS;
  1020. break;
  1021. }
  1022. }
  1023. stringtrimspace(capturedData);
  1024. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1025. sprintf((char*)data, capturedData);
  1026. }
  1027. }
  1028. break;
  1029. case CERT_PARSE_IssuerKeyHash:
  1030. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1031. fp = popen(temp, "r");
  1032. if(fp)
  1033. {
  1034. while(fgets(temp, sizeof(temp), fp) != NULL)
  1035. {
  1036. if(strstr(temp, "BIT STRING") != NULL)
  1037. {
  1038. sscanf(temp, "%[^:]", capturedData);
  1039. showupLine = atoi(capturedData);
  1040. break;
  1041. }
  1042. }
  1043. }
  1044. if(showupLine > 0)
  1045. {
  1046. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1047. system(temp);
  1048. }
  1049. else
  1050. {
  1051. break;
  1052. }
  1053. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1054. {
  1055. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1056. fp = popen(temp, "r");
  1057. if(fp)
  1058. {
  1059. while(fgets(temp, sizeof(temp), fp) != NULL)
  1060. {
  1061. if(strstr(temp, "(stdin)=") != NULL)
  1062. {
  1063. sscanf(temp, "%*[^=]=%s", capturedData);
  1064. result = PASS;
  1065. break;
  1066. }
  1067. }
  1068. stringtrimspace(capturedData);
  1069. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1070. sprintf((char*)data, capturedData);
  1071. }
  1072. }
  1073. break;
  1074. case CERT_PARSE_OcspUrl:
  1075. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1076. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1077. fp = popen(temp, "r");
  1078. if(fp)
  1079. {
  1080. while(fgets(temp, sizeof(temp), fp) != NULL)
  1081. {
  1082. if(strstr(temp, "OCSP - URI:") != NULL)
  1083. {
  1084. //strcpy((char*)data, temp);
  1085. sscanf(temp, "%*[^:]:%s", capturedData);
  1086. sprintf((char*)data, capturedData);
  1087. DEBUG_INFO("OCSP_URI: %s\n", data);
  1088. result = PASS;
  1089. break;
  1090. }
  1091. }
  1092. }
  1093. break;
  1094. default:
  1095. DEBUG_INFO("Parse type is invalid.\n");
  1096. break;
  1097. }
  1098. pclose(fp);
  1099. }
  1100. return result;
  1101. }
  1102. //=========================================
  1103. // Get connector charging info
  1104. //=========================================
  1105. struct ChargingInfoData *getTargetChargingInfoData(uint8_t gun_index)
  1106. {
  1107. struct ChargingInfoData *targetChargingInfoData;
  1108. uint8_t tempIndex;
  1109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1110. {
  1111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1112. {
  1113. tempIndex = ((gun_index==2) ? 1: 0);
  1114. }
  1115. else
  1116. {
  1117. tempIndex = gun_index;
  1118. }
  1119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1120. {
  1121. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1122. {
  1123. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1129. {
  1130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1131. {
  1132. tempIndex = ((gun_index==2) ? 1: 0);
  1133. }
  1134. else
  1135. {
  1136. tempIndex = gun_index;
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1141. {
  1142. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1148. {
  1149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1150. {
  1151. tempIndex = ((gun_index==2) ? 1: 0);
  1152. }
  1153. else
  1154. {
  1155. tempIndex = gun_index;
  1156. }
  1157. for (int index = 0; index < GB_QUANTITY; index++)
  1158. {
  1159. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1160. {
  1161. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. else if(gunType[gun_index] == GUN_TYPE_DO)
  1167. {
  1168. tempIndex = gun_index;
  1169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1172. {
  1173. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData;
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. else
  1179. {
  1180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1181. {
  1182. tempIndex = 2;
  1183. }
  1184. else
  1185. {
  1186. tempIndex = gun_index;
  1187. }
  1188. for (int index = 0; index < AC_QUANTITY; index++)
  1189. {
  1190. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1191. {
  1192. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.AcChargingData[index];
  1193. break;
  1194. }
  1195. }
  1196. }
  1197. return targetChargingInfoData;
  1198. }
  1199. //=========================================
  1200. // Save configuration
  1201. //=========================================
  1202. int runShellCmd(const char*cmd)
  1203. {
  1204. int result = FAIL;
  1205. char buf[256];
  1206. FILE *fp;
  1207. fp = popen(cmd, "r");
  1208. if(fp != NULL)
  1209. {
  1210. while(fgets(buf, sizeof(buf), fp) != NULL)
  1211. {
  1212. DEBUG_INFO("%s\n", buf);
  1213. }
  1214. result = PASS;
  1215. }
  1216. pclose(fp);
  1217. return result;
  1218. }
  1219. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1220. {
  1221. int result = PASS;
  1222. int fd,wrd;
  1223. unsigned int i,Chk;
  1224. unsigned char *ptr, *BufTmp;
  1225. int MtdBlockSize = 0x300000;
  1226. Chk=0;
  1227. ptr=(unsigned char *)UsrData;
  1228. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  1229. {
  1230. memset(BufTmp,0,MtdBlockSize);
  1231. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  1232. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  1233. Chk+=*(BufTmp+i);
  1234. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  1235. // Output configuration to file.
  1236. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  1237. if (fd < 0)
  1238. {
  1239. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  1240. free(BufTmp);
  1241. return 0;
  1242. }
  1243. wrd=write(fd, BufTmp, MtdBlockSize);
  1244. close(fd);
  1245. if(wrd<MtdBlockSize)
  1246. {
  1247. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  1248. free(BufTmp);
  1249. return 0;
  1250. }
  1251. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  1252. DEBUG_INFO("Erase /dev/mtd10.\n");
  1253. runShellCmd("flash_erase /dev/mtd10 0 0");
  1254. DEBUG_INFO("Write /dev/mtd10.\n");
  1255. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  1256. DEBUG_INFO("Erase /dev/mtd11.\n");
  1257. runShellCmd("flash_erase /dev/mtd11 0 0");
  1258. DEBUG_INFO("Write /dev/mtd11.\n");
  1259. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  1260. system("rm -f /mnt/EvseConfig.bin");
  1261. DEBUG_INFO("EvseConfig write to flash OK\n");
  1262. }
  1263. else
  1264. {
  1265. DEBUG_ERROR("alloc BlockSize NG\r\n");
  1266. result = FAIL;
  1267. }
  1268. if(BufTmp!=NULL)
  1269. free(BufTmp);
  1270. return result;
  1271. }
  1272. //=========================================
  1273. // Date time related function
  1274. //=========================================
  1275. void getNowDatetime(uint8_t *data)
  1276. {
  1277. time_t t = time(NULL);
  1278. struct tm tm = *localtime(&t);
  1279. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1280. }
  1281. //=========================================
  1282. // Sqlite3 related function
  1283. //=========================================
  1284. int DB_Initial()
  1285. {
  1286. int result = PASS;
  1287. char* errMsg = NULL;
  1288. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  1289. "idToken text UNIQUE,"
  1290. "type text,"
  1291. "status text,"
  1292. "cacheExpiryDateTime text,"
  1293. "chargingPriority integer,"
  1294. "language1 text,"
  1295. "evseId text,"
  1296. "language2 text,"
  1297. "groupIdToken_idToken text,"
  1298. "groupIdToken_type text,"
  1299. "personalMessage text);";
  1300. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  1301. "idToken text UNIQUE,"
  1302. "type text,"
  1303. "status text,"
  1304. "cacheExpiryDateTime text,"
  1305. "chargingPriority integer,"
  1306. "language1 text,"
  1307. "evseId text,"
  1308. "language2 text,"
  1309. "groupIdToken_idToken text,"
  1310. "groupIdToken_type text,"
  1311. "personalMessage text,"
  1312. "version text);";
  1313. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  1314. "componentName text NOT NULL ,"
  1315. "componentInstance text, "
  1316. "variableName text NOT NULL, "
  1317. "variableInstance text, "
  1318. "variableCharacteristicsDataType integer, "
  1319. "variableCharacteristicsUnit text, "
  1320. "variableCharacteristicsMaxLimit real,"
  1321. "variableAttributesType text, "
  1322. "variableAttributesTypeMutability text, "
  1323. "variableAttributesTypeValue text, "
  1324. "variableCharacteristicsMinLimit real,"
  1325. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  1326. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  1327. "type text);";
  1328. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  1329. "type text);";
  1330. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  1331. "slot integer UNIQUE, connectionData text);";
  1332. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  1333. "occurDatetime text,"
  1334. "message_type text,"
  1335. "message_content text)";
  1336. char *sqlMeterValueBuffer = "create table if not exists meterValuesBuffer( idx integer primary key,"
  1337. "occurDatetime text,"
  1338. "gun_index text,"
  1339. "transactionId text,"
  1340. "ReadingContext text,"
  1341. "meterValue text);";
  1342. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  1343. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  1344. {
  1345. result = FAIL;
  1346. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  1347. sqlite3_close(db);
  1348. }
  1349. else
  1350. {
  1351. DEBUG_INFO( "OCPP local database open successfully.\n");
  1352. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  1353. {
  1354. result = FAIL;
  1355. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  1356. }
  1357. else
  1358. {
  1359. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  1360. }
  1361. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  1362. {
  1363. result = FAIL;
  1364. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  1365. }
  1366. else
  1367. {
  1368. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  1369. }
  1370. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  1371. {
  1372. result = FAIL;
  1373. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  1374. }
  1375. else
  1376. {
  1377. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  1378. }
  1379. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  1380. {
  1381. result = FAIL;
  1382. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  1383. }
  1384. else
  1385. {
  1386. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  1387. }
  1388. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  1389. {
  1390. result = FAIL;
  1391. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  1392. }
  1393. else
  1394. {
  1395. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  1396. }
  1397. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  1398. {
  1399. result = FAIL;
  1400. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  1401. }
  1402. else
  1403. {
  1404. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  1405. }
  1406. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  1407. {
  1408. result = FAIL;
  1409. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  1410. }
  1411. else
  1412. {
  1413. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1414. }
  1415. // Create meter values buffer table
  1416. if(sqlite3_exec(db, sqlMeterValueBuffer, 0, 0, &errMsg) != SQLITE_OK)
  1417. {
  1418. DEBUG_INFO( "Create Table meterValuesBuffer error %s\n",errMsg);
  1419. return 0;
  1420. }
  1421. else
  1422. {
  1423. DEBUG_INFO( "Opened meterValuesBuffer table successfully\n");
  1424. }
  1425. //sqlite3_close(db);
  1426. }
  1427. return result;
  1428. }
  1429. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1430. {
  1431. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1432. return 0;
  1433. }
  1434. void DB_getListVerion()
  1435. {
  1436. char sql[256];
  1437. char* errMsg = NULL;
  1438. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1439. /* Execute SQL statement */
  1440. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1441. {
  1442. DEBUG_INFO("SQL error: %s", errMsg);
  1443. }
  1444. }
  1445. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1446. {
  1447. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1448. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1449. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1450. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1451. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1452. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1453. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1454. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1455. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1456. return 0;
  1457. }
  1458. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1459. {
  1460. char sql[256];
  1461. char* errMsg = NULL;
  1462. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1463. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1464. if(isQueryFromCache)
  1465. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1466. else
  1467. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1468. /* Execute SQL statement */
  1469. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1470. {
  1471. DEBUG_INFO("SQL error: %s", errMsg);
  1472. }
  1473. }
  1474. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1475. {
  1476. for (int i = 0; i < columnCount; i++)
  1477. {
  1478. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1479. }
  1480. return 0;
  1481. }
  1482. void DB_get_TableAuthlocalAllData(void)
  1483. {
  1484. char sql[256];
  1485. char* errMsg = NULL;
  1486. sprintf(sql,"select * from ocpp20_auth_local;");
  1487. /* Execute SQL statement */
  1488. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1489. {
  1490. DEBUG_INFO("SQL error: %s", errMsg);
  1491. }
  1492. }
  1493. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1494. {
  1495. for(int i = 0; i<columnCount; i++)
  1496. {
  1497. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1498. }
  1499. return 0;
  1500. }
  1501. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1502. {
  1503. int result = PASS;
  1504. char sql[512];
  1505. char* errMsg = NULL;
  1506. sprintf(sql,"insert or replace into ocpp20_auth_local (idToken, type, status, cacheExpiryDateTime, chargingPriority, language1, language2, groupIdToken_idToken, groupIdToken_type, version) VALUES('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d ); SELECT * from ocpp20_auth_local;",
  1507. data->idToken.idToken,
  1508. data->idToken.type,
  1509. data->idTokenInfo.status,
  1510. data->idTokenInfo.cacheExpiryDateTime,
  1511. data->idTokenInfo.chargingPriority,
  1512. data->idTokenInfo.language1,
  1513. data->idTokenInfo.language2,
  1514. data->idTokenInfo.groupIdToken.idToken,
  1515. data->idTokenInfo.groupIdToken.type,
  1516. listVersion);
  1517. //* Execute SQL statement */
  1518. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1519. {
  1520. DEBUG_INFO("SQL error: %s\n", errMsg);
  1521. result = FAIL;
  1522. }
  1523. else
  1524. {
  1525. memset(sql, 0, ARRAY_SIZE(sql));
  1526. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1527. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1528. {
  1529. DEBUG_INFO("SQL error: %s\n", errMsg);
  1530. result = FAIL;
  1531. }
  1532. }
  1533. return result;
  1534. }
  1535. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1536. {
  1537. int result = PASS;
  1538. char sql[512];
  1539. char* errMsg = NULL;
  1540. sprintf(sql,"insert or replace into ocpp20_auth_cache (idToken, type, status, cacheExpiryDateTime, chargingPriority, language1, language2, groupIdToken_idToken, groupIdToken_type) VALUES('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s'); SELECT * from ocpp20_auth_cache;",
  1541. idToken->idToken,
  1542. idToken->type,
  1543. idTokenInfo->status,
  1544. idTokenInfo->cacheExpiryDateTime,
  1545. idTokenInfo->chargingPriority,
  1546. idTokenInfo->language1,
  1547. idTokenInfo->language2,
  1548. idTokenInfo->groupIdToken.idToken,
  1549. idTokenInfo->groupIdToken.type);
  1550. //* Execute SQL statement */
  1551. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1552. {
  1553. DEBUG_INFO("SQL error: %s\n", errMsg);
  1554. result = FAIL;
  1555. }
  1556. return result;
  1557. }
  1558. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1559. {
  1560. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1561. // printf("localversion=%d\n", localversion);
  1562. return 0;
  1563. }
  1564. void DB_deleteIdTag(char idTag[])
  1565. {
  1566. char sql[512];
  1567. char* errMsg = NULL;
  1568. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1569. //* Execute SQL statement */
  1570. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1571. {
  1572. DEBUG_INFO("SQL error: %s", errMsg);
  1573. }
  1574. }
  1575. int DB_cleanLocalList()
  1576. {
  1577. int result = PASS;
  1578. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1579. char *errMsg = 0;
  1580. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1581. {
  1582. DEBUG_INFO("%s\n", errMsg);
  1583. result = FAIL;
  1584. }
  1585. return result;
  1586. }
  1587. int DB_cleanLocalCache()
  1588. {
  1589. int result = PASS;
  1590. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1591. char *errMsg = 0;
  1592. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1593. {
  1594. DEBUG_INFO("%s\n", errMsg);
  1595. result = FAIL;
  1596. }
  1597. return result;
  1598. }
  1599. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1600. {
  1601. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1602. return 0;
  1603. }
  1604. void DB_getBooType()
  1605. {
  1606. char sql[256];
  1607. char* errMsg = NULL;
  1608. sprintf(sql,"select * from ocpp20_boot_type;");
  1609. /* Execute SQL statement */
  1610. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1611. {
  1612. DEBUG_INFO("SQL error: %s\n", errMsg);
  1613. }
  1614. }
  1615. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1616. {
  1617. for(int i = 0; i<columnCount; i++)
  1618. {
  1619. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1620. }
  1621. return 0;
  1622. }
  1623. int DB_updateBootType(BootReasonEnumType reason)
  1624. {
  1625. int result = PASS;
  1626. char sql[512];
  1627. char* errMsg = NULL;
  1628. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1629. //* Execute SQL statement */
  1630. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1631. {
  1632. DEBUG_INFO("SQL error: %s\n", errMsg);
  1633. result = FAIL;
  1634. }
  1635. return result;
  1636. }
  1637. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1638. {
  1639. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1640. return 0;
  1641. }
  1642. void DB_getSecurityEventType()
  1643. {
  1644. char sql[256];
  1645. char* errMsg = NULL;
  1646. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1647. /* Execute SQL statement */
  1648. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1649. {
  1650. DEBUG_INFO("SQL error: %s\n", errMsg);
  1651. }
  1652. }
  1653. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1654. {
  1655. for(int i = 0; i<columnCount; i++)
  1656. {
  1657. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1658. }
  1659. return 0;
  1660. }
  1661. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1662. {
  1663. int result = PASS;
  1664. char sql[512];
  1665. char* errMsg = NULL;
  1666. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1667. //* Execute SQL statement */
  1668. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1669. {
  1670. DEBUG_INFO("SQL error: %s\n", errMsg);
  1671. result = FAIL;
  1672. }
  1673. return result;
  1674. }
  1675. int DB_variableClear()
  1676. {
  1677. int result = PASS;
  1678. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1679. char *errMsg = 0;
  1680. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1681. {
  1682. DEBUG_INFO("%s\n", errMsg);
  1683. result = FAIL;
  1684. }
  1685. return result;
  1686. }
  1687. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1688. {
  1689. for(int i = 0; i<columnCount; i++)
  1690. {
  1691. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1692. }
  1693. return 0;
  1694. }
  1695. int DB_variableSaveToDb(struct ReportDataType *variable)
  1696. {
  1697. int result = FAIL;
  1698. char sql[4096];
  1699. char* errMsg = NULL;
  1700. sprintf(sql,"insert or replace into ocpp20_variable (componentName, componentInstance, variableName, variableInstance, variableCharacteristicsDataType, variableCharacteristicsUnit, variableCharacteristicsMaxLimit, variableAttributesType, variableAttributesTypeMutability, variableAttributesTypeValue, variableCharacteristicsMinLimit) VALUES('%s', '%s', '%s', '%s', '%s', '%s', %f, '%s', '%s', '%s', '%f'); SELECT * from ocpp20_variable;",
  1701. variable->component.name,
  1702. variable->component.instance,
  1703. variable->variable.name,
  1704. variable->variable.instance,
  1705. variable->variableCharacteristics.dataType,
  1706. variable->variableCharacteristics.unit,
  1707. variable->variableCharacteristics.maxLimit,
  1708. variable->variableAttribute[0].type,
  1709. variable->variableAttribute[0].mutability,
  1710. variable->variableAttribute[0].value,
  1711. variable->variableCharacteristics.minLimit);
  1712. //* Execute SQL statement */
  1713. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1714. {
  1715. DEBUG_INFO("SQL error: %s\n", errMsg);
  1716. result = FAIL;
  1717. }
  1718. return result;
  1719. }
  1720. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1721. {
  1722. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1723. if(atoi(columnValue[0]) == 0)
  1724. {
  1725. DB_updateBootType(BootReasonEnumType_PowerUp);
  1726. // Create variable table content
  1727. /* AlignedDataCtrlr Required item */
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "false");
  1734. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "true");
  1741. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1745. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1748. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1750. "Energy.Active.Import.Register,"
  1751. "Energy.Active.Import.Interval,"
  1752. "Power.Active.Import,"
  1753. "Voltage,"
  1754. "SoC,"
  1755. "Current.Offered,"
  1756. "Power.Offered");
  1757. else
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1759. "Energy.Active.Import.Register,"
  1760. "Energy.Active.Import.Interval,"
  1761. "Power.Active.Import,"
  1762. "Voltage,"
  1763. "Current.Offered");
  1764. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1769. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1773. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "true");
  1780. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  1787. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1791. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1796. "Energy.Active.Import.Register,"
  1797. "Energy.Active.Import.Interval,"
  1798. "Power.Active.Import,"
  1799. "Voltage,"
  1800. "SoC");
  1801. else
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1803. "Energy.Active.Import.Register,"
  1804. "Energy.Active.Import.Interval,"
  1805. "Power.Active.Import,"
  1806. "Voltage");
  1807. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1815. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1816. /* AuthCtrlrVariable Required item */
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
  1823. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1830. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "false");
  1837. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "false");
  1844. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true");
  1851. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true");
  1858. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1862. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1866. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1867. /* AuthCacheCtrlr Variable Required item*/
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "false");
  1874. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "true");
  1881. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "true");
  1889. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1893. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "true");
  1897. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1904. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1905. /* ClockCtrlr Variable Required item */
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1911. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1912. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1919. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1927. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1934. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1941. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1949. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1956. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1963. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1964. /* ChargingStation Required item */
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "false");
  1971. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1978. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1985. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  1992. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  1999. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  2006. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  2013. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  2014. /* Connector Required item */
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "false");
  2021. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  2028. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  2035. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  2036. /* CustomizationCtrlr Required item */
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "false");
  2043. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  2044. /* DeviceDataCtrlr Required item */
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  2052. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2060. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  2068. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2076. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2079. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  2084. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2087. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  2092. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2100. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2108. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  2109. /* DisplayMessageCtrlr Required item */
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "false");
  2116. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "false");
  2123. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2127. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  2131. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  2138. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  2145. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  2146. /* EVSE Required item */
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "false");
  2153. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  2160. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  2167. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  2174. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  2175. /* LocalAuthListCtrlr Required item */
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true");
  2182. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2186. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  2190. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "true");
  2197. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  2205. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  2213. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2217. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  2221. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  2222. /* MonitoringCtrlr Required item */
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "false");
  2229. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "false");
  2236. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2244. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2252. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2260. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2268. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  2275. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  2276. /* OCPPCommCtrlr Required item */
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  2283. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  2292. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  2299. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  2303. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  2308. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  2315. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  2322. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  2330. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "false");
  2337. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  2346. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  2355. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "true");
  2362. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  2366. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  2371. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  2378. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  2385. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  2392. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "false");
  2399. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  2403. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  2408. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.unit, "Seconds");
  2412. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.minLimit = 5;
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value, "30");
  2417. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval]);
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].component.name, "OCPPCommCtrlr");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variable.name, "RfidEndianType");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"big":"little");
  2424. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType]);
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].component.name, "OCPPCommCtrlr");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variable.name, "AuthorizeTimeout");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.unit, "Seconds");
  2428. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.minLimit = 10;
  2429. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.maxLimit = 300;
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].value, "15");
  2434. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout]);
  2435. /* ReservationCtrlr Required item */
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "true");
  2442. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "true");
  2449. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "false");
  2456. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2457. /* SampledDataCtrlr Required item */
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "true");
  2464. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "true");
  2471. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  2478. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2482. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2487. "Energy.Active.Import.Register,"
  2488. "Energy.Active.Import.Interval,"
  2489. "Power.Active.Import,"
  2490. "Voltage,"
  2491. "SoC");
  2492. else
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2494. "Energy.Active.Import.Register,"
  2495. "Energy.Active.Import.Interval,"
  2496. "Power.Active.Import,"
  2497. "Voltage");
  2498. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2510. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2514. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2518. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2523. "Energy.Active.Import.Register,"
  2524. "Energy.Active.Import.Interval,"
  2525. "Power.Active.Import,"
  2526. "Voltage,"
  2527. "SoC,"
  2528. "Current.Offered,"
  2529. "Power.Offered");
  2530. else
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2532. "Energy.Active.Import.Register,"
  2533. "Energy.Active.Import.Interval,"
  2534. "Power.Active.Import,"
  2535. "Voltage,"
  2536. "Current.Offered");
  2537. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2542. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2546. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2547. /* SecurityCtrlr Required item */
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2551. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2555. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2559. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2563. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2570. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2574. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2578. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2585. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "false");
  2592. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2596. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2600. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2601. /* SmartChargingCtrlr Required item */
  2602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "true");
  2608. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "true");
  2615. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "false");
  2622. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2629. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2636. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2643. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "false");
  2650. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "false");
  2657. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "false");
  2664. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2668. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2672. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2679. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2680. /* TariffCostCtrlr Required item */
  2681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "false");
  2688. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "false");
  2696. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2700. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2704. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "false");
  2712. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "false");
  2720. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2724. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2728. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2732. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2736. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2737. /* TxCtrlr Required item */
  2738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2744. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2752. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "true");
  2759. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2766. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2773. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2780. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2788. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "false");
  2795. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2796. }
  2797. else
  2798. {
  2799. // Variable name init
  2800. /* AlignedDataCtrlr Required item */
  2801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2817. /* AuthCtrlrVariable Required item */
  2818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2832. /* AuthCacheCtrlr Variable Required item */
  2833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2843. /* ClockCtrlr Variable Required item */
  2844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2862. /* ChargingStation Required item */
  2863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2877. /* Connector Required item */
  2878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2884. /* CustomizationCtrlr Required item */
  2885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2887. /* DeviceDataCtrlr Required item */
  2888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2910. /* DisplayMessageCtrlr Required item */
  2911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2921. /* EVSE Required item */
  2922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2930. /* LocalAuthListCtrlr Required item */
  2931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2945. /* MonitoringCtrlr Required item */
  2946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2964. /* OCPPCommCtrlr Required item */
  2965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  3000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  3001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  3002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  3003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  3004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].component.name, "OCPPCommCtrlr");
  3005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variable.name, "RfidEndianType");
  3006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].component.name, "OCPPCommCtrlr");
  3007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variable.name, "AuthorizeTimeout");
  3008. /* ReservationCtrlr Required item */
  3009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  3010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  3011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  3012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  3013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  3014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  3015. /* SampledDataCtrlr Required item */
  3016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  3017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  3018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  3019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  3020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  3021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  3022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  3023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  3024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  3025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  3026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  3027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  3028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  3029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  3030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  3031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  3032. /* SecurityCtrlr Required item */
  3033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  3034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  3035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  3036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  3037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  3038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  3039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  3040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  3041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  3042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  3043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  3044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  3045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  3046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  3047. /* SmartChargingCtrlr Required item */
  3048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  3049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  3050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  3051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  3052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  3053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  3054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  3055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  3056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  3057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  3058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  3059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  3060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  3061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  3062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  3063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  3064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  3065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  3066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  3067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  3068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  3069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  3070. /* TariffCostCtrlr Required item */
  3071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  3072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  3073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  3074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  3075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  3076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  3077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  3078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  3079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  3080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  3081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  3082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  3083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  3084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  3085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  3086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  3087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  3088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  3089. /* TxCtrlr Required item */
  3090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  3092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  3093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  3094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  3095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  3096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  3098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  3099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  3100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  3101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  3102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  3103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  3104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  3105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  3106. }
  3107. return 0;
  3108. }
  3109. void DB_variableIsCreate()
  3110. {
  3111. char sql[512];
  3112. char* errMsg = NULL;
  3113. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  3114. /* Execute SQL statement */
  3115. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  3116. {
  3117. DEBUG_INFO("SQL error: %s\n", errMsg);
  3118. }
  3119. }
  3120. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3121. {
  3122. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  3123. {
  3124. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  3125. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  3126. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  3127. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  3128. {
  3129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  3130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  3131. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  3132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  3133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  3134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  3135. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  3136. }
  3137. }
  3138. return 0;
  3139. }
  3140. void DB_variableLoadFromDb()
  3141. {
  3142. char sql[512];
  3143. char* errMsg = NULL;
  3144. sprintf(sql,"select * from ocpp20_variable order by idx;");
  3145. /* Execute SQL statement */
  3146. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3147. {
  3148. DEBUG_INFO("SQL error: %s\n", errMsg);
  3149. }
  3150. }
  3151. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3152. {
  3153. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  3154. if(columnCount > 0)
  3155. {
  3156. for(int idx=0;idx<columnCount;idx++)
  3157. {
  3158. json_object *SetNetworkProfile;
  3159. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  3160. if(!is_error(SetNetworkProfile))
  3161. {
  3162. // Required data
  3163. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  3164. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  3165. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  3166. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  3167. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  3168. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  3169. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  3170. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  3171. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  3172. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  3173. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  3174. {
  3175. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  3176. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  3177. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  3178. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  3179. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  3180. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  3181. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  3182. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  3183. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  3184. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  3185. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  3186. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  3187. }
  3188. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  3189. {
  3190. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  3191. {
  3192. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  3193. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  3194. }
  3195. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  3196. {
  3197. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  3198. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  3199. }
  3200. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  3201. {
  3202. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  3203. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  3204. }
  3205. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  3206. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  3207. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  3208. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  3209. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  3210. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  3211. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  3212. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  3213. }
  3214. }
  3215. json_object_put(SetNetworkProfile);
  3216. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  3217. }
  3218. }
  3219. return 0;
  3220. }
  3221. void DB_getNetworkProfileFromDb()
  3222. {
  3223. char sql[512];
  3224. char* errMsg = NULL;
  3225. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  3226. /* Execute SQL statement */
  3227. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3228. {
  3229. DEBUG_INFO("SQL error: %s\n", errMsg);
  3230. }
  3231. }
  3232. int DB_addNetworkProfile(int slot, char *data)
  3233. {
  3234. int result = PASS;
  3235. char sql[512];
  3236. char* errMsg = NULL;
  3237. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  3238. slot,
  3239. data);
  3240. //* Execute SQL statement */
  3241. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  3242. {
  3243. DEBUG_INFO("SQL error: %s\n", errMsg);
  3244. result = FAIL;
  3245. }
  3246. return result;
  3247. }
  3248. int DB_deleteNetworkProfile(int slot)
  3249. {
  3250. int result = PASS;
  3251. char sql[512];
  3252. char* errMsg = NULL;
  3253. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  3254. //* Execute SQL statement */
  3255. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3256. {
  3257. DEBUG_INFO("SQL error: %s", errMsg);
  3258. result = FAIL;
  3259. }
  3260. return result;
  3261. }
  3262. int isNumber(uint8_t *string, uint8_t isFloat)
  3263. {
  3264. int result = NO;
  3265. int cntDecimal = 0;
  3266. float i;
  3267. for(int idx=0; idx<strlen((char*)string); idx++)
  3268. {
  3269. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  3270. {
  3271. return result;
  3272. }
  3273. else if(string[idx] == '.')
  3274. cntDecimal++;
  3275. if(cntDecimal>1)
  3276. return result;
  3277. }
  3278. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  3279. {
  3280. //DEBUG_INFO("%s is not pure integer!!\n", string);
  3281. }
  3282. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  3283. {
  3284. //DEBUG_INFO("%s is not float format!!\n", string);
  3285. }
  3286. else if(sscanf((char*)string, "%f", &i) != 0)
  3287. {
  3288. result = YES;
  3289. }
  3290. return result;
  3291. }
  3292. int isMatchTimeFormat(uint8_t *time)
  3293. {
  3294. int result = NO;
  3295. struct ParsingResult
  3296. {
  3297. int result;
  3298. int scanedElement;
  3299. int year;
  3300. int month;
  3301. int mday;
  3302. int hour;
  3303. int min;
  3304. int sec;
  3305. int tz_hour;
  3306. int tz_min;
  3307. float minSec;
  3308. }parsingResult;
  3309. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3310. if(strstr((char*)time, ".") != NULL)
  3311. {
  3312. // Original data with mini second
  3313. if(strstr((char*)time, "Z") != NULL)
  3314. {
  3315. // Original data with Z
  3316. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  3317. &parsingResult.year,
  3318. &parsingResult.month,
  3319. &parsingResult.mday,
  3320. &parsingResult.hour,
  3321. &parsingResult.min,
  3322. &parsingResult.sec,
  3323. &parsingResult.minSec);
  3324. }
  3325. else
  3326. {
  3327. // Original data without Z
  3328. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3329. &parsingResult.year,
  3330. &parsingResult.month,
  3331. &parsingResult.mday,
  3332. &parsingResult.hour,
  3333. &parsingResult.min,
  3334. &parsingResult.sec,
  3335. &parsingResult.minSec,
  3336. &parsingResult.tz_hour,
  3337. &parsingResult.tz_min);
  3338. }
  3339. }
  3340. else
  3341. {
  3342. // Original data without mini second
  3343. if(strstr((char*)time, "Z") != NULL)
  3344. {
  3345. // Original data with Z
  3346. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  3347. &parsingResult.year,
  3348. &parsingResult.month,
  3349. &parsingResult.mday,
  3350. &parsingResult.hour,
  3351. &parsingResult.min,
  3352. &parsingResult.sec);
  3353. }
  3354. else
  3355. {
  3356. // Original data without Z
  3357. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  3358. &parsingResult.year,
  3359. &parsingResult.month,
  3360. &parsingResult.mday,
  3361. &parsingResult.hour,
  3362. &parsingResult.min,
  3363. &parsingResult.sec,
  3364. &parsingResult.tz_hour,
  3365. &parsingResult.tz_min);
  3366. }
  3367. }
  3368. if(parsingResult.scanedElement >= 6)
  3369. {
  3370. result = YES;
  3371. }
  3372. return result;
  3373. }
  3374. int getCurrentYear()
  3375. {
  3376. int result = 0;
  3377. time_t CurrentTime;
  3378. struct tm *tm;
  3379. CurrentTime = time(NULL);
  3380. tm=localtime(&CurrentTime);
  3381. result = (tm->tm_year + 1900);
  3382. return result;
  3383. }
  3384. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  3385. {
  3386. int result = PASS;
  3387. char* errMsg = NULL;
  3388. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  3389. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  3390. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3391. {
  3392. result = FAIL;
  3393. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  3394. }
  3395. sprintf(sqlStr, "delete from ocpp20_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  3396. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3397. {
  3398. result = FAIL;
  3399. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  3400. }
  3401. return result;
  3402. }
  3403. //==========================================
  3404. // Check time passed since today
  3405. //==========================================
  3406. long long DiffTimebWithNow(struct timeb ST)
  3407. {
  3408. //return milli-second
  3409. struct timeb ET;
  3410. long long StartTime,StopTime;
  3411. ftime(&ET);
  3412. StartTime=(long long)ST.time;
  3413. StopTime=(long long)ET.time;
  3414. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  3415. }
  3416. int getTimePassSinceToday(uint8_t gun_index)
  3417. {
  3418. int result = -1;
  3419. static time_t lastTime[4];
  3420. time_t t;
  3421. struct tm *tmStartToday;
  3422. struct timeb tbStartToday;
  3423. t=time(NULL);
  3424. if(difftime(t, lastTime[gun_index])>0)
  3425. {
  3426. tmStartToday=localtime(&t);
  3427. tmStartToday->tm_hour = 0;
  3428. tmStartToday->tm_min = 0;
  3429. tmStartToday->tm_sec = 0;
  3430. tbStartToday.time = mktime(tmStartToday);
  3431. tbStartToday.millitm = 0;
  3432. result = DiffTimebWithNow(tbStartToday)/1000;
  3433. lastTime[gun_index] = t;
  3434. }
  3435. return result;
  3436. }
  3437. int syncDateTimeRTC(uint8_t *data)
  3438. {
  3439. struct ParsingResult
  3440. {
  3441. int result;
  3442. int scanedElement;
  3443. int year;
  3444. int month;
  3445. int mday;
  3446. int hour;
  3447. int min;
  3448. int sec;
  3449. int tz_hour;
  3450. int tz_min;
  3451. float minSec;
  3452. }result;
  3453. struct tm tmOrg;
  3454. struct tm *tmTarget;
  3455. struct timeb tbTarget;
  3456. char buf[128];
  3457. memset(&result, 0x00, sizeof(struct ParsingResult));
  3458. result.result = PASS;
  3459. if(strstr((char*)data, ".") != NULL)
  3460. {
  3461. // Original data with mini second
  3462. if(strstr((char*)data, "Z") != NULL)
  3463. {
  3464. // Original data with Z
  3465. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3466. &result.year,
  3467. &result.month,
  3468. &result.mday,
  3469. &result.hour,
  3470. &result.min,
  3471. &result.sec,
  3472. &result.minSec);
  3473. }
  3474. else
  3475. {
  3476. // Original data without Z
  3477. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3478. &result.year,
  3479. &result.month,
  3480. &result.mday,
  3481. &result.hour,
  3482. &result.min,
  3483. &result.sec,
  3484. &result.minSec,
  3485. &result.tz_hour,
  3486. &result.tz_min);
  3487. }
  3488. }
  3489. else
  3490. {
  3491. // Original data without mini second
  3492. if(strstr((char*)data, "Z") != NULL)
  3493. {
  3494. // Original data with Z
  3495. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3496. &result.year,
  3497. &result.month,
  3498. &result.mday,
  3499. &result.hour,
  3500. &result.min,
  3501. &result.sec);
  3502. }
  3503. else
  3504. {
  3505. // Original data without Z
  3506. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3507. &result.year,
  3508. &result.month,
  3509. &result.mday,
  3510. &result.hour,
  3511. &result.min,
  3512. &result.sec,
  3513. &result.tz_hour,
  3514. &result.tz_min);
  3515. }
  3516. }
  3517. tmOrg.tm_year = result.year - 1900;
  3518. tmOrg.tm_mon = result.month - 1;
  3519. tmOrg.tm_mday = result.mday;
  3520. tmOrg.tm_hour = result.hour;
  3521. tmOrg.tm_min = result.min;
  3522. tmOrg.tm_sec = result.sec;
  3523. tmOrg.tm_gmtoff = 0;
  3524. tbTarget.time = mktime(&tmOrg);
  3525. tbTarget.timezone = 0;
  3526. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3527. tmTarget = gmtime(&tbTarget.time);
  3528. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  3529. //DEBUG_INFO(" org date time: %s\n", data);
  3530. //DEBUG_INFO("parse date time: %s\n", buf);
  3531. system(buf);
  3532. system("/sbin/hwclock -w --systohc");
  3533. if(result.scanedElement < 6)
  3534. result.result = FAIL;
  3535. return result.result;
  3536. }
  3537. //==========================================
  3538. // GetCompositeSchedule logic related function
  3539. //==========================================
  3540. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3541. {
  3542. //return milli-second
  3543. unsigned int StartTime,StopTime;
  3544. StartTime=(unsigned int)ST.time;
  3545. StopTime=(unsigned int)ET.time;
  3546. return (StopTime-StartTime);
  3547. }
  3548. int DiffTimebWithNowSec(struct timeb ST)
  3549. {
  3550. //return milli-second
  3551. struct timeb ET;
  3552. unsigned int StartTime,StopTime;
  3553. ftime(&ET);
  3554. StartTime=(unsigned int)ST.time;
  3555. StopTime=(unsigned int)ET.time;
  3556. return (StopTime-StartTime);
  3557. }
  3558. int getStartStop(uint8_t *start, uint8_t *stop)
  3559. {
  3560. struct ParsingResult
  3561. {
  3562. int result;
  3563. int scanedElement;
  3564. int year;
  3565. int month;
  3566. int mday;
  3567. int hour;
  3568. int min;
  3569. int sec;
  3570. int tz_hour;
  3571. int tz_min;
  3572. float minSec;
  3573. };
  3574. struct ParsingResult parseStart;
  3575. struct ParsingResult parseStop;
  3576. int result = -1;
  3577. struct tm tmStart;
  3578. struct timeb tbStart;
  3579. struct tm tmStop;
  3580. struct timeb tbStop;
  3581. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3582. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3583. // Scan start & stop date time
  3584. if(strstr((char*)start, ".") != NULL)
  3585. {
  3586. // Original data with mini second
  3587. if(strstr((char*)start, "Z") != NULL)
  3588. {
  3589. // Original data with Z
  3590. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3591. &parseStart.year,
  3592. &parseStart.month,
  3593. &parseStart.mday,
  3594. &parseStart.hour,
  3595. &parseStart.min,
  3596. &parseStart.sec,
  3597. &parseStart.minSec);
  3598. }
  3599. else
  3600. {
  3601. // Original data without Z
  3602. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3603. &parseStart.year,
  3604. &parseStart.month,
  3605. &parseStart.mday,
  3606. &parseStart.hour,
  3607. &parseStart.min,
  3608. &parseStart.sec,
  3609. &parseStart.minSec,
  3610. &parseStart.tz_hour,
  3611. &parseStart.tz_min);
  3612. }
  3613. }
  3614. else
  3615. {
  3616. // Original data without mini second
  3617. if(strstr((char*)start, "Z") != NULL)
  3618. {
  3619. // Original data with Z
  3620. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3621. &parseStart.year,
  3622. &parseStart.month,
  3623. &parseStart.mday,
  3624. &parseStart.hour,
  3625. &parseStart.min,
  3626. &parseStart.sec);
  3627. }
  3628. else
  3629. {
  3630. // Original data without Z
  3631. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3632. &parseStart.year,
  3633. &parseStart.month,
  3634. &parseStart.mday,
  3635. &parseStart.hour,
  3636. &parseStart.min,
  3637. &parseStart.sec,
  3638. &parseStart.tz_hour,
  3639. &parseStart.tz_min);
  3640. }
  3641. }
  3642. if(strstr((char*)stop, ".") != NULL)
  3643. {
  3644. // Original data with mini second
  3645. if(strstr((char*)stop, "Z") != NULL)
  3646. {
  3647. // Original data with Z
  3648. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3649. &parseStop.year,
  3650. &parseStop.month,
  3651. &parseStop.mday,
  3652. &parseStop.hour,
  3653. &parseStop.min,
  3654. &parseStop.sec,
  3655. &parseStop.minSec);
  3656. }
  3657. else
  3658. {
  3659. // Original data without Z
  3660. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3661. &parseStop.year,
  3662. &parseStop.month,
  3663. &parseStop.mday,
  3664. &parseStop.hour,
  3665. &parseStop.min,
  3666. &parseStop.sec,
  3667. &parseStop.minSec,
  3668. &parseStop.tz_hour,
  3669. &parseStop.tz_min);
  3670. }
  3671. }
  3672. else
  3673. {
  3674. // Original data without mini second
  3675. if(strstr((char*)stop, "Z") != NULL)
  3676. {
  3677. // Original data with Z
  3678. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3679. &parseStop.year,
  3680. &parseStop.month,
  3681. &parseStop.mday,
  3682. &parseStop.hour,
  3683. &parseStop.min,
  3684. &parseStop.sec);
  3685. }
  3686. else
  3687. {
  3688. // Original data without Z
  3689. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3690. &parseStop.year,
  3691. &parseStop.month,
  3692. &parseStop.mday,
  3693. &parseStop.hour,
  3694. &parseStop.min,
  3695. &parseStop.sec,
  3696. &parseStop.tz_hour,
  3697. &parseStop.tz_min);
  3698. }
  3699. }
  3700. // Calculate date time difference
  3701. if((parseStart.scanedElement >=6) &&
  3702. (parseStop.scanedElement >=6))
  3703. {
  3704. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  3705. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  3706. tmStart.tm_year = parseStart.year - 1900;
  3707. tmStart.tm_mon = parseStart.month - 1;
  3708. tmStart.tm_mday = parseStart.mday;
  3709. tmStart.tm_hour = parseStart.hour;
  3710. tmStart.tm_min = parseStart.min;
  3711. tmStart.tm_sec = parseStart.sec;
  3712. tmStart.tm_gmtoff = 0;
  3713. tbStart.time = mktime(&tmStart);
  3714. tbStart.timezone = 0;
  3715. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3716. tmStop.tm_year = parseStop.year - 1900;
  3717. tmStop.tm_mon = parseStop.month - 1;
  3718. tmStop.tm_mday = parseStop.mday;
  3719. tmStop.tm_hour = parseStop.hour;
  3720. tmStop.tm_min = parseStop.min;
  3721. tmStop.tm_sec = parseStop.sec;
  3722. tmStop.tm_gmtoff = 0;
  3723. tbStop.time = mktime(&tmStop);
  3724. tbStop.timezone = 0;
  3725. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3726. result = DiffTimebSec(tbStart, tbStop);
  3727. //DEBUG_INFO("getStartStop(): %d\n", result);
  3728. }
  3729. else
  3730. {
  3731. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3732. }
  3733. return result;
  3734. }
  3735. int isOvertNow(uint8_t *start)
  3736. {
  3737. int result = NO;
  3738. struct ParsingResult
  3739. {
  3740. int result;
  3741. int scanedElement;
  3742. int year;
  3743. int month;
  3744. int mday;
  3745. int hour;
  3746. int min;
  3747. int sec;
  3748. int tz_hour;
  3749. int tz_min;
  3750. float minSec;
  3751. }parsingResult;
  3752. struct tm tmStart;
  3753. struct timeb tbStart;
  3754. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3755. if(strstr((char*)start, ".") != NULL)
  3756. {
  3757. // Original data with mini second
  3758. if(strstr((char*)start, "Z") != NULL)
  3759. {
  3760. // Original data with Z
  3761. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3762. &parsingResult.year,
  3763. &parsingResult.month,
  3764. &parsingResult.mday,
  3765. &parsingResult.hour,
  3766. &parsingResult.min,
  3767. &parsingResult.sec,
  3768. &parsingResult.minSec);
  3769. }
  3770. else
  3771. {
  3772. // Original data without Z
  3773. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3774. &parsingResult.year,
  3775. &parsingResult.month,
  3776. &parsingResult.mday,
  3777. &parsingResult.hour,
  3778. &parsingResult.min,
  3779. &parsingResult.sec,
  3780. &parsingResult.minSec,
  3781. &parsingResult.tz_hour,
  3782. &parsingResult.tz_min);
  3783. }
  3784. }
  3785. else
  3786. {
  3787. // Original data without mini second
  3788. if(strstr((char*)start, "Z") != NULL)
  3789. {
  3790. // Original data with Z
  3791. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3792. &parsingResult.year,
  3793. &parsingResult.month,
  3794. &parsingResult.mday,
  3795. &parsingResult.hour,
  3796. &parsingResult.min,
  3797. &parsingResult.sec);
  3798. }
  3799. else
  3800. {
  3801. // Original data without Z
  3802. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3803. &parsingResult.year,
  3804. &parsingResult.month,
  3805. &parsingResult.mday,
  3806. &parsingResult.hour,
  3807. &parsingResult.min,
  3808. &parsingResult.sec,
  3809. &parsingResult.tz_hour,
  3810. &parsingResult.tz_min);
  3811. }
  3812. }
  3813. if(parsingResult.scanedElement >= 6)
  3814. {
  3815. tmStart.tm_year = parsingResult.year - 1900;
  3816. tmStart.tm_mon = parsingResult.month - 1;
  3817. tmStart.tm_mday = parsingResult.mday;
  3818. tmStart.tm_hour = parsingResult.hour;
  3819. tmStart.tm_min = parsingResult.min;
  3820. tmStart.tm_sec = parsingResult.sec;
  3821. tmStart.tm_gmtoff = 0;
  3822. tbStart.time = mktime(&tmStart);
  3823. tbStart.timezone = 0;
  3824. tbStart.millitm = 0;
  3825. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3826. if(DiffTimebWithNowSec(tbStart) <= 0)
  3827. result = NO;
  3828. else
  3829. result = YES;
  3830. }
  3831. else
  3832. {
  3833. DEBUG_WARN("Start date parsing error.\n");
  3834. }
  3835. return result;
  3836. }
  3837. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3838. {
  3839. struct ParsingResult
  3840. {
  3841. int result;
  3842. int scanedElement;
  3843. int year;
  3844. int month;
  3845. int mday;
  3846. int hour;
  3847. int min;
  3848. int sec;
  3849. int tz_hour;
  3850. int tz_min;
  3851. float minSec;
  3852. };
  3853. struct ParsingResult parseStart;
  3854. struct ParsingResult parseStop;
  3855. int result = -1;
  3856. struct tm tmStart;
  3857. struct timeb tbStart;
  3858. struct tm tmStop;
  3859. struct timeb tbStop;
  3860. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3861. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3862. // Scan start & stop date time
  3863. if(strstr((char*)start, ".") != NULL)
  3864. {
  3865. // Original data with mini second
  3866. if(strstr((char*)start, "Z") != NULL)
  3867. {
  3868. // Original data with Z
  3869. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3870. &parseStart.year,
  3871. &parseStart.month,
  3872. &parseStart.mday,
  3873. &parseStart.hour,
  3874. &parseStart.min,
  3875. &parseStart.sec,
  3876. &parseStart.minSec);
  3877. }
  3878. else
  3879. {
  3880. // Original data without Z
  3881. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3882. &parseStart.year,
  3883. &parseStart.month,
  3884. &parseStart.mday,
  3885. &parseStart.hour,
  3886. &parseStart.min,
  3887. &parseStart.sec,
  3888. &parseStart.minSec,
  3889. &parseStart.tz_hour,
  3890. &parseStart.tz_min);
  3891. }
  3892. }
  3893. else
  3894. {
  3895. // Original data without mini second
  3896. if(strstr((char*)start, "Z") != NULL)
  3897. {
  3898. // Original data with Z
  3899. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3900. &parseStart.year,
  3901. &parseStart.month,
  3902. &parseStart.mday,
  3903. &parseStart.hour,
  3904. &parseStart.min,
  3905. &parseStart.sec);
  3906. }
  3907. else
  3908. {
  3909. // Original data without Z
  3910. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3911. &parseStart.year,
  3912. &parseStart.month,
  3913. &parseStart.mday,
  3914. &parseStart.hour,
  3915. &parseStart.min,
  3916. &parseStart.sec,
  3917. &parseStart.tz_hour,
  3918. &parseStart.tz_min);
  3919. }
  3920. }
  3921. if(strstr((char*)stop, ".") != NULL)
  3922. {
  3923. // Original data with mini second
  3924. if(strstr((char*)stop, "Z") != NULL)
  3925. {
  3926. // Original data with Z
  3927. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3928. &parseStop.year,
  3929. &parseStop.month,
  3930. &parseStop.mday,
  3931. &parseStop.hour,
  3932. &parseStop.min,
  3933. &parseStop.sec,
  3934. &parseStop.minSec);
  3935. }
  3936. else
  3937. {
  3938. // Original data without Z
  3939. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3940. &parseStop.year,
  3941. &parseStop.month,
  3942. &parseStop.mday,
  3943. &parseStop.hour,
  3944. &parseStop.min,
  3945. &parseStop.sec,
  3946. &parseStop.minSec,
  3947. &parseStop.tz_hour,
  3948. &parseStop.tz_min);
  3949. }
  3950. }
  3951. else
  3952. {
  3953. // Original data without mini second
  3954. if(strstr((char*)stop, "Z") != NULL)
  3955. {
  3956. // Original data with Z
  3957. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3958. &parseStop.year,
  3959. &parseStop.month,
  3960. &parseStop.mday,
  3961. &parseStop.hour,
  3962. &parseStop.min,
  3963. &parseStop.sec);
  3964. }
  3965. else
  3966. {
  3967. // Original data without Z
  3968. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3969. &parseStop.year,
  3970. &parseStop.month,
  3971. &parseStop.mday,
  3972. &parseStop.hour,
  3973. &parseStop.min,
  3974. &parseStop.sec,
  3975. &parseStop.tz_hour,
  3976. &parseStop.tz_min);
  3977. }
  3978. }
  3979. // Calculate date time difference
  3980. if((parseStart.scanedElement >=6) &&
  3981. (parseStop.scanedElement >=6))
  3982. {
  3983. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  3984. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  3985. tmStart.tm_year = parseStart.year - 1900;
  3986. tmStart.tm_mon = parseStart.month - 1;
  3987. tmStart.tm_mday = parseStart.mday;
  3988. tmStart.tm_hour = parseStart.hour;
  3989. tmStart.tm_min = parseStart.min;
  3990. tmStart.tm_sec = parseStart.sec;
  3991. tmStart.tm_gmtoff = 0;
  3992. tbStart.time = mktime(&tmStart);
  3993. tbStart.timezone = 0;
  3994. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3995. tmStop.tm_year = parseStop.year - 1900;
  3996. tmStop.tm_mon = parseStop.month - 1;
  3997. tmStop.tm_mday = parseStop.mday;
  3998. tmStop.tm_hour = parseStop.hour;
  3999. tmStop.tm_min = parseStop.min;
  4000. tmStop.tm_sec = parseStop.sec;
  4001. tmStop.tm_gmtoff = 0;
  4002. tbStop.time = mktime(&tmStop);
  4003. tbStop.timezone = 0;
  4004. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  4005. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  4006. //DEBUG_INFO("getStartStop(): %d\n", result);
  4007. }
  4008. else
  4009. {
  4010. DEBUG_WARN("Start or stop date parsing error.\r\n");
  4011. }
  4012. return result;
  4013. }
  4014. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4015. {
  4016. FILE *fp;
  4017. char profileFileName[128];
  4018. char *line = NULL;
  4019. size_t len = 0;
  4020. time_t CurrentTime;
  4021. struct tm *tmComposite;
  4022. struct ChargingProfileType maxProfile;
  4023. struct ChargingProfileType compositeProfile;
  4024. uint8_t limitMax=0;
  4025. int compositePeriodIdx = 0;
  4026. CurrentTime = time(NULL);
  4027. tmComposite=localtime(&CurrentTime);
  4028. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].startSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  4029. if(isUnitA)
  4030. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4031. else
  4032. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4033. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4034. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4035. {
  4036. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4037. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4038. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4039. }
  4040. compositeProfile.id = 0;
  4041. compositeProfile.stackLevel = 99 ;
  4042. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  4043. maxProfile.id = -1;
  4044. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4045. system("rm -f /tmp/*.json");
  4046. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4047. // Search max profile
  4048. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4049. if((access(profileFileName, F_OK))!=-1)
  4050. {
  4051. fp = fopen(profileFileName, "r");
  4052. while(getline(&line, &len, fp) != -1)
  4053. {
  4054. json_object *obj = NULL;
  4055. obj = json_tokener_parse(line);
  4056. if(is_error(obj))
  4057. {
  4058. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4059. }
  4060. else
  4061. {
  4062. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4063. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4064. )
  4065. {
  4066. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4067. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4068. )
  4069. {
  4070. struct tm tmFrom, tmTo;
  4071. struct timeb tbFrom, tbTo;
  4072. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  4073. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  4074. {
  4075. tmFrom.tm_year -= 1900;
  4076. tmFrom.tm_mon -= 1;
  4077. tbFrom.time = mktime(&tmFrom);
  4078. tmTo.tm_year -= 1900;
  4079. tmTo.tm_mon -= 1;
  4080. tbTo.time = mktime(&tmTo);
  4081. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4082. {
  4083. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4084. {
  4085. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4086. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4087. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4088. }
  4089. if(maxProfile.id == -1)
  4090. DEBUG_INFO("MaxProfile found.\n");
  4091. else
  4092. DEBUG_INFO("MaxProfile updated.\n");
  4093. // Required item
  4094. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4095. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4096. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4097. if(isUnitA)
  4098. {
  4099. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4100. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4101. {
  4102. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4103. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4104. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4107. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4108. else
  4109. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4110. }
  4111. else
  4112. {
  4113. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4114. }*/
  4115. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4116. }
  4117. }
  4118. else
  4119. {
  4120. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4121. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4122. {
  4123. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4124. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4125. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4126. {
  4127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4128. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4129. else
  4130. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4131. }
  4132. else
  4133. {
  4134. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4135. }*/
  4136. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4137. }
  4138. }
  4139. // Optional item
  4140. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4141. {
  4142. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4143. }
  4144. else
  4145. {
  4146. sprintf((char*)maxProfile.validFrom, " ");
  4147. }
  4148. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4149. {
  4150. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4151. }
  4152. else
  4153. {
  4154. sprintf((char*)maxProfile.validTo, " ");
  4155. }
  4156. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4157. {
  4158. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4159. }
  4160. else
  4161. {
  4162. sprintf((char*)maxProfile.recurrencyKind, " ");
  4163. }
  4164. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4165. {
  4166. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4167. }
  4168. else
  4169. {
  4170. sprintf((char*)maxProfile.transactionId, " ");
  4171. }
  4172. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4173. {
  4174. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4175. }
  4176. else
  4177. {
  4178. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4179. }
  4180. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4181. {
  4182. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4183. }
  4184. else
  4185. {
  4186. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4187. }
  4188. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4189. {
  4190. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4191. }
  4192. else
  4193. {
  4194. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4195. }
  4196. }
  4197. }
  4198. }
  4199. else
  4200. {
  4201. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4202. {
  4203. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4204. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4205. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4206. }
  4207. if(maxProfile.id == -1)
  4208. DEBUG_INFO("MaxProfile found.\n");
  4209. else
  4210. DEBUG_INFO("MaxProfile updated.\n");
  4211. // Required item
  4212. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4213. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4214. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4215. if(isUnitA)
  4216. {
  4217. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4218. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4219. {
  4220. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4221. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4222. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4223. {
  4224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4225. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4226. else
  4227. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4228. }
  4229. else
  4230. {
  4231. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4232. }*/
  4233. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4234. }
  4235. }
  4236. else
  4237. {
  4238. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4239. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4240. {
  4241. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4242. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4243. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4244. {
  4245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4246. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4247. else
  4248. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4249. }
  4250. else
  4251. {
  4252. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4253. }*/
  4254. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4255. }
  4256. }
  4257. // Optional item
  4258. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4259. {
  4260. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4261. }
  4262. else
  4263. {
  4264. sprintf((char*)maxProfile.validFrom, " ");
  4265. }
  4266. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4267. {
  4268. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4269. }
  4270. else
  4271. {
  4272. sprintf((char*)maxProfile.validTo, " ");
  4273. }
  4274. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4275. {
  4276. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4277. }
  4278. else
  4279. {
  4280. sprintf((char*)maxProfile.recurrencyKind, " ");
  4281. }
  4282. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4283. {
  4284. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4285. }
  4286. else
  4287. {
  4288. sprintf((char*)maxProfile.transactionId, " ");
  4289. }
  4290. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4291. {
  4292. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4293. }
  4294. else
  4295. {
  4296. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4297. }
  4298. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4299. {
  4300. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4301. }
  4302. else
  4303. {
  4304. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4305. }
  4306. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4307. {
  4308. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4309. }
  4310. else
  4311. {
  4312. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4313. }
  4314. }
  4315. }
  4316. }
  4317. json_object_put(obj);
  4318. }
  4319. fclose(fp);
  4320. /*
  4321. if(maxProfile.id !=-1)
  4322. {
  4323. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4324. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4325. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4326. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4327. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4328. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4329. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4330. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4331. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4332. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4333. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4334. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4335. {
  4336. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4337. {
  4338. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4339. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4340. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4341. }
  4342. }
  4343. }
  4344. else
  4345. DEBUG_INFO("MaxProfile not found.\n");
  4346. DEBUG_INFO("------------------------------------\n");*/
  4347. }
  4348. if(maxProfile.id != -1)
  4349. {
  4350. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4351. {
  4352. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4353. {
  4354. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4355. 0:
  4356. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4357. }
  4358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4359. {
  4360. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4361. {
  4362. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4363. 0:
  4364. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4365. if(idxPeriod > 0)
  4366. {
  4367. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4368. {
  4369. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4370. }
  4371. }
  4372. }
  4373. }
  4374. }
  4375. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4376. {
  4377. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4378. {
  4379. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  4380. }
  4381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4382. {
  4383. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4384. {
  4385. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  4386. if(idxPeriod > 0)
  4387. {
  4388. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4389. {
  4390. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4391. }
  4392. }
  4393. }
  4394. }
  4395. }
  4396. else
  4397. {
  4398. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4399. {
  4400. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4401. {
  4402. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4403. 0:
  4404. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4405. }
  4406. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4407. {
  4408. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4409. {
  4410. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4411. 0:
  4412. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4413. if(idxPeriod > 0)
  4414. {
  4415. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4416. {
  4417. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4418. }
  4419. }
  4420. }
  4421. }
  4422. }
  4423. else
  4424. {
  4425. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4426. {
  4427. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4428. 0:
  4429. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4430. }
  4431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4432. {
  4433. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4434. {
  4435. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4436. 0:
  4437. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4438. if(idxPeriod > 0)
  4439. {
  4440. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4441. {
  4442. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4443. }
  4444. }
  4445. }
  4446. }
  4447. }
  4448. }
  4449. /*
  4450. DEBUG_INFO("MaxProfile after align.\n");
  4451. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4452. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4453. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4454. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4455. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4456. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4457. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4458. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4459. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4460. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4461. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4463. {
  4464. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4465. {
  4466. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4467. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4468. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4469. }
  4470. }
  4471. DEBUG_INFO("------------------------------------\n");*/
  4472. }
  4473. // Find each profile period quantity
  4474. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4475. {
  4476. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4477. limitMax = idx+1;
  4478. }
  4479. if(maxProfile.id != -1)
  4480. {
  4481. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4482. {
  4483. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4484. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4485. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4486. {
  4487. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4488. {
  4489. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4490. compositePeriodIdx++;
  4491. }
  4492. else
  4493. {
  4494. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4495. }
  4496. }
  4497. }
  4498. }
  4499. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4500. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4501. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4502. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4503. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4504. {
  4505. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4506. {
  4507. compositeProfile.id = 1;
  4508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4511. }
  4512. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4513. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4514. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4515. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4516. }
  4517. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4518. if(line)
  4519. free(line);
  4520. }
  4521. void checkCompositeSchedule(uint8_t evseId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4522. {
  4523. FILE *fp;
  4524. char profileFileName[128];
  4525. char *line = NULL;
  4526. size_t len = 0;
  4527. time_t CurrentTime;
  4528. struct tm *tmComposite;
  4529. struct ChargingProfileType maxProfile;
  4530. struct ChargingProfileType defaultTxProfile;
  4531. struct ChargingProfileType txProfile;
  4532. struct ChargingProfileType compositeProfile;
  4533. struct ChargingSchedulePeriodType tmpPeriod;
  4534. uint8_t limitMax=0;
  4535. uint8_t limitDef=0;
  4536. uint8_t limitTx=0;
  4537. int compositePeriodIdx = 0;
  4538. CurrentTime = time(NULL);
  4539. tmComposite=localtime(&CurrentTime);
  4540. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].startSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  4541. if(isUnitA)
  4542. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4543. else
  4544. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4545. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4547. {
  4548. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4549. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4550. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4551. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4552. }
  4553. compositeProfile.id = 0;
  4554. compositeProfile.stackLevel = 99 ;
  4555. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4556. maxProfile.id = -1;
  4557. defaultTxProfile.id = -1;
  4558. txProfile.id = -1;
  4559. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4560. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4561. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4562. system("rm -f /tmp/*.json");
  4563. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4564. /*
  4565. * Search valid charging profile
  4566. */
  4567. //DEBUG_INFO("====================================\n");
  4568. // Search tx profile
  4569. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", evseId);
  4570. if((access(profileFileName, F_OK))!=-1)
  4571. {
  4572. fp = fopen(profileFileName, "r");
  4573. while(getline(&line, &len, fp) != -1)
  4574. {
  4575. json_object *obj = NULL;
  4576. obj = json_tokener_parse(line);
  4577. if(is_error(obj))
  4578. {
  4579. DEBUG_ERROR("Parse txProfile from file error.\n");
  4580. }
  4581. else
  4582. {
  4583. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4584. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4585. )
  4586. {
  4587. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4588. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4589. )
  4590. {
  4591. struct tm tmFrom, tmTo;
  4592. struct timeb tbFrom, tbTo;
  4593. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  4594. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  4595. {
  4596. tmFrom.tm_year -= 1900;
  4597. tmFrom.tm_mon -= 1;
  4598. tbFrom.time = mktime(&tmFrom);
  4599. tmTo.tm_year -= 1900;
  4600. tmTo.tm_mon -= 1;
  4601. tbTo.time = mktime(&tmTo);
  4602. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4603. {
  4604. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4605. {
  4606. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4607. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4608. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4609. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4610. }
  4611. if(txProfile.id == -1)
  4612. DEBUG_INFO("TxProfile found.\n");
  4613. else
  4614. DEBUG_INFO("TxProfile updated.\n");
  4615. // Required item
  4616. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4617. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4618. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4619. if(isUnitA)
  4620. {
  4621. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4622. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4623. {
  4624. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4625. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4626. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4629. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4630. else
  4631. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4632. }
  4633. else
  4634. {
  4635. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4636. }*/
  4637. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4638. }
  4639. }
  4640. else
  4641. {
  4642. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4643. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4644. {
  4645. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4646. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4647. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4648. {
  4649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4650. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4651. else
  4652. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4653. }
  4654. else
  4655. {
  4656. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4657. }*/
  4658. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4659. }
  4660. }
  4661. // Optional item
  4662. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4663. {
  4664. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4665. }
  4666. else
  4667. {
  4668. sprintf((char*)txProfile.validFrom, " ");
  4669. }
  4670. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4671. {
  4672. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4673. }
  4674. else
  4675. {
  4676. sprintf((char*)txProfile.validTo, " ");
  4677. }
  4678. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4679. {
  4680. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4681. }
  4682. else
  4683. {
  4684. sprintf((char*)txProfile.recurrencyKind, " ");
  4685. }
  4686. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4687. {
  4688. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4689. }
  4690. else
  4691. {
  4692. sprintf((char*)txProfile.transactionId, " ");
  4693. }
  4694. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4695. {
  4696. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4697. }
  4698. else
  4699. {
  4700. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4701. }
  4702. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4703. {
  4704. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4705. }
  4706. else
  4707. {
  4708. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4709. }
  4710. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4711. {
  4712. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4713. }
  4714. else
  4715. {
  4716. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4717. }
  4718. }
  4719. }
  4720. }
  4721. else
  4722. {
  4723. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4724. {
  4725. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4726. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4727. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4728. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4729. }
  4730. if(txProfile.id == -1)
  4731. DEBUG_INFO("TxProfile found.\n");
  4732. else
  4733. DEBUG_INFO("TxProfile updated.\n");
  4734. // Required item
  4735. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4736. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4737. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4738. if(isUnitA)
  4739. {
  4740. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4741. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4742. {
  4743. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4744. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4745. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4746. {
  4747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4748. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4749. else
  4750. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4751. }
  4752. else
  4753. {
  4754. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4755. }*/
  4756. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4757. }
  4758. }
  4759. else
  4760. {
  4761. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4762. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4763. {
  4764. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4765. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4766. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4769. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4770. else
  4771. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4772. }
  4773. else
  4774. {
  4775. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4776. }*/
  4777. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4778. }
  4779. }
  4780. // Optional item
  4781. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4782. {
  4783. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4784. }
  4785. else
  4786. {
  4787. sprintf((char*)txProfile.validFrom, " ");
  4788. }
  4789. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4790. {
  4791. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4792. }
  4793. else
  4794. {
  4795. sprintf((char*)txProfile.validTo, " ");
  4796. }
  4797. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4798. {
  4799. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4800. }
  4801. else
  4802. {
  4803. sprintf((char*)txProfile.recurrencyKind, " ");
  4804. }
  4805. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4806. {
  4807. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4808. }
  4809. else
  4810. {
  4811. sprintf((char*)txProfile.transactionId, " ");
  4812. }
  4813. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4814. {
  4815. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4816. }
  4817. else
  4818. {
  4819. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4820. }
  4821. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4822. {
  4823. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4824. }
  4825. else
  4826. {
  4827. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4828. }
  4829. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4830. {
  4831. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4832. }
  4833. else
  4834. {
  4835. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4836. }
  4837. }
  4838. }
  4839. }
  4840. json_object_put(obj);
  4841. }
  4842. fclose(fp);
  4843. /*
  4844. if(txProfile.id != -1)
  4845. {
  4846. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4847. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4848. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4849. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4850. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4851. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4852. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4853. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4854. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4855. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4856. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4858. {
  4859. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4860. {
  4861. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4862. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4863. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4864. }
  4865. }
  4866. }
  4867. else
  4868. DEBUG_INFO("TxProfile not found.\n");*/
  4869. }
  4870. // Search default tx profile
  4871. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", evseId);
  4872. if((access(profileFileName, F_OK))==-1)
  4873. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4874. if((access(profileFileName, F_OK))!=-1)
  4875. {
  4876. fp = fopen(profileFileName, "r");
  4877. while(getline(&line, &len, fp) != -1)
  4878. {
  4879. json_object *obj = NULL;
  4880. obj = json_tokener_parse(line);
  4881. if(is_error(obj))
  4882. {
  4883. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4884. }
  4885. else
  4886. {
  4887. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  4888. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  4889. )
  4890. {
  4891. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4892. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4893. )
  4894. {
  4895. struct tm tmFrom, tmTo;
  4896. struct timeb tbFrom, tbTo;
  4897. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  4898. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  4899. {
  4900. tmFrom.tm_year -= 1900;
  4901. tmFrom.tm_mon -= 1;
  4902. tbFrom.time = mktime(&tmFrom);
  4903. tmTo.tm_year -= 1900;
  4904. tmTo.tm_mon -= 1;
  4905. tbTo.time = mktime(&tmTo);
  4906. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4907. {
  4908. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4909. {
  4910. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4911. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4912. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4913. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4914. }
  4915. if(defaultTxProfile.id == -1)
  4916. DEBUG_INFO("TxDefaultProfile found.\n");
  4917. else
  4918. DEBUG_INFO("TxDefaultProfile updated.\n");
  4919. // Required item
  4920. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4921. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4922. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4923. if(isUnitA)
  4924. {
  4925. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4926. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4927. {
  4928. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4929. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4930. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4931. {
  4932. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4933. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4934. else
  4935. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4936. }
  4937. else
  4938. {
  4939. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4940. }*/
  4941. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4942. }
  4943. }
  4944. else
  4945. {
  4946. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4947. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4948. {
  4949. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4950. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4951. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4952. {
  4953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4954. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4955. else
  4956. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4957. }
  4958. else
  4959. {
  4960. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4961. }*/
  4962. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4963. }
  4964. }
  4965. // Optional item
  4966. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4967. {
  4968. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4969. }
  4970. else
  4971. {
  4972. sprintf((char*)defaultTxProfile.validFrom, " ");
  4973. }
  4974. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4975. {
  4976. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4977. }
  4978. else
  4979. {
  4980. sprintf((char*)defaultTxProfile.validTo, " ");
  4981. }
  4982. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4983. {
  4984. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4985. }
  4986. else
  4987. {
  4988. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4989. }
  4990. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4991. {
  4992. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4993. }
  4994. else
  4995. {
  4996. sprintf((char*)defaultTxProfile.transactionId, " ");
  4997. }
  4998. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4999. {
  5000. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  5001. }
  5002. else
  5003. {
  5004. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5005. }
  5006. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5007. {
  5008. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  5009. }
  5010. else
  5011. {
  5012. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5013. }
  5014. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5015. {
  5016. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  5017. }
  5018. else
  5019. {
  5020. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5021. }
  5022. }
  5023. }
  5024. }
  5025. else
  5026. {
  5027. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5028. {
  5029. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5030. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5031. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5032. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5033. }
  5034. if(defaultTxProfile.id == -1)
  5035. DEBUG_INFO("TxDefaultProfile found.\n");
  5036. else
  5037. DEBUG_INFO("TxDefaultProfile updated.\n");
  5038. // Required item
  5039. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5040. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5041. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5042. if(isUnitA)
  5043. {
  5044. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5045. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  5046. {
  5047. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  5048. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5049. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5052. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5053. else
  5054. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5055. }
  5056. else
  5057. {
  5058. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5059. }*/
  5060. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  5061. }
  5062. }
  5063. else
  5064. {
  5065. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5066. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  5067. {
  5068. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  5069. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5070. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5071. {
  5072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5073. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5074. else
  5075. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5076. }
  5077. else
  5078. {
  5079. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5080. }*/
  5081. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  5082. }
  5083. }
  5084. // Optional item
  5085. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5086. {
  5087. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5088. }
  5089. else
  5090. {
  5091. sprintf((char*)defaultTxProfile.validFrom, " ");
  5092. }
  5093. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5094. {
  5095. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5096. }
  5097. else
  5098. {
  5099. sprintf((char*)defaultTxProfile.validTo, " ");
  5100. }
  5101. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5102. {
  5103. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5104. }
  5105. else
  5106. {
  5107. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5108. }
  5109. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5110. {
  5111. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5112. }
  5113. else
  5114. {
  5115. sprintf((char*)defaultTxProfile.transactionId, " ");
  5116. }
  5117. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5118. {
  5119. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  5120. }
  5121. else
  5122. {
  5123. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5124. }
  5125. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5126. {
  5127. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  5128. }
  5129. else
  5130. {
  5131. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5132. }
  5133. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5134. {
  5135. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  5136. }
  5137. else
  5138. {
  5139. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5140. }
  5141. }
  5142. }
  5143. }
  5144. json_object_put(obj);
  5145. }
  5146. fclose(fp);
  5147. /*
  5148. if(defaultTxProfile.id != -1)
  5149. {
  5150. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5151. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5152. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5153. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5154. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5155. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5156. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5157. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5158. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5159. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5160. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5161. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5162. {
  5163. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5164. {
  5165. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5166. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5167. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5168. }
  5169. }
  5170. }
  5171. else
  5172. DEBUG_INFO("TxDefaultProfile not found.\n");
  5173. DEBUG_INFO("------------------------------------\n");*/
  5174. }
  5175. // Search max profile
  5176. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  5177. if((access(profileFileName, F_OK))!=-1)
  5178. {
  5179. fp = fopen(profileFileName, "r");
  5180. while(getline(&line, &len, fp) != -1)
  5181. {
  5182. json_object *obj = NULL;
  5183. obj = json_tokener_parse(line);
  5184. if(is_error(obj))
  5185. {
  5186. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  5187. }
  5188. else
  5189. {
  5190. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  5191. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  5192. )
  5193. {
  5194. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5195. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5196. )
  5197. {
  5198. struct tm tmFrom, tmTo;
  5199. struct timeb tbFrom, tbTo;
  5200. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  5201. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  5202. {
  5203. tmFrom.tm_year -= 1900;
  5204. tmFrom.tm_mon -= 1;
  5205. tbFrom.time = mktime(&tmFrom);
  5206. tmTo.tm_year -= 1900;
  5207. tmTo.tm_mon -= 1;
  5208. tbTo.time = mktime(&tmTo);
  5209. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5210. {
  5211. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5212. {
  5213. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5214. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5215. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5216. }
  5217. if(maxProfile.id == -1)
  5218. DEBUG_INFO("MaxProfile found.\n");
  5219. else
  5220. DEBUG_INFO("MaxProfile updated.\n");
  5221. // Required item
  5222. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5223. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5224. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5225. if(isUnitA)
  5226. {
  5227. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5228. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  5229. {
  5230. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  5231. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5232. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5233. {
  5234. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5235. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5236. else
  5237. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5238. }
  5239. else
  5240. {
  5241. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5242. }*/
  5243. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  5244. }
  5245. }
  5246. else
  5247. {
  5248. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5249. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  5250. {
  5251. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  5252. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5253. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5254. {
  5255. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5256. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5257. else
  5258. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5259. }
  5260. else
  5261. {
  5262. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5263. }*/
  5264. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  5265. }
  5266. }
  5267. // Optional item
  5268. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5269. {
  5270. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5271. }
  5272. else
  5273. {
  5274. sprintf((char*)maxProfile.validFrom, " ");
  5275. }
  5276. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5277. {
  5278. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5279. }
  5280. else
  5281. {
  5282. sprintf((char*)maxProfile.validTo, " ");
  5283. }
  5284. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5285. {
  5286. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5287. }
  5288. else
  5289. {
  5290. sprintf((char*)maxProfile.recurrencyKind, " ");
  5291. }
  5292. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5293. {
  5294. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5295. }
  5296. else
  5297. {
  5298. sprintf((char*)maxProfile.transactionId, " ");
  5299. }
  5300. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5301. {
  5302. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  5303. }
  5304. else
  5305. {
  5306. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5307. }
  5308. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5309. {
  5310. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  5311. }
  5312. else
  5313. {
  5314. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5315. }
  5316. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5317. {
  5318. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  5319. }
  5320. else
  5321. {
  5322. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5323. }
  5324. }
  5325. }
  5326. }
  5327. else
  5328. {
  5329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5330. {
  5331. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5332. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5333. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5334. }
  5335. if(maxProfile.id == -1)
  5336. DEBUG_INFO("MaxProfile found.\n");
  5337. else
  5338. DEBUG_INFO("MaxProfile updated.\n");
  5339. // Required item
  5340. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5341. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5342. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5343. if(isUnitA)
  5344. {
  5345. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5346. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  5347. {
  5348. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  5349. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5350. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5351. {
  5352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5353. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5354. else
  5355. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5356. }
  5357. else
  5358. {
  5359. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5360. }*/
  5361. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  5362. }
  5363. }
  5364. else
  5365. {
  5366. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5367. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  5368. {
  5369. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  5370. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5371. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5372. {
  5373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5374. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5375. else
  5376. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5377. }
  5378. else
  5379. {
  5380. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5381. }*/
  5382. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  5383. }
  5384. }
  5385. // Optional item
  5386. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5387. {
  5388. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5389. }
  5390. else
  5391. {
  5392. sprintf((char*)maxProfile.validFrom, " ");
  5393. }
  5394. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5395. {
  5396. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5397. }
  5398. else
  5399. {
  5400. sprintf((char*)maxProfile.validTo, " ");
  5401. }
  5402. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5403. {
  5404. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5405. }
  5406. else
  5407. {
  5408. sprintf((char*)maxProfile.recurrencyKind, " ");
  5409. }
  5410. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5411. {
  5412. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5413. }
  5414. else
  5415. {
  5416. sprintf((char*)maxProfile.transactionId, " ");
  5417. }
  5418. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5419. {
  5420. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  5421. }
  5422. else
  5423. {
  5424. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5425. }
  5426. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5427. {
  5428. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  5429. }
  5430. else
  5431. {
  5432. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5433. }
  5434. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5435. {
  5436. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  5437. }
  5438. else
  5439. {
  5440. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5441. }
  5442. }
  5443. }
  5444. }
  5445. json_object_put(obj);
  5446. }
  5447. fclose(fp);
  5448. /*
  5449. if(maxProfile.id !=-1)
  5450. {
  5451. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5452. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5453. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5454. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5455. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5456. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5457. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5458. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5459. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5460. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5461. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5463. {
  5464. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5465. {
  5466. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5467. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5468. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5469. }
  5470. }
  5471. }
  5472. else
  5473. DEBUG_INFO("MaxProfile not found.\n");
  5474. DEBUG_INFO("------------------------------------\n");*/
  5475. }
  5476. /*
  5477. * Align found profile start schedule & periods
  5478. */
  5479. //DEBUG_INFO("====================================\n");
  5480. /*
  5481. // For local test usage, force modify found profile start schedule info
  5482. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  5483. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  5484. sprintf((char*)txProfile.chargingSchedule[idxSchedule].StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  5485. */
  5486. if(txProfile.id != -1)
  5487. {
  5488. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5489. {
  5490. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5491. {
  5492. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5493. 0:
  5494. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5495. }
  5496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5497. {
  5498. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5499. {
  5500. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5501. 0:
  5502. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5503. if(idxPeriod > 0)
  5504. {
  5505. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5506. {
  5507. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5508. }
  5509. }
  5510. }
  5511. }
  5512. }
  5513. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5514. {
  5515. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5516. {
  5517. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5518. 0:
  5519. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5520. }
  5521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5522. {
  5523. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5524. {
  5525. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5526. 0:
  5527. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5528. if(idxPeriod > 0)
  5529. {
  5530. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5531. {
  5532. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5533. }
  5534. }
  5535. }
  5536. }
  5537. }
  5538. else
  5539. {
  5540. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5541. {
  5542. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5543. {
  5544. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5545. 0:
  5546. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5547. }
  5548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5549. {
  5550. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5551. {
  5552. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5553. 0:
  5554. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5555. if(idxPeriod > 0)
  5556. {
  5557. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5558. {
  5559. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5560. }
  5561. }
  5562. }
  5563. }
  5564. }
  5565. else
  5566. {
  5567. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5568. {
  5569. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5570. 0:
  5571. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5572. }
  5573. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5574. {
  5575. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5576. {
  5577. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5578. 0:
  5579. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5580. if(idxPeriod > 0)
  5581. {
  5582. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5583. {
  5584. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5585. }
  5586. }
  5587. }
  5588. }
  5589. }
  5590. }
  5591. /*
  5592. DEBUG_INFO("txProfile after align.\n");
  5593. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5594. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5595. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5596. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5597. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5598. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5599. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5600. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5601. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5602. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5603. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5604. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5605. {
  5606. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5607. {
  5608. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5609. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5610. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5611. }
  5612. }*/
  5613. }
  5614. if(defaultTxProfile.id != -1)
  5615. {
  5616. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5617. {
  5618. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5619. {
  5620. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5621. 0:
  5622. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5623. }
  5624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5625. {
  5626. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5627. {
  5628. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5629. 0:
  5630. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5631. if(idxPeriod > 0)
  5632. {
  5633. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5634. {
  5635. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5636. }
  5637. }
  5638. }
  5639. }
  5640. }
  5641. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5642. {
  5643. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5644. {
  5645. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5646. 0:
  5647. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5648. }
  5649. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5650. {
  5651. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5652. {
  5653. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5654. 0:
  5655. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5656. if(idxPeriod > 0)
  5657. {
  5658. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5659. {
  5660. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5661. }
  5662. }
  5663. }
  5664. }
  5665. }
  5666. else
  5667. {
  5668. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5669. {
  5670. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5671. {
  5672. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5673. 0:
  5674. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5675. }
  5676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5677. {
  5678. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5679. {
  5680. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5681. 0:
  5682. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5683. if(idxPeriod > 0)
  5684. {
  5685. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5686. {
  5687. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5688. }
  5689. }
  5690. }
  5691. }
  5692. }
  5693. else
  5694. {
  5695. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5696. {
  5697. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5698. 0:
  5699. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5700. }
  5701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5702. {
  5703. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5704. {
  5705. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5706. 0:
  5707. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5708. if(idxPeriod > 0)
  5709. {
  5710. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5711. {
  5712. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5713. }
  5714. }
  5715. }
  5716. }
  5717. }
  5718. }
  5719. /*
  5720. DEBUG_INFO("defaultTxProfile after align.\n");
  5721. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5722. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5723. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5724. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5725. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5726. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5727. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5728. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5729. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5730. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5731. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5732. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5733. {
  5734. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5735. {
  5736. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5737. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5738. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5739. }
  5740. }
  5741. DEBUG_INFO("------------------------------------\n");*/
  5742. }
  5743. if(maxProfile.id != -1)
  5744. {
  5745. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5746. {
  5747. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5748. {
  5749. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5750. 0:
  5751. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5752. }
  5753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5754. {
  5755. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5756. {
  5757. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5758. 0:
  5759. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5760. if(idxPeriod > 0)
  5761. {
  5762. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5763. {
  5764. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5765. }
  5766. }
  5767. }
  5768. }
  5769. }
  5770. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5771. {
  5772. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5773. {
  5774. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5775. 0:
  5776. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5777. }
  5778. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5779. {
  5780. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5781. {
  5782. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5783. 0:
  5784. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5785. if(idxPeriod > 0)
  5786. {
  5787. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5788. {
  5789. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5790. }
  5791. }
  5792. }
  5793. }
  5794. }
  5795. else
  5796. {
  5797. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5798. {
  5799. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5800. {
  5801. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5802. 0:
  5803. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5804. }
  5805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5806. {
  5807. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5808. {
  5809. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5810. 0:
  5811. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5812. if(idxPeriod > 0)
  5813. {
  5814. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5815. {
  5816. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5817. }
  5818. }
  5819. }
  5820. }
  5821. }
  5822. else
  5823. {
  5824. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5825. {
  5826. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5827. 0:
  5828. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5829. }
  5830. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5831. {
  5832. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5833. {
  5834. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5835. 0:
  5836. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5837. if(idxPeriod > 0)
  5838. {
  5839. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5840. {
  5841. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5842. }
  5843. }
  5844. }
  5845. }
  5846. }
  5847. }
  5848. /*
  5849. DEBUG_INFO("MaxProfile after align.\n");
  5850. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5851. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5852. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5853. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5854. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5855. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5856. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5857. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5858. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5859. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5860. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5861. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5862. {
  5863. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5864. {
  5865. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5866. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5867. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5868. }
  5869. }
  5870. DEBUG_INFO("------------------------------------\n");*/
  5871. }
  5872. /*
  5873. * Merge to conposite schedule
  5874. */
  5875. //DEBUG_INFO("====================================\n");
  5876. // Find each profile period quantity
  5877. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5878. {
  5879. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5880. limitMax = idx+1;
  5881. }
  5882. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5883. {
  5884. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5885. limitDef = idx+1;
  5886. }
  5887. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5888. {
  5889. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5890. limitTx = idx+1;
  5891. }
  5892. // TxProfile found, composite schedule based on it
  5893. if(txProfile.id != -1)
  5894. {
  5895. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  5896. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  5897. {
  5898. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  5899. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  5900. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  5901. {
  5902. if(maxProfile.id != -1)
  5903. {
  5904. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5905. {
  5906. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  5907. {
  5908. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5909. {
  5910. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5911. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5912. tmpPeriod.limit = (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit>maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit:txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit);
  5913. }
  5914. else
  5915. {
  5916. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5917. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5918. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  5919. }
  5920. }
  5921. if(idxMaxPeriod == (limitMax-1))
  5922. {
  5923. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5924. {
  5925. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5926. {
  5927. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5928. compositePeriodIdx++;
  5929. }
  5930. else
  5931. {
  5932. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5933. }
  5934. }
  5935. }
  5936. }
  5937. }
  5938. else
  5939. {
  5940. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5941. {
  5942. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5943. compositePeriodIdx++;
  5944. }
  5945. else
  5946. {
  5947. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5948. }
  5949. }
  5950. }
  5951. if(idxTxPeriod == (limitTx-1))
  5952. {
  5953. if(defaultTxProfile.id != -1)
  5954. {
  5955. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  5956. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5957. {
  5958. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  5959. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5960. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  5961. {
  5962. if(maxProfile.id != -1)
  5963. {
  5964. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5965. {
  5966. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5967. {
  5968. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5969. {
  5970. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5971. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5972. tmpPeriod.limit = (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit>maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit:defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit);
  5973. }
  5974. else
  5975. {
  5976. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5977. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5978. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5979. }
  5980. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5981. {
  5982. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5983. {
  5984. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5985. compositePeriodIdx++;
  5986. }
  5987. else
  5988. {
  5989. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5990. }
  5991. }
  5992. // Delete duplicate period
  5993. if(compositePeriodIdx > 1)
  5994. {
  5995. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5996. {
  5997. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5998. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5999. compositePeriodIdx -= 1;
  6000. }
  6001. }
  6002. }
  6003. else
  6004. {
  6005. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6006. {
  6007. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6008. compositePeriodIdx++;
  6009. }
  6010. else
  6011. {
  6012. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6013. }
  6014. break;
  6015. }
  6016. }
  6017. }
  6018. else
  6019. {
  6020. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6021. {
  6022. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6023. compositePeriodIdx++;
  6024. }
  6025. else
  6026. {
  6027. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6028. }
  6029. }
  6030. }
  6031. }
  6032. }
  6033. }
  6034. }
  6035. }
  6036. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  6037. else if(defaultTxProfile.id != -1)
  6038. {
  6039. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  6040. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6041. {
  6042. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  6043. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6044. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  6045. {
  6046. if(maxProfile.id != -1)
  6047. {
  6048. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6049. {
  6050. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6051. {
  6052. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6053. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6054. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6055. {
  6056. tmpPeriod.limit = (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit>maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit:defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit);
  6057. }
  6058. else
  6059. {
  6060. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6061. }
  6062. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6063. {
  6064. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6065. {
  6066. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6067. compositePeriodIdx++;
  6068. }
  6069. else
  6070. {
  6071. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6072. }
  6073. }
  6074. // Delete duplicate period
  6075. if(compositePeriodIdx > 1)
  6076. {
  6077. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6078. {
  6079. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6080. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6081. compositePeriodIdx -= 1;
  6082. }
  6083. }
  6084. }
  6085. else
  6086. {
  6087. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6088. {
  6089. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6090. compositePeriodIdx++;
  6091. }
  6092. else
  6093. {
  6094. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6095. }
  6096. break;
  6097. }
  6098. }
  6099. }
  6100. else
  6101. {
  6102. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6103. {
  6104. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6105. compositePeriodIdx++;
  6106. }
  6107. else
  6108. {
  6109. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6110. }
  6111. }
  6112. }
  6113. }
  6114. }
  6115. // Fill other period by MaxProfile
  6116. if(maxProfile.id != -1)
  6117. {
  6118. if(compositePeriodIdx==0)
  6119. {
  6120. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  6121. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  6122. {
  6123. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6124. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6125. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6126. {
  6127. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6128. {
  6129. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6130. compositePeriodIdx++;
  6131. }
  6132. else
  6133. {
  6134. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6135. }
  6136. }
  6137. }
  6138. }
  6139. else
  6140. {
  6141. int lastCompositePeriodIdx = compositePeriodIdx;
  6142. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6143. {
  6144. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6145. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6146. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6147. {
  6148. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  6149. {
  6150. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  6151. {
  6152. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6153. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6154. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  6155. }
  6156. else
  6157. {
  6158. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6159. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6160. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  6161. }
  6162. }
  6163. if(tmpPeriod.limit != -1)
  6164. {
  6165. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  6166. {
  6167. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  6168. {
  6169. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6170. compositePeriodIdx++;
  6171. }
  6172. else
  6173. {
  6174. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6175. }
  6176. }
  6177. // Delete duplicate period
  6178. if(compositePeriodIdx > 1)
  6179. {
  6180. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6181. {
  6182. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6183. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6184. compositePeriodIdx -= 1;
  6185. }
  6186. }
  6187. }
  6188. }
  6189. }
  6190. }
  6191. }
  6192. if(compositeProfile.chargingSchedule[idxSchedule].duration < durationReq)
  6193. {
  6194. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6195. {
  6196. if((idxPeriod >= 0) && (compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1))
  6197. {
  6198. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = compositeProfile.chargingSchedule[idxSchedule].duration;
  6199. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  6200. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].numberPhases;
  6201. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  6202. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6203. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6204. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6205. DEBUG_INFO("------------------------------------------------\n");
  6206. break;
  6207. }
  6208. }
  6209. }
  6210. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  6211. DEBUG_INFO("Connector-%d composite schedule ready.\n", evseId);
  6212. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  6213. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  6214. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  6215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6216. {
  6217. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  6218. {
  6219. compositeProfile.id = 1;
  6220. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6221. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6222. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6223. }
  6224. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  6225. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  6226. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  6227. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  6228. }
  6229. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  6230. if(line)
  6231. free(line);
  6232. ShmOCPP20Data->CSUMsg.bits[(evseId==0?0:evseId-1)].ChargingProfileConf = ON;
  6233. }
  6234. //==========================================
  6235. // Init all share memory
  6236. //==========================================
  6237. int InitShareMemory()
  6238. {
  6239. int result = PASS;
  6240. int MeterSMId;
  6241. //creat ShmSysConfigAndInfo
  6242. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  6243. {
  6244. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  6245. result = FAIL;
  6246. }
  6247. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6248. {
  6249. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  6250. result = FAIL;
  6251. }
  6252. else
  6253. {}
  6254. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  6255. {
  6256. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  6257. result = FAIL;
  6258. }
  6259. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6260. {
  6261. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  6262. result = FAIL;
  6263. }
  6264. else
  6265. {}
  6266. //creat ShmPsuData
  6267. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  6268. {
  6269. DEBUG_ERROR("shmget ShmPsuData NG\n");
  6270. result = FAIL;
  6271. }
  6272. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6273. {
  6274. DEBUG_ERROR("shmat ShmPsuData NG\n");
  6275. result = FAIL;
  6276. }
  6277. else
  6278. {}
  6279. //creat ShmOCPP20Data
  6280. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  6281. {
  6282. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  6283. result = FAIL;
  6284. }
  6285. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6286. {
  6287. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  6288. result = FAIL;
  6289. }
  6290. else
  6291. {}
  6292. /****************************** For Initial Settings************************************************/
  6293. /*
  6294. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  6295. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  6296. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  6297. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  6298. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  6299. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  6300. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  6301. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  6302. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  6303. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  6304. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  6305. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  6306. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  6307. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  6308. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  6309. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  6310. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  6311. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  6312. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  6313. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  6314. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  6315. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  6316. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  6317. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  6318. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  6319. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  6320. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  6321. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  6322. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  6323. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  6324. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  6325. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  6326. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  6327. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  6328. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  6329. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  6330. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  6331. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  6332. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  6333. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  6334. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  6335. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  6336. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  6337. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  6338. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  6339. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  6340. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  6341. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  6342. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  6343. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  6344. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  6345. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  6346. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  6347. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  6348. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  6349. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  6350. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  6351. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  6352. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  6353. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  6354. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  6355. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  6356. */
  6357. return result;
  6358. }
  6359. int ProcessShareMemory()
  6360. {
  6361. int result = PASS;
  6362. if(InitShareMemory() == FAIL)
  6363. {
  6364. DEBUG_ERROR("InitShareMemory NG\n");
  6365. if(ShmStatusCodeData!=NULL)
  6366. {
  6367. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  6368. }
  6369. result = FAIL;
  6370. }
  6371. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  6372. {
  6373. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  6374. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6375. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  6376. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  6377. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  6378. ) // 'D' means DC
  6379. {
  6380. // DO series
  6381. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  6382. {
  6383. gunTotalNumber += 1;
  6384. gunType[gun_index] = GUN_TYPE_DO;
  6385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6386. {
  6387. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  6388. {
  6389. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6390. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6391. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  6392. }
  6393. }
  6394. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6395. {
  6396. case Gun_Type_Chademo:
  6397. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  6398. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  6399. {
  6400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6401. {
  6402. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6403. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6404. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  6405. }
  6406. }
  6407. break;
  6408. case Gun_Type_CCS_2:
  6409. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  6410. for (int index = 0; index < CCS_QUANTITY; index++)
  6411. {
  6412. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6413. {
  6414. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6415. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6416. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  6417. }
  6418. }
  6419. break;
  6420. case Gun_Type_GB:
  6421. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  6422. for (int index = 0; index < GB_QUANTITY; index++)
  6423. {
  6424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6425. {
  6426. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6427. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6428. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  6429. }
  6430. }
  6431. break;
  6432. case Gun_Type_AC:
  6433. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  6434. for (int index = 0; index < AC_QUANTITY; index++)
  6435. {
  6436. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6437. {
  6438. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6439. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6440. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  6441. }
  6442. }
  6443. break;
  6444. default:
  6445. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  6446. break;
  6447. }
  6448. }
  6449. }
  6450. else
  6451. {
  6452. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  6453. {
  6454. gunTotalNumber += 1;
  6455. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6456. {
  6457. case Gun_Type_Chademo:
  6458. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  6459. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  6460. break;
  6461. case Gun_Type_CCS_2:
  6462. gunType[gun_index] = GUN_TYPE_CCS;
  6463. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  6464. break;
  6465. case Gun_Type_GB:
  6466. gunType[gun_index] = GUN_TYPE_GBT;
  6467. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  6468. break;
  6469. case Gun_Type_AC:
  6470. gunType[gun_index] = GUN_TYPE_AC;
  6471. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  6472. break;
  6473. default:
  6474. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  6475. break;
  6476. }
  6477. }
  6478. }
  6479. }
  6480. else
  6481. {
  6482. DEBUG_ERROR("Model name parsing fail.\n");
  6483. result = FAIL;
  6484. }
  6485. if(result != PASS)sleep(5);
  6486. return result;
  6487. }
  6488. //---------------------common routine---------------------------//
  6489. void checkNetworkProfile(void)
  6490. {
  6491. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  6492. json_object *priority;
  6493. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  6494. if(!is_error(priority))
  6495. {
  6496. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  6497. {
  6498. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  6499. {
  6500. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  6501. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  6502. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  6503. {
  6504. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  6505. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  6506. break;
  6507. }
  6508. }
  6509. }
  6510. }
  6511. json_object_put(priority);
  6512. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  6513. }
  6514. void checkRemoteStart(uint8_t evseIdx)
  6515. {
  6516. uint8_t tempIndex;
  6517. int isAllowStart = TRUE;
  6518. char cmdBuf[512];
  6519. //check Transaction active
  6520. if(gunType[evseIdx-1] == GUN_TYPE_CHAdeMO)
  6521. {
  6522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6523. {
  6524. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6525. }
  6526. else
  6527. {
  6528. tempIndex = (evseIdx-1);
  6529. }
  6530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6531. {
  6532. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6533. {
  6534. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6535. {
  6536. //Reserved
  6537. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  6538. }
  6539. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6540. {
  6541. //Reserved
  6542. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  6543. isAllowStart = FALSE;
  6544. }
  6545. else
  6546. {
  6547. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6548. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6549. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6550. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6551. {
  6552. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  6553. isAllowStart = FALSE;
  6554. }
  6555. }//END FOR ELSE
  6556. }
  6557. }// END FOR CHAdeMO_QUANTITY
  6558. }
  6559. else if(gunType[evseIdx-1] == GUN_TYPE_CCS)
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6562. {
  6563. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6564. }
  6565. else
  6566. {
  6567. tempIndex = (evseIdx-1);
  6568. }
  6569. for (int index = 0; index < CCS_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6572. {
  6573. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6574. {
  6575. //Reserved
  6576. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  6577. }
  6578. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6579. {
  6580. //Reserved
  6581. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  6582. isAllowStart = FALSE;
  6583. }
  6584. else
  6585. {
  6586. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6587. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6588. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6589. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6590. {
  6591. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  6592. isAllowStart = FALSE;
  6593. }
  6594. }// END FOR ELSE
  6595. }
  6596. }// END FOR CCS_QUANTITY
  6597. }
  6598. else if(gunType[evseIdx-1] == GUN_TYPE_GBT)
  6599. {
  6600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6601. {
  6602. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6603. }
  6604. else
  6605. {
  6606. tempIndex = (evseIdx-1);
  6607. }
  6608. for (int index = 0; index < GB_QUANTITY; index++)
  6609. {
  6610. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6611. {
  6612. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6613. {
  6614. //Reserved
  6615. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6616. }
  6617. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6618. {
  6619. //Reserved
  6620. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6621. isAllowStart = FALSE;
  6622. }
  6623. else
  6624. {
  6625. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6626. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6627. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6628. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6629. {
  6630. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6631. isAllowStart = FALSE;
  6632. }
  6633. }// END FOR ELSE
  6634. }
  6635. } // END FOR GB_QUANTITY
  6636. }
  6637. else if(gunType[evseIdx-1] == GUN_TYPE_DO)
  6638. {
  6639. tempIndex = (evseIdx-1);
  6640. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6641. {
  6642. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6643. {
  6644. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6645. {
  6646. //Reserved
  6647. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6648. }
  6649. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6650. {
  6651. //Reserved
  6652. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6653. isAllowStart = FALSE;
  6654. }
  6655. else
  6656. {
  6657. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6658. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6659. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6660. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6661. {
  6662. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6663. isAllowStart = FALSE;
  6664. }
  6665. }// END FOR ELSE
  6666. }
  6667. } // END FOR GB_QUANTITY
  6668. }
  6669. else
  6670. {
  6671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6672. {
  6673. tempIndex = 2;
  6674. }
  6675. else
  6676. {
  6677. tempIndex = (evseIdx-1);
  6678. }
  6679. for (int index = 0; index < AC_QUANTITY; index++)
  6680. {
  6681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6682. {
  6683. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6684. {
  6685. //Reserved
  6686. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6687. }
  6688. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6689. {
  6690. //Reserved
  6691. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6692. isAllowStart = FALSE;
  6693. }
  6694. else
  6695. {
  6696. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6697. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6698. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6699. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6700. {
  6701. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6702. isAllowStart = FALSE;
  6703. }
  6704. }//END FOR ELSE
  6705. }
  6706. }// END FOR AC_QUANTITY
  6707. }
  6708. if(isAllowStart == TRUE)
  6709. {
  6710. if(ShmOCPP20Data->RequestStartTransaction[evseIdx -1].chargingProfile.id > 0)
  6711. {
  6712. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6713. {
  6714. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdx);
  6715. system(cmdBuf);
  6716. }
  6717. }
  6718. ShmOCPP20Data->CsMsg.bits[evseIdx-1].RequestStartTransactionReq = ON;
  6719. }
  6720. }
  6721. void CheckSystemValue(void)
  6722. {
  6723. char filenmae[100]={0};
  6724. char str[100]={0};
  6725. int tempIndex = 0;
  6726. //===============================
  6727. // EVSE operation check
  6728. //===============================
  6729. //===============================
  6730. // Heartbeat check
  6731. //===============================
  6732. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6733. {
  6734. //parameter for test
  6735. sendHeartbeatRequest(0);
  6736. //==============================================
  6737. // Reset Waiting Time
  6738. //==============================================
  6739. HeartBeatWithNOResponse += 1;
  6740. }
  6741. //===============================
  6742. // CSU Trigger Authorize Request
  6743. //===============================
  6744. if(isWebsocketSendable &&
  6745. (server_sign == TRUE) &&
  6746. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6747. (authorizeRetryTimes < 3))
  6748. {
  6749. sendAuthorizeRequest(0);
  6750. authorizeRetryTimes = authorizeRetryTimes + 1;
  6751. if(authorizeRetryTimes < 3)
  6752. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6753. }
  6754. else if((server_sign == TRUE) &&
  6755. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6756. (authorizeRetryTimes >= 3))
  6757. {
  6758. authorizeRetryTimes = 0;
  6759. SetOcppConnStatus(FALSE);
  6760. server_sign = FALSE;
  6761. }
  6762. else if((server_sign == FALSE) &&
  6763. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6764. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6765. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6766. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6767. {
  6768. sendAuthorizeRequest(0);
  6769. }
  6770. //===============================
  6771. // NotifyMonitoringReportRequest
  6772. //===============================
  6773. if(isWebsocketSendable &&
  6774. (server_sign == TRUE) &&
  6775. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6776. {
  6777. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6778. {
  6779. if((strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0) ||
  6780. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0) ||
  6781. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0))
  6782. {
  6783. /*for(uint8_t idxVarMonitoring=0; idxVarMonitoring<10; idxVarMonitoring++)
  6784. {
  6785. if(strcmp((char*)ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].variableMonitoring[idxVarMonitoring].type, (char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion]))
  6786. {
  6787. strcpy(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxVarMonitoring].component, ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].
  6788. }
  6789. }*/
  6790. }
  6791. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6792. {
  6793. /*
  6794. * TODO:
  6795. * 1. Report component that are ThresholdMonitoring
  6796. */
  6797. }
  6798. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6799. {
  6800. /*
  6801. * TODO:
  6802. * 1. Report component that are DeltaMonitoring
  6803. */
  6804. }
  6805. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6806. {
  6807. /*
  6808. * TODO:
  6809. * 1. Report component that are PeriodicMonitoring
  6810. */
  6811. }
  6812. else
  6813. {
  6814. /*
  6815. * TODO:
  6816. * 1. Process unknown criteria condition
  6817. */
  6818. }
  6819. }
  6820. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6821. }
  6822. if(isWebsocketSendable &&
  6823. (server_sign == TRUE) &&
  6824. (ShmOCPP20Data->GetReport.requestId > 0))
  6825. {
  6826. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6827. {
  6828. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6829. {
  6830. /*
  6831. * TODO:
  6832. * 1. Report component that are active
  6833. */
  6834. }
  6835. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6836. {
  6837. /*
  6838. * TODO:
  6839. * 1. Report component that are available
  6840. */
  6841. }
  6842. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6843. {
  6844. /*
  6845. * TODO:
  6846. * 1. Report component that are enable
  6847. */
  6848. }
  6849. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6850. {
  6851. /*
  6852. * TODO:
  6853. * 1. Report component that are problem
  6854. */
  6855. }
  6856. else
  6857. {
  6858. /*
  6859. * TODO:
  6860. * 1. Process unknown criteria condition
  6861. */
  6862. }
  6863. }
  6864. ShmOCPP20Data->GetReport.requestId = 0;
  6865. }
  6866. if(isWebsocketSendable &&
  6867. (server_sign == TRUE) &&
  6868. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6869. {
  6870. uint8_t reportIdx = 0;
  6871. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6872. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6873. {
  6874. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6875. {
  6876. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6877. {
  6878. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]) == 0) || (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]) == 0))
  6879. {
  6880. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6881. reportIdx++;
  6882. }
  6883. }
  6884. else
  6885. {
  6886. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6887. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6888. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6889. else
  6890. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6891. sendNotifyReportRequest();
  6892. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6893. reportIdx = 0;
  6894. idx_var--;
  6895. }
  6896. }
  6897. }
  6898. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6899. {
  6900. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6901. {
  6902. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6903. {
  6904. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6905. reportIdx++;
  6906. }
  6907. else
  6908. {
  6909. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6910. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6911. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6912. else
  6913. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6914. sendNotifyReportRequest();
  6915. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6916. reportIdx = 0;
  6917. idx_var--;
  6918. }
  6919. }
  6920. }
  6921. else
  6922. {
  6923. /*
  6924. * TODO:
  6925. * 1. Fill out summary inventory to response message, currently not support
  6926. */
  6927. }
  6928. if(reportIdx > 0)
  6929. {
  6930. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6931. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6932. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6933. else
  6934. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6935. sendNotifyReportRequest();
  6936. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6937. reportIdx = 0;
  6938. }
  6939. ShmOCPP20Data->GetBaseReport.requestId = 0;
  6940. }
  6941. if(isWebsocketSendable &&
  6942. (server_sign == TRUE) &&
  6943. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  6944. {
  6945. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  6946. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  6947. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  6948. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  6949. else
  6950. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  6951. sendNotifyEventRequest();
  6952. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  6953. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  6954. }
  6955. if(isWebsocketSendable &&
  6956. (server_sign == TRUE) &&
  6957. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  6958. {
  6959. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  6960. {
  6961. /*
  6962. * TODO:
  6963. * 1.
  6964. */
  6965. }
  6966. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  6967. {
  6968. /*
  6969. * TODO:
  6970. * 1.
  6971. */
  6972. }
  6973. else
  6974. {
  6975. /*
  6976. * TODO:
  6977. * 1.
  6978. */
  6979. }
  6980. sendGet15118EVCertificateRequest();
  6981. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  6982. }
  6983. if(isWebsocketSendable &&
  6984. (server_sign == TRUE) &&
  6985. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  6986. {
  6987. sendSecurityEventNotificationRequest();
  6988. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  6989. }
  6990. if(isWebsocketSendable &&
  6991. (server_sign == TRUE) &&
  6992. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  6993. {
  6994. sendNotifyCustomerInformationRequest();
  6995. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  6996. }
  6997. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6998. {
  6999. // ClockAlign MeterValue
  7000. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value)))==0):FALSE))
  7001. {
  7002. //check Transaction active
  7003. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7006. {
  7007. tempIndex = ((gun_index==2) ? 1: 0);
  7008. }
  7009. else
  7010. {
  7011. tempIndex = gun_index;
  7012. }
  7013. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7014. {
  7015. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7016. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7017. {
  7018. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7019. }
  7020. }// End for CHAdeMO
  7021. }
  7022. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7023. {
  7024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7025. {
  7026. tempIndex = ((gun_index==2) ? 1: 0);
  7027. }
  7028. else
  7029. {
  7030. tempIndex = gun_index;
  7031. }
  7032. for (int index = 0; index < CCS_QUANTITY; index++)
  7033. {
  7034. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7035. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7036. {
  7037. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7038. }
  7039. } // End for CCS
  7040. }
  7041. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7042. {
  7043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7044. {
  7045. tempIndex = ((gun_index==2) ? 1: 0);
  7046. }
  7047. else
  7048. {
  7049. tempIndex = gun_index;
  7050. }
  7051. for (int index = 0; index < GB_QUANTITY; index++)
  7052. {
  7053. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7054. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7055. {
  7056. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7057. }
  7058. }// End for GB
  7059. }
  7060. else if(gunType[gun_index] == GUN_TYPE_DO)
  7061. {
  7062. tempIndex = gun_index;
  7063. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7064. {
  7065. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7066. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7067. {
  7068. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7069. }
  7070. }
  7071. }
  7072. else
  7073. {
  7074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7075. {
  7076. tempIndex = 2;
  7077. }
  7078. else
  7079. {
  7080. tempIndex = gun_index;
  7081. }
  7082. for (int index = 0; index < AC_QUANTITY; index++)
  7083. {
  7084. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7085. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7086. {
  7087. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7088. }
  7089. }//End for AC
  7090. }
  7091. }
  7092. }
  7093. //===============================
  7094. // Each connector operation check
  7095. //===============================
  7096. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  7097. {
  7098. //==========================================
  7099. // Check remote start without connector id
  7100. //==========================================
  7101. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  7102. {
  7103. int evseIdInt = -1;
  7104. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  7105. {
  7106. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  7107. {
  7108. evseIdInt = (gun_index+1);
  7109. DEBUG_INFO("Detect connector of evse-%02d connected ready to start.\n", evseIdInt);
  7110. checkRemoteStart(evseIdInt);
  7111. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7112. break;
  7113. }
  7114. }
  7115. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  7116. {
  7117. DEBUG_WARN("Remote start request without evse id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  7118. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7119. }
  7120. }
  7121. //==========================================
  7122. // csu trigger DataTransferReq
  7123. //==========================================
  7124. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  7125. {
  7126. sendDataTransferRequest(gun_index);
  7127. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  7128. }
  7129. //==============================================
  7130. // Charger status notification & Transaction event report
  7131. //==============================================
  7132. //--- Check Mode Change ---//
  7133. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7134. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7135. {
  7136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7137. {
  7138. tempIndex = ((gun_index==2) ? 1: 0);
  7139. }
  7140. else
  7141. {
  7142. tempIndex = gun_index;
  7143. }
  7144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7145. {
  7146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7147. {
  7148. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  7149. {
  7150. //if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7151. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7152. /*if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7153. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7154. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7155. {
  7156. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7157. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7158. else
  7159. {
  7160. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7161. {
  7162. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7163. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7164. }
  7165. }
  7166. }*/
  7167. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  7168. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  7169. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7170. {
  7171. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7172. if((access(filenmae,F_OK))!=-1)
  7173. {
  7174. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7175. sprintf(str,"rm -f %s",filenmae);
  7176. system(str);
  7177. }
  7178. }
  7179. }
  7180. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7181. #if 1 // for TempStopTransaction
  7182. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7183. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7184. {
  7185. checkTempStopTransaction(gun_index);
  7186. }
  7187. #endif
  7188. }
  7189. }
  7190. }
  7191. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7192. {
  7193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7194. {
  7195. tempIndex = ((gun_index==2) ? 1: 0);
  7196. }
  7197. else
  7198. {
  7199. tempIndex = gun_index;
  7200. }
  7201. for (int index = 0; index < CCS_QUANTITY; index++)
  7202. {
  7203. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7204. {
  7205. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  7206. {
  7207. //if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7208. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7209. /*if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7210. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7211. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7212. {
  7213. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7214. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7215. else
  7216. {
  7217. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7218. {
  7219. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7220. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7221. }
  7222. }
  7223. }*/
  7224. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  7225. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  7226. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7227. {
  7228. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7229. if((access(filenmae,F_OK))!=-1)
  7230. {
  7231. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7232. sprintf(str,"rm -f %s",filenmae);
  7233. system(str);
  7234. }
  7235. }
  7236. }
  7237. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7238. #if 1 // for TempStopTransaction
  7239. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7240. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7241. {
  7242. checkTempStopTransaction(gun_index);
  7243. }
  7244. #endif
  7245. }
  7246. }
  7247. }
  7248. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7251. {
  7252. tempIndex = ((gun_index==2) ? 1: 0);
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < GB_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7261. {
  7262. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  7263. {
  7264. //if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7265. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7266. /*if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7267. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7268. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]))
  7269. {
  7270. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7271. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7272. else
  7273. {
  7274. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7275. {
  7276. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7277. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7278. }
  7279. }
  7280. }*/
  7281. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  7282. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  7283. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7284. {
  7285. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7286. if((access(filenmae,F_OK))!=-1)
  7287. {
  7288. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7289. sprintf(str,"rm -f %s",filenmae);
  7290. system(str);
  7291. }
  7292. }
  7293. }
  7294. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7295. #if 1 // for TempStopTransaction
  7296. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7297. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7298. {
  7299. checkTempStopTransaction(gun_index);
  7300. }
  7301. #endif
  7302. }
  7303. }
  7304. }
  7305. else if(gunType[gun_index] == GUN_TYPE_DO)
  7306. {
  7307. tempIndex = gun_index;
  7308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7309. {
  7310. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7311. {
  7312. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  7313. {
  7314. //if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_AUTHORIZING)
  7315. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7316. /*if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  7317. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  7318. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]))
  7319. {
  7320. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  7321. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7322. else
  7323. {
  7324. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7325. {
  7326. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7327. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7328. }
  7329. }
  7330. }*/
  7331. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  7332. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  7333. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  7334. {
  7335. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7336. if((access(filenmae,F_OK))!=-1)
  7337. {
  7338. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7339. sprintf(str,"rm -f %s",filenmae);
  7340. system(str);
  7341. }
  7342. }
  7343. }
  7344. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7345. #if 1 // for TempStopTransaction
  7346. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  7347. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7348. {
  7349. checkTempStopTransaction(gun_index);
  7350. }
  7351. #endif
  7352. }
  7353. }
  7354. }
  7355. else
  7356. {
  7357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7358. {
  7359. tempIndex = 2;
  7360. }
  7361. else
  7362. {
  7363. tempIndex = gun_index;
  7364. }
  7365. for (int index = 0; index < AC_QUANTITY; index++)
  7366. {
  7367. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7368. {
  7369. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  7370. {
  7371. //if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7372. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7373. /*if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7374. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7375. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) && (AcPreviousSystemStatus[index] != 99))
  7376. {
  7377. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7378. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7379. else
  7380. {
  7381. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7382. {
  7383. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7384. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7385. }
  7386. }
  7387. }*/
  7388. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  7389. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  7390. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7391. {
  7392. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7393. if((access(filenmae,F_OK))!=-1)
  7394. {
  7395. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7396. sprintf(str,"rm -f %s",filenmae);
  7397. system(str);
  7398. }
  7399. }
  7400. }
  7401. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7402. #if 1 // for TempStopTransaction
  7403. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7404. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7405. {
  7406. checkTempStopTransaction(gun_index);
  7407. }
  7408. #endif
  7409. }
  7410. }// END
  7411. }
  7412. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  7413. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  7414. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  7415. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  7416. {
  7417. sendStatusNotificationRequest(gun_index);
  7418. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  7419. }
  7420. //==============================================
  7421. // CSU Trigger or timer timeout refresh Smart Charging Profile
  7422. //==============================================
  7423. if((ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON) ||
  7424. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value))))
  7425. {
  7426. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  7427. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  7428. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  7429. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  7430. }
  7431. //==============================================
  7432. // CSU transaction event
  7433. //==============================================
  7434. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  7435. {
  7436. sendTransactionEventRequest(gun_index);
  7437. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  7438. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  7439. //storeTempStopTransaction(gun_index);
  7440. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  7441. }
  7442. //==============================================
  7443. // Meter report
  7444. //==============================================
  7445. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  7446. {
  7447. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger, FALSE);
  7448. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  7449. }
  7450. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  7451. {
  7452. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock, FALSE);
  7453. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  7454. }
  7455. // Sample period MeterValue
  7456. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0) &&
  7457. (getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>3)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):3)))
  7458. {
  7459. //check Transaction active
  7460. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7461. {
  7462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7463. {
  7464. tempIndex = ((gun_index==2) ? 1: 0);
  7465. }
  7466. else
  7467. {
  7468. tempIndex = gun_index;
  7469. }
  7470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7471. {
  7472. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7473. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7474. {
  7475. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7476. {
  7477. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7478. }
  7479. }
  7480. }// End for CHAdeMO
  7481. }
  7482. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7483. {
  7484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7485. {
  7486. tempIndex = ((gun_index==2) ? 1: 0);
  7487. }
  7488. else
  7489. {
  7490. tempIndex = gun_index;
  7491. }
  7492. for (int index = 0; index < CCS_QUANTITY; index++)
  7493. {
  7494. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7495. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7496. {
  7497. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7498. {
  7499. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7500. }
  7501. }
  7502. } // End for CCS
  7503. }
  7504. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7505. {
  7506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7507. {
  7508. tempIndex = ((gun_index==2) ? 1: 0);
  7509. }
  7510. else
  7511. {
  7512. tempIndex = gun_index;
  7513. }
  7514. for (int index = 0; index < GB_QUANTITY; index++)
  7515. {
  7516. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7517. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7518. {
  7519. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7520. {
  7521. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7522. }
  7523. }
  7524. }// End for GB
  7525. }
  7526. else if(gunType[gun_index] == GUN_TYPE_DO)
  7527. {
  7528. tempIndex = gun_index;
  7529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7530. {
  7531. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7532. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7533. {
  7534. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7535. {
  7536. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7537. }
  7538. }
  7539. }
  7540. }
  7541. else
  7542. {
  7543. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7544. {
  7545. tempIndex = 2;
  7546. }
  7547. else
  7548. {
  7549. tempIndex = gun_index;
  7550. }
  7551. for (int index = 0; index < AC_QUANTITY; index++)
  7552. {
  7553. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7554. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7555. {
  7556. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7557. {
  7558. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7559. }
  7560. }
  7561. }//End for AC
  7562. }
  7563. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7564. {
  7565. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7566. {
  7567. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, FALSE);
  7568. }
  7569. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7570. }
  7571. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  7572. }
  7573. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value) > 0) &&
  7574. (getDiffSecNow(clientTime.SampledDataTxEnded[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value)>3)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value)- 1):3)))
  7575. {
  7576. //check Transaction active
  7577. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7578. {
  7579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7580. {
  7581. tempIndex = ((gun_index==2) ? 1: 0);
  7582. }
  7583. else
  7584. {
  7585. tempIndex = gun_index;
  7586. }
  7587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7588. {
  7589. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7590. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7591. {
  7592. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7593. {
  7594. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7595. }
  7596. }
  7597. }// End for CHAdeMO
  7598. }
  7599. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7600. {
  7601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7602. {
  7603. tempIndex = ((gun_index==2) ? 1: 0);
  7604. }
  7605. else
  7606. {
  7607. tempIndex = gun_index;
  7608. }
  7609. for (int index = 0; index < CCS_QUANTITY; index++)
  7610. {
  7611. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7612. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7613. {
  7614. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7615. {
  7616. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7617. }
  7618. }
  7619. } // End for CCS
  7620. }
  7621. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7622. {
  7623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7624. {
  7625. tempIndex = ((gun_index==2) ? 1: 0);
  7626. }
  7627. else
  7628. {
  7629. tempIndex = gun_index;
  7630. }
  7631. for (int index = 0; index < GB_QUANTITY; index++)
  7632. {
  7633. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7634. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7635. {
  7636. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7637. {
  7638. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7639. }
  7640. }
  7641. }// End for GB
  7642. }
  7643. else if(gunType[gun_index] == GUN_TYPE_DO)
  7644. {
  7645. tempIndex = gun_index;
  7646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7647. {
  7648. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7649. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7650. {
  7651. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7652. {
  7653. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7654. }
  7655. }
  7656. }
  7657. }
  7658. else
  7659. {
  7660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7661. {
  7662. tempIndex = 2;
  7663. }
  7664. else
  7665. {
  7666. tempIndex = gun_index;
  7667. }
  7668. for (int index = 0; index < AC_QUANTITY; index++)
  7669. {
  7670. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7671. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7672. {
  7673. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7674. {
  7675. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7676. }
  7677. }
  7678. }//End for AC
  7679. }
  7680. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7681. {
  7682. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7683. {
  7684. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, TRUE);
  7685. }
  7686. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7687. }
  7688. refreshStartTimer(&clientTime.SampledDataTxEnded[gun_index]);
  7689. }
  7690. //==============================================
  7691. // Check Connector reserved
  7692. //==============================================
  7693. //===============================
  7694. // Check if Reserve is expired
  7695. //===============================
  7696. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  7697. {
  7698. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  7699. {
  7700. DEBUG_INFO("reserve expired.\n");
  7701. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  7702. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  7703. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  7704. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  7705. }
  7706. }//END OF Check if Reserve is expired
  7707. //==========================================
  7708. // csu trigger FirmwareStatusNotificationReq
  7709. //==========================================
  7710. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  7711. {
  7712. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  7713. }
  7714. //==========================================
  7715. // csu cleared charging limit request
  7716. //==========================================
  7717. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  7718. {
  7719. sendClearedChargingLimitRequest(gun_index);
  7720. }
  7721. //==========================================
  7722. // csu trigger CancelReservationConf
  7723. //==========================================
  7724. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  7725. {
  7726. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  7727. }
  7728. //==========================================
  7729. // csu notify EV charging need request
  7730. //==========================================
  7731. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  7732. {
  7733. sendNotifyEVChargingNeedsRequest(gun_index);
  7734. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  7735. }
  7736. //==========================================
  7737. // csu notify EV charging schedule request
  7738. //==========================================
  7739. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  7740. {
  7741. sendNotifyEVChargingScheduleRequest(gun_index);
  7742. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  7743. }
  7744. //==========================================
  7745. // csu trigger ChangeAvailabilityConf
  7746. //==========================================
  7747. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  7748. {
  7749. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  7750. }
  7751. //==========================================
  7752. // csu trigger UnlockConnectorConf
  7753. //==========================================
  7754. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  7755. {
  7756. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  7757. }
  7758. //==========================================
  7759. // csu trigger ReserveNowConf
  7760. //==========================================
  7761. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  7762. {
  7763. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  7764. }
  7765. //==========================================
  7766. // csu trigger ReserveNowConf
  7767. //==========================================
  7768. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  7769. {
  7770. sendReservationStatusUpdateRequest(gun_index);
  7771. }
  7772. //==========================================
  7773. // csu trigger LogStatusNotificationReq
  7774. //==========================================
  7775. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  7776. {
  7777. if(isCancelUploadLog == TRUE)
  7778. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7779. else
  7780. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  7781. }
  7782. //==========================================
  7783. // csu trigger SignCertificateReq
  7784. //==========================================
  7785. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7786. {
  7787. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7788. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7789. {
  7790. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7791. }
  7792. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7793. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7794. {
  7795. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7796. }
  7797. }
  7798. }
  7799. }
  7800. //==========================================
  7801. // send request routine
  7802. //==========================================
  7803. int sendAuthorizeRequest(int gun_index)
  7804. {
  7805. mtrace();
  7806. int result = FAIL;
  7807. char message[4096]={0};
  7808. char guid[37];
  7809. char tempdata[128]={0};
  7810. json_object *Authorize = json_object_new_object();
  7811. json_object *idToken = json_object_new_object();
  7812. DEBUG_INFO("sendAuthorizeRequest...\n");
  7813. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7814. //Local Authorize
  7815. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7816. {
  7817. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7818. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7819. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7820. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7821. result = PASS;
  7822. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7823. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7824. authorizeRetryTimes = 0;
  7825. return result;
  7826. }
  7827. else if(((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0) && (ShmOCPP20Data->OcppConnStatus == 0)) ||
  7828. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7829. {
  7830. // Query idtag from cache
  7831. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7832. // Query idtag from list
  7833. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7834. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7835. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7836. {
  7837. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7838. {
  7839. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7840. }
  7841. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7842. {
  7843. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7844. }
  7845. // Return authorize result if does not connect to server
  7846. if(!ShmOCPP20Data->OcppConnStatus)
  7847. {
  7848. DEBUG_INFO("Local Authorization Fail.\n");
  7849. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7850. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7851. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7852. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7853. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7854. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7855. authorizeRetryTimes = 0;
  7856. return result;
  7857. }
  7858. }
  7859. else
  7860. {
  7861. DEBUG_INFO("Local Authorization get result.\n");
  7862. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7863. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7864. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7865. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7866. else
  7867. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7868. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7869. result = PASS;
  7870. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7871. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7872. authorizeRetryTimes = 0;
  7873. return result;
  7874. }
  7875. }
  7876. //get data from shared memory
  7877. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7878. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  7879. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  7880. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  7881. {
  7882. memset(&ShmOCPP20Data->Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  7883. int parseCertResult = FAIL;
  7884. json_object *iso15118CertificateHashData = json_object_new_array();
  7885. // Read CERTIFICATE_PnCAuth file content
  7886. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  7887. {
  7888. memset(ShmOCPP20Data->Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.certificate));
  7889. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  7890. char *line = NULL;
  7891. size_t len = 0;
  7892. while(getline(&line, &len, fp) != -1)
  7893. {
  7894. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  7895. strcat((char *)ShmOCPP20Data->Authorize.certificate, line);
  7896. }
  7897. fclose(fp);
  7898. }
  7899. if(strlen((char*)ShmOCPP20Data->Authorize.certificate) > 0)
  7900. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  7901. char parseData[512] = {0};
  7902. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  7903. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  7904. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  7905. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  7906. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  7907. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  7908. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  7909. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  7910. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  7911. strcpy((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  7912. for(int idx=0; idx < 4; idx++)
  7913. {
  7914. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  7915. {
  7916. json_object *OCSPRequestDataType = json_object_new_object();
  7917. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  7918. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  7919. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  7920. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  7921. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  7922. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  7923. parseCertResult = PASS;
  7924. }
  7925. }
  7926. if(parseCertResult == PASS)
  7927. {
  7928. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  7929. }
  7930. else
  7931. {
  7932. sprintf((char*)ShmOCPP20Data->Authorize.Response_certificateStatus, "NoCertificateAvailable");
  7933. sprintf((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Invalid");
  7934. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON;
  7935. }
  7936. }
  7937. json_object_object_add(Authorize, "idToken", idToken);
  7938. random_uuid(guid);
  7939. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  7940. json_object_put(Authorize);
  7941. LWS_Send(message);
  7942. sprintf(tempdata, "Authorize,%d", gun_index);
  7943. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7944. {
  7945. result = PASS;
  7946. }
  7947. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7948. return result;
  7949. }
  7950. int sendBootNotificationRequest()
  7951. {
  7952. mtrace();
  7953. int result = FAIL;
  7954. char message[4096]={0};
  7955. char guid[37]={0};
  7956. char tempdata[128]={0};
  7957. json_object *BootNotification = json_object_new_object();
  7958. json_object *chargingStation = json_object_new_object();
  7959. json_object *modem = json_object_new_object();
  7960. DEBUG_INFO("sendBootNotificationRequest...\n");
  7961. // Fill BootNotification fields
  7962. DB_getBooType();
  7963. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  7964. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7965. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7966. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  7967. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  7968. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  7969. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  7970. {
  7971. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  7972. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  7973. json_object_object_add(chargingStation, "modem", modem);
  7974. }
  7975. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  7976. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  7977. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  7978. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  7979. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  7980. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  7981. random_uuid(guid);
  7982. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  7983. json_object_put(BootNotification);
  7984. LWS_Send(message);
  7985. sprintf(tempdata, "BootNotification,0");
  7986. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7987. {
  7988. result = PASS;
  7989. }
  7990. return result;
  7991. }
  7992. int sendClearedChargingLimitRequest(int gun_index)
  7993. {
  7994. mtrace();
  7995. int result = FAIL;
  7996. char message[4096]={0};
  7997. char guid[37]={0};
  7998. char tempdata[128]={0};
  7999. json_object *ClearedChargingLimit = json_object_new_object();
  8000. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  8001. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  8002. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  8003. random_uuid(guid);
  8004. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  8005. json_object_put(ClearedChargingLimit);
  8006. LWS_Send(message);
  8007. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  8008. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8009. {
  8010. result = PASS;
  8011. }
  8012. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  8013. return result;
  8014. }
  8015. int sendDataTransferRequest(int gun_index)
  8016. {
  8017. mtrace();
  8018. char message[1000]={0};
  8019. char guid[37]={0};
  8020. char tempdata[65]={0};
  8021. int result = FAIL;
  8022. DEBUG_INFO("sendDataTransferRequest...\n");
  8023. random_uuid(guid);
  8024. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  8025. MESSAGE_TYPE_CALL,
  8026. guid,
  8027. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  8028. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  8029. ShmOCPP20Data->DataTransfer[gun_index].data);
  8030. LWS_Send(message);
  8031. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  8032. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8033. {
  8034. result = PASS;
  8035. }
  8036. return result;
  8037. }
  8038. int sendFirmwareStatusNotificationRequest(char *status)
  8039. {
  8040. mtrace();
  8041. int result = FAIL;
  8042. char message[110]={0};
  8043. char guid[37]={0};
  8044. char tempdata[65]={0};
  8045. json_object *FirmwareStatusNotification = json_object_new_object();
  8046. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  8047. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  8048. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  8049. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  8050. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  8051. random_uuid(guid);
  8052. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8053. json_object_put(FirmwareStatusNotification);
  8054. LWS_SendNow(message);
  8055. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  8056. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8057. {
  8058. result = PASS;
  8059. }
  8060. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  8061. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  8062. //record status
  8063. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  8064. {
  8065. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  8066. }
  8067. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  8068. {
  8069. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  8070. }
  8071. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  8072. {
  8073. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  8074. }
  8075. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  8076. {
  8077. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  8078. }
  8079. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  8080. {
  8081. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  8082. }
  8083. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  8084. {
  8085. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  8086. }
  8087. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  8088. {
  8089. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  8090. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8091. }
  8092. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  8093. {
  8094. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  8095. }
  8096. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  8097. {
  8098. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  8099. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8100. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8101. }
  8102. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  8103. {
  8104. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  8105. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8106. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8107. }
  8108. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  8109. {
  8110. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  8111. }
  8112. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  8113. {
  8114. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  8115. }
  8116. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  8117. {
  8118. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  8119. }
  8120. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  8121. {
  8122. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  8123. }
  8124. return result;
  8125. }
  8126. int sendGet15118EVCertificateRequest()
  8127. {
  8128. mtrace();
  8129. int result = FAIL;
  8130. char message[4096]={0};
  8131. char guid[37]={0};
  8132. char tempdata[128]={0};
  8133. json_object *Get15118EVCertificate = json_object_new_object();
  8134. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  8135. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  8136. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  8137. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  8138. random_uuid(guid);
  8139. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  8140. json_object_put(Get15118EVCertificate);
  8141. LWS_Send(message);
  8142. sprintf(tempdata, "Get15118EVCertificate,0");
  8143. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8144. {
  8145. result = PASS;
  8146. }
  8147. return result;
  8148. }
  8149. int sendGetCertificateStatusRequest()
  8150. {
  8151. mtrace();
  8152. int result = FAIL;
  8153. char message[4096]={0};
  8154. char guid[37]={0};
  8155. char tempdata[128]={0};
  8156. json_object *GetCertificateStatus = json_object_new_object();
  8157. json_object *ocspRequestData = json_object_new_object();
  8158. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  8159. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  8160. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  8161. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  8162. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  8163. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  8164. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  8165. random_uuid(guid);
  8166. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  8167. json_object_put(GetCertificateStatus);
  8168. LWS_Send(message);
  8169. sprintf(tempdata, "GetCertificateStatus,0");
  8170. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8171. {
  8172. result = PASS;
  8173. }
  8174. return result;
  8175. }
  8176. int sendHeartbeatRequest()
  8177. {
  8178. mtrace();
  8179. int result = FAIL;
  8180. char message[40096]={0};
  8181. char guid[37]={0};
  8182. char tempdata[128]={0};
  8183. DEBUG_INFO("sendHeartbeatRequest...\n");
  8184. random_uuid(guid);
  8185. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  8186. , MESSAGE_TYPE_CALL
  8187. , guid );
  8188. LWS_Send(message);
  8189. sprintf(tempdata, "Heartbeat,%d", 0);
  8190. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8191. {
  8192. result = PASS;
  8193. }
  8194. return result;
  8195. }
  8196. int sendLogStatusNotificationRequest(char *status)
  8197. {
  8198. mtrace();
  8199. int result = FAIL;
  8200. char message[4096]={0};
  8201. char guid[37]={0};
  8202. char tempdata[128]={0};
  8203. json_object *LogStatusNotification = json_object_new_object();
  8204. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8205. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  8206. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  8207. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  8208. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  8209. random_uuid(guid);
  8210. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8211. json_object_put(LogStatusNotification);
  8212. LWS_SendNow(message);
  8213. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8214. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8215. {
  8216. result = PASS;
  8217. }
  8218. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  8219. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  8220. //record status
  8221. if(strcmp(status,"BadMessage")==0)
  8222. {
  8223. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  8224. }
  8225. else if(strcmp(status,"Idle")==0)
  8226. {
  8227. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  8228. }
  8229. else if(strcmp(status,"NotSupportedOperation")==0)
  8230. {
  8231. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  8232. }
  8233. else if(strcmp(status,"PermissionDenied")==0)
  8234. {
  8235. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  8236. }
  8237. else if(strcmp(status,"Uploaded")==0)
  8238. {
  8239. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  8240. }
  8241. else if(strcmp(status,"UploadFailure")==0)
  8242. {
  8243. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  8244. }
  8245. else if(strcmp(status,"Uploading")==0)
  8246. {
  8247. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  8248. }
  8249. return result;
  8250. }
  8251. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType, uint8_t isSampledDataTxEnd)
  8252. {
  8253. mtrace();
  8254. int result = FAIL;
  8255. char guid[37]={0};
  8256. char tempdata[65]={0};
  8257. int tempIndex = 0;
  8258. DEBUG_INFO("sendMeterValuesRequest...\n");
  8259. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  8260. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  8261. //set value
  8262. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  8263. //UTC Date time
  8264. struct timeval tmnow;
  8265. struct tm *tm;
  8266. char buf[28];//, usec_buf[6];
  8267. gettimeofday(&tmnow, NULL);
  8268. time_t t;
  8269. t = time(NULL);
  8270. /*UTC time and date*/
  8271. tm = gmtime(&t);
  8272. if(dataType == ReadingContextEnumType_Sample_Clock)
  8273. {
  8274. struct tm *tmTarget;
  8275. struct timeb tbTarget;
  8276. tbTarget.time = mktime(tm);
  8277. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  8278. tmTarget = gmtime(&tbTarget.time);
  8279. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  8280. }
  8281. else
  8282. {
  8283. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8284. }
  8285. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  8286. struct ChargingInfoData *targetChargingInfoData = getTargetChargingInfoData(gun_index);
  8287. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  8288. //idx_sample=0;
  8289. //********************************(1)Current.Import L1************************************************/
  8290. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8291. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8292. (dataType == ReadingContextEnumType_Trigger))
  8293. {
  8294. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8295. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrent*100))/100.0;
  8296. if(gunType[gun_index] == GUN_TYPE_AC)
  8297. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8298. else
  8299. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8300. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  8301. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8302. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8303. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  8304. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  8305. }
  8306. //idx_sample=1;
  8307. //********************************(2)Energy.Active.Import.Register ************************************************/
  8308. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8309. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8310. (dataType == ReadingContextEnumType_Trigger))
  8311. {
  8312. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8313. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(targetChargingInfoData->PowerConsumption*100))/100.0;
  8314. if(gunType[gun_index] == GUN_TYPE_AC)
  8315. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8316. else
  8317. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8318. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  8319. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  8320. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8321. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  8322. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8323. }
  8324. //idx_sample=2;
  8325. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  8326. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8327. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8328. (dataType == ReadingContextEnumType_Trigger))
  8329. {
  8330. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8331. if(dataType == ReadingContextEnumType_Sample_Clock)
  8332. {
  8333. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousClockPowerConsumption[gun_index]);
  8334. periousClockPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8335. }
  8336. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  8337. {
  8338. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  8339. periousPeriodicPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8340. }
  8341. else
  8342. {
  8343. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  8344. }
  8345. if(gunType[gun_index] == GUN_TYPE_AC)
  8346. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8347. else
  8348. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8349. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  8350. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  8351. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8352. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  8353. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8354. }
  8355. //idx_sample=3;
  8356. //********************************(4)Power.Active.Import************************************************/
  8357. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8358. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8359. (dataType == ReadingContextEnumType_Trigger))
  8360. {
  8361. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8362. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(targetChargingInfoData->PresentChargingPower*100))/100.0;
  8363. if(gunType[gun_index] == GUN_TYPE_AC)
  8364. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8365. else
  8366. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8367. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  8368. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  8369. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8370. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  8371. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  8372. }
  8373. //idx_sample=4;
  8374. //***********************************************(5)VOLTAGE L1******************************************************/
  8375. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8376. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8377. (dataType == ReadingContextEnumType_Trigger))
  8378. {
  8379. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8380. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltage*100))/100.0;
  8381. if(gunType[gun_index] == GUN_TYPE_AC)
  8382. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8383. else
  8384. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8385. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8386. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8387. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8388. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8389. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8390. }
  8391. //***********************************************(6)SOC******************************************************/
  8392. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8393. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8394. (dataType == ReadingContextEnumType_Trigger))
  8395. {
  8396. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  8397. {
  8398. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = targetChargingInfoData->EvBatterySoc;
  8399. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8400. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8401. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8402. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8403. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8404. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8405. }
  8406. }
  8407. //********************************(7)Current.Import L2************************************************/
  8408. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8409. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8410. (dataType == ReadingContextEnumType_Trigger))
  8411. {
  8412. // Only for AC 3 phase
  8413. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8414. {
  8415. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL2*100))/100.0;
  8416. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8417. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8418. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8419. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8420. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8421. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8422. }
  8423. }
  8424. //********************************(8)Current.Import L3************************************************/
  8425. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8426. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8427. (dataType == ReadingContextEnumType_Trigger))
  8428. {
  8429. // Only for AC 3 phase
  8430. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8431. {
  8432. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL3*100))/100.0;
  8433. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8434. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8435. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8436. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8437. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8438. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8439. }
  8440. }
  8441. //***********************************************(9)VOLTAGE L2******************************************************/
  8442. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8443. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8444. (dataType == ReadingContextEnumType_Trigger))
  8445. {
  8446. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8447. {
  8448. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL2*100))/100.0;
  8449. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8450. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8451. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8452. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8453. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8454. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8455. }
  8456. }
  8457. //***********************************************(10)VOLTAGE L3******************************************************/
  8458. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8459. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8460. (dataType == ReadingContextEnumType_Trigger))
  8461. {
  8462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8463. {
  8464. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL3*100))/100.0;
  8465. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8466. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8467. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8468. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8469. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8470. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8471. }
  8472. }
  8473. //***********************************************(11)Current.Offered******************************************************/
  8474. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8475. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8476. (dataType == ReadingContextEnumType_Trigger))
  8477. {
  8478. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8479. if(gunType[gun_index] == GUN_TYPE_AC)
  8480. {
  8481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8482. {
  8483. tempIndex = 2;
  8484. }
  8485. else
  8486. {
  8487. tempIndex = gun_index;
  8488. }
  8489. for (int index = 0; index < AC_QUANTITY; index++)
  8490. {
  8491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8492. {
  8493. uint16_t currentOffer;
  8494. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8495. {
  8496. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8497. }
  8498. else
  8499. {
  8500. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8501. }
  8502. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8503. }
  8504. }
  8505. }
  8506. else
  8507. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t)(targetChargingInfoData->AvailableChargingCurrent/10);
  8508. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8509. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8510. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8511. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8512. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8513. }
  8514. //***********************************************(12)Power.Offered******************************************************/
  8515. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8516. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8517. (dataType == ReadingContextEnumType_Trigger))
  8518. {
  8519. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8520. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t)(targetChargingInfoData->AvailableChargingPower*100);
  8521. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8522. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8523. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8524. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8525. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8526. }
  8527. // Message create ====================================================================================================
  8528. random_uuid(guid);
  8529. json_object *MeterValueReq = json_object_new_object();
  8530. json_object *meterValues = json_object_new_array();
  8531. json_object *sampledValues = json_object_new_array();
  8532. json_object *sampledValuesBuffer = json_object_new_array();
  8533. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8534. {
  8535. json_object *meterValue = json_object_new_object();
  8536. json_object *MeterValueBuffer = json_object_new_object();
  8537. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8538. {
  8539. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8540. {
  8541. json_object *sampledValue = json_object_new_object();
  8542. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8543. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8544. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8545. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8546. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8547. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8548. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8549. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8550. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8551. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8552. {
  8553. json_object *signedMeterValue = json_object_new_object();
  8554. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8555. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8556. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8557. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8558. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8559. }
  8560. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8561. {
  8562. json_object *unitOfMeasure = json_object_new_object();
  8563. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8564. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8565. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8566. }
  8567. json_object_array_add(sampledValues, sampledValue);
  8568. // For StopTxn data
  8569. if((isSampledDataTxEnd == TRUE) &&
  8570. (((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand ) != NULL) && (strlen((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value) > 0)) ||
  8571. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL) && (strlen((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value) > 0))))
  8572. {
  8573. json_object *sampledValue = json_object_new_object();
  8574. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8575. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8576. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8577. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8578. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8579. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8580. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8581. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8582. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8583. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8584. {
  8585. json_object *signedMeterValue = json_object_new_object();
  8586. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8587. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8588. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8589. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8590. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8591. }
  8592. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8593. {
  8594. json_object *unitOfMeasure = json_object_new_object();
  8595. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8596. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8597. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8598. }
  8599. json_object_array_add(sampledValuesBuffer, sampledValue);
  8600. }
  8601. }
  8602. }
  8603. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8604. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8605. json_object_array_add(meterValues, meterValue);
  8606. // For StopTxn data
  8607. if((isSampledDataTxEnd == TRUE) && (dataType != ReadingContextEnumType_Trigger) &&
  8608. (json_object_array_length(sampledValuesBuffer) > 0))
  8609. {
  8610. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8611. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  8612. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  8613. meterValueBufferInsert(gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8614. else
  8615. meterValueBufferReplace(200, gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8616. json_object_put(MeterValueBuffer);
  8617. }
  8618. else
  8619. {
  8620. json_object_put(sampledValuesBuffer);
  8621. json_object_put(MeterValueBuffer);
  8622. }
  8623. idxMeter++;
  8624. }
  8625. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8626. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8627. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8628. ,MESSAGE_TYPE_CALL
  8629. ,guid
  8630. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8631. json_object_put(MeterValueReq);
  8632. if((dataType != ReadingContextEnumType_Trigger) &&
  8633. (dataType != ReadingContextEnumType_Sample_Clock))
  8634. {
  8635. // Transaction meter value send by TransactionEvent message
  8636. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8637. if(isSampledDataTxEnd != TRUE)
  8638. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8639. result = PASS;
  8640. }
  8641. else
  8642. {
  8643. // Put request guid to hash map
  8644. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8645. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8646. {
  8647. result = PASS;
  8648. }
  8649. if((dataType != ReadingContextEnumType_Trigger) &&
  8650. (dataType != ReadingContextEnumType_Sample_Clock))
  8651. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8652. else
  8653. {
  8654. if(FirstHeartBeat)
  8655. LWS_Send(queuedata);
  8656. }
  8657. }
  8658. return result;
  8659. }
  8660. int sendNotifyChargingLimitRequest(int gun_index)
  8661. {
  8662. mtrace();
  8663. int result = FAIL;
  8664. char message[4096]={0};
  8665. char guid[37]={0};
  8666. char tempdata[128]={0};
  8667. json_object *NotifyChargingLimit = json_object_new_object();
  8668. json_object *chargingLimit = json_object_new_object();
  8669. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8670. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8671. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8672. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8673. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8674. random_uuid(guid);
  8675. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8676. json_object_put(NotifyChargingLimit);
  8677. LWS_Send(message);
  8678. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8679. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8680. {
  8681. result = PASS;
  8682. }
  8683. return result;
  8684. }
  8685. int sendNotifyCustomerInformationRequest()
  8686. {
  8687. mtrace();
  8688. int result = FAIL;
  8689. char message[4096]={0};
  8690. char guid[37]={0};
  8691. char tempdata[128]={0};
  8692. json_object *NotifyCustomerInformation = json_object_new_object();
  8693. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8694. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8695. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8696. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8697. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8698. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8699. random_uuid(guid);
  8700. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8701. json_object_put(NotifyCustomerInformation);
  8702. LWS_Send(message);
  8703. sprintf(tempdata, "NotifyCustomerInformation,0");
  8704. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8705. {
  8706. result = PASS;
  8707. }
  8708. return result;
  8709. }
  8710. int sendNotifyDisplayMessagesRequest()
  8711. {
  8712. mtrace();
  8713. int result = FAIL;
  8714. char message[4096]={0};
  8715. char guid[37]={0};
  8716. char tempdata[128]={0};
  8717. json_object *NotifyDisplayMessages = json_object_new_object();
  8718. json_object *messageInfos = json_object_new_array();
  8719. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8720. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8721. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8722. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8723. {
  8724. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8725. {
  8726. json_object *messageInfo = json_object_new_object();
  8727. json_object *message = json_object_new_object();
  8728. json_object *display = json_object_new_object();
  8729. json_object *evse = json_object_new_object();
  8730. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8731. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8732. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8733. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8734. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8735. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8736. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8737. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8738. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8739. json_object_object_add(messageInfo, "message", message);
  8740. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8741. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8742. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8743. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8744. json_object_object_add(display, "evse",evse);
  8745. json_object_object_add(messageInfo, "evse", display);
  8746. json_object_array_add(messageInfos, messageInfo);
  8747. }
  8748. }
  8749. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8750. random_uuid(guid);
  8751. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8752. json_object_put(NotifyDisplayMessages);
  8753. LWS_Send(message);
  8754. sprintf(tempdata, "NotifyDisplayMessages,0");
  8755. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8756. {
  8757. result = PASS;
  8758. }
  8759. return result;
  8760. }
  8761. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8762. {
  8763. mtrace();
  8764. int result = FAIL;
  8765. char message[4096]={0};
  8766. char guid[37]={0};
  8767. char tempdata[128]={0};
  8768. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8769. json_object *chargingNeeds = json_object_new_object();
  8770. json_object *acChargingParameters = json_object_new_object();
  8771. json_object *dcChargingParameters = json_object_new_object();
  8772. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8773. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8774. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8775. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8776. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8777. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8778. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8779. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8780. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8781. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8782. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8783. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8784. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8785. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8786. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8787. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8788. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8789. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8790. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8791. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8792. random_uuid(guid);
  8793. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8794. json_object_put(NotifyEVChargingNeeds);
  8795. LWS_Send(message);
  8796. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8797. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8798. {
  8799. result = PASS;
  8800. }
  8801. return result;
  8802. }
  8803. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8804. {
  8805. mtrace();
  8806. int result = FAIL;
  8807. char message[4096]={0};
  8808. char guid[37]={0};
  8809. char tempdata[128]={0};
  8810. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8811. json_object *chargingSchedule = json_object_new_object();
  8812. json_object *periods = json_object_new_array();
  8813. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8814. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8815. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8816. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8817. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8818. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8819. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8820. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8821. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8822. {
  8823. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8824. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8825. {
  8826. json_object *Period = json_object_new_object();
  8827. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8828. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8829. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8830. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8831. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8832. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8833. json_object_array_add(periods, Period);
  8834. }
  8835. }
  8836. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8837. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8838. random_uuid(guid);
  8839. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8840. json_object_put(NotifyEVChargingSchedule);
  8841. LWS_Send(message);
  8842. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8843. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8844. {
  8845. result = PASS;
  8846. }
  8847. return result;
  8848. }
  8849. int sendNotifyEventRequest()
  8850. {
  8851. mtrace();
  8852. int result = FAIL;
  8853. char message[4096]={0};
  8854. char guid[37]={0};
  8855. char tempdata[128]={0};
  8856. json_object *NotifyEvent = json_object_new_object();
  8857. json_object *eventDatas = json_object_new_array();
  8858. DEBUG_INFO("sendNotifyEventRequest...\n");
  8859. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8860. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8861. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8862. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8863. {
  8864. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8865. {
  8866. json_object *eventData = json_object_new_object();
  8867. json_object *component = json_object_new_object();
  8868. json_object *evse = json_object_new_object();
  8869. json_object *variable = json_object_new_object();
  8870. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8871. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8872. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8873. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8874. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8875. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8876. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8877. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8878. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8879. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8880. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8881. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8882. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8883. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8884. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8885. json_object_object_add(component, "evse",evse);
  8886. json_object_object_add(eventData, "component", component);
  8887. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8888. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8889. json_object_object_add(eventData, "variable", variable);
  8890. json_object_array_add(eventDatas, eventData);
  8891. }
  8892. }
  8893. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8894. random_uuid(guid);
  8895. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8896. json_object_put(NotifyEvent);
  8897. LWS_Send(message);
  8898. sprintf(tempdata, "NotifyEvent,0");
  8899. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8900. {
  8901. result = PASS;
  8902. }
  8903. return result;
  8904. }
  8905. int sendNotifyMonitoringReportRequest()
  8906. {
  8907. mtrace();
  8908. int result = FAIL;
  8909. char message[4096]={0};
  8910. char guid[37]={0};
  8911. char tempdata[128]={0};
  8912. json_object *NotifyMonitoringReport = json_object_new_object();
  8913. json_object *monitors = json_object_new_array();
  8914. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8915. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8916. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8917. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8918. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8919. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8920. {
  8921. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8922. {
  8923. json_object *monitor = json_object_new_object();
  8924. json_object *component = json_object_new_object();
  8925. json_object *evse = json_object_new_object();
  8926. json_object *variable = json_object_new_object();
  8927. json_object *variableMonitorings = json_object_new_array();
  8928. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8929. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8930. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8931. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8932. json_object_object_add(component, "evse",evse);
  8933. json_object_object_add(monitor, "component", component);
  8934. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8935. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8936. json_object_object_add(monitor, "variable", variable);
  8937. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8938. {
  8939. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8940. {
  8941. json_object *variableMonitoring = json_object_new_object();
  8942. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8943. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8944. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8945. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8946. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8947. json_object_array_add(variableMonitorings, variableMonitoring);
  8948. }
  8949. }
  8950. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8951. json_object_array_add(monitors, monitor);
  8952. }
  8953. }
  8954. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8955. random_uuid(guid);
  8956. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8957. json_object_put(NotifyMonitoringReport);
  8958. LWS_Send(message);
  8959. sprintf(tempdata, "NotifyMonitoringReport,0");
  8960. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8961. {
  8962. result = PASS;
  8963. }
  8964. return result;
  8965. }
  8966. int sendNotifyReportRequest()
  8967. {
  8968. mtrace();
  8969. int result = FAIL;
  8970. char message[4096]={0};
  8971. char guid[37]={0};
  8972. char tempdata[128]={0};
  8973. json_object *NotifyReport = json_object_new_object();
  8974. json_object *reportDatas = json_object_new_array();
  8975. DEBUG_INFO("sendNotifyReportRequest...\n");
  8976. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8977. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8978. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8979. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8980. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8981. {
  8982. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8983. {
  8984. json_object *reportData = json_object_new_object();
  8985. json_object *component = json_object_new_object();
  8986. json_object *evse = json_object_new_object();
  8987. json_object *variable = json_object_new_object();
  8988. json_object *variableAttributes = json_object_new_array();
  8989. json_object *variableCharacteristics = json_object_new_object();
  8990. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8991. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8992. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8993. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8994. json_object_object_add(component, "evse",evse);
  8995. json_object_object_add(reportData, "component", component);
  8996. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8997. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8998. json_object_object_add(reportData, "variable",variable);
  8999. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  9000. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  9001. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  9002. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  9003. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  9004. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  9005. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  9006. {
  9007. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  9008. {
  9009. json_object *variableAttribute = json_object_new_object();
  9010. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  9011. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  9012. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  9013. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  9014. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  9015. json_object_array_add(variableAttributes, variableAttribute);
  9016. }
  9017. }
  9018. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  9019. json_object_array_add(reportDatas, reportData);
  9020. }
  9021. }
  9022. json_object_object_add(NotifyReport, "reportData", reportDatas);
  9023. random_uuid(guid);
  9024. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  9025. json_object_put(NotifyReport);
  9026. LWS_SendNow(message);
  9027. sprintf(tempdata, "NotifyReport,0");
  9028. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9029. {
  9030. result = PASS;
  9031. }
  9032. return result;
  9033. }
  9034. int sendPublishFirmwareStatusNotificationRequest()
  9035. {
  9036. mtrace();
  9037. int result = FAIL;
  9038. char message[4096]={0};
  9039. char guid[37]={0};
  9040. char tempdata[128]={0};
  9041. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  9042. json_object *locations = json_object_new_array();
  9043. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  9044. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  9045. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  9046. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  9047. {
  9048. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  9049. }
  9050. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  9051. random_uuid(guid);
  9052. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  9053. json_object_put(PublishFirmwareStatusNotification);
  9054. LWS_Send(message);
  9055. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  9056. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9057. {
  9058. result = PASS;
  9059. }
  9060. return result;
  9061. }
  9062. int sendReportChargingProfilesRequest(int gun_index)
  9063. {
  9064. mtrace();
  9065. int result = FAIL;
  9066. char message[4096]={0};
  9067. char guid[37]={0};
  9068. char tempdata[128]={0};
  9069. json_object *ReportChargingProfiles = json_object_new_object();
  9070. json_object *chargingProfiles = json_object_new_array();
  9071. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  9072. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  9073. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  9074. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  9075. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  9076. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  9077. {
  9078. json_object *chargingProfile = json_object_new_object();
  9079. json_object *chargingSchedules = json_object_new_array();
  9080. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  9081. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  9082. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  9083. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  9084. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  9085. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  9086. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  9087. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  9088. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  9089. {
  9090. json_object *chargingSchedule = json_object_new_object();
  9091. json_object *chargingSchedulePeriods = json_object_new_array();
  9092. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  9093. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  9094. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  9095. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  9096. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  9097. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  9098. {
  9099. json_object *chargingSchedulePeriod = json_object_new_object();
  9100. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  9101. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  9102. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  9103. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  9104. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  9105. }
  9106. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  9107. json_object_array_add(chargingSchedules, chargingSchedule);
  9108. }
  9109. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  9110. json_object_array_add(chargingProfiles, chargingProfile);
  9111. }
  9112. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  9113. random_uuid(guid);
  9114. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9115. json_object_put(ReportChargingProfiles);
  9116. LWS_Send(message);
  9117. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  9118. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9119. {
  9120. result = PASS;
  9121. }
  9122. return result;
  9123. }
  9124. int sendReservationStatusUpdateRequest(int gun_index)
  9125. {
  9126. mtrace();
  9127. int result = FAIL;
  9128. char message[4096]={0};
  9129. char guid[37]={0};
  9130. char tempdata[128]={0};
  9131. json_object *ReservationStatusUpdate = json_object_new_object();
  9132. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  9133. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  9134. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  9135. random_uuid(guid);
  9136. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  9137. json_object_put(ReservationStatusUpdate);
  9138. LWS_Send(message);
  9139. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  9140. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9141. {
  9142. result = PASS;
  9143. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  9144. }
  9145. return result;
  9146. }
  9147. int sendSecurityEventNotificationRequest()
  9148. {
  9149. mtrace();
  9150. int result = FAIL;
  9151. char message[4096]={0};
  9152. char guid[37]={0};
  9153. char tempdata[128]={0};
  9154. struct timeval tmnow;
  9155. struct tm *tm;
  9156. char buf[28];//, usec_buf[6];
  9157. json_object *SecurityEventNotification = json_object_new_object();
  9158. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  9159. DB_getSecurityEventType();
  9160. gettimeofday(&tmnow, NULL);
  9161. time_t t;
  9162. t = time(NULL);
  9163. /*UTC time and date*/
  9164. tm = gmtime(&t);
  9165. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9166. #if 0 // remove temporally
  9167. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9168. strcat(buf,".");
  9169. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9170. strcat(buf,usec_buf);
  9171. #endif
  9172. printf("%s",buf);
  9173. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  9174. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9175. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9176. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9177. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9178. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9179. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9180. random_uuid(guid);
  9181. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9182. json_object_put(SecurityEventNotification);
  9183. LWS_Send(message);
  9184. sprintf(tempdata, "SecurityEventNotification,0");
  9185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9186. {
  9187. result = PASS;
  9188. }
  9189. return result;
  9190. }
  9191. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9192. {
  9193. mtrace();
  9194. int result = FAIL;
  9195. char message[4096]={0};
  9196. char guid[37]={0};
  9197. char tempdata[128]={0};
  9198. json_object *SignCertificate = json_object_new_object();
  9199. DEBUG_INFO("sendSignCertificateRequest...\n");
  9200. // Read csr file content
  9201. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9202. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?CSR_V2G:CSR_CP),"r");
  9203. char *line = NULL;
  9204. size_t len = 0;
  9205. while(getline(&line, &len, fp) != -1)
  9206. {
  9207. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9208. {
  9209. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9210. }
  9211. }
  9212. fclose(fp);
  9213. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9214. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9215. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9216. random_uuid(guid);
  9217. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9218. json_object_put(SignCertificate);
  9219. LWS_Send(message);
  9220. sprintf(tempdata, "SignCertificate,0");
  9221. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9222. {
  9223. result = PASS;
  9224. }
  9225. return result;
  9226. }
  9227. int sendStatusNotificationRequest(int gun_index)
  9228. {
  9229. mtrace();
  9230. int result = FAIL;
  9231. char message[600]={0};
  9232. char guid[37];
  9233. int currentStatus = 0;
  9234. struct timeval tmnow;
  9235. struct tm *tm;
  9236. char buf[28];//, usec_buf[6];
  9237. char tempdata[65]={0};
  9238. int tempIndex = 0;
  9239. uint8_t isStateChanged = TRUE;
  9240. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9241. gettimeofday(&tmnow, NULL);
  9242. time_t t;
  9243. t = time(NULL);
  9244. /*UTC time and date*/
  9245. tm = gmtime(&t);
  9246. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9247. #if 0 // remove temporally
  9248. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9249. strcat(buf,".");
  9250. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9251. strcat(buf,usec_buf);
  9252. #endif
  9253. printf("%s",buf);
  9254. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9255. ShmOCPP20Data->StatusNotification[gun_index].connectorId = 1;
  9256. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9257. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9258. /*
  9259. enum _SYSTEM_STATUS
  9260. {
  9261. S_BOOTING = 0,
  9262. S_IDLE, = 1
  9263. S_AUTHORIZING, =2
  9264. S_REASSIGN_CHECK, =3
  9265. S_REASSIGN, =4
  9266. S_PRECHARGE, =5
  9267. S_PREPARING_FOR_EV, =6
  9268. S_PREPARING_FOR_EVSE, =7
  9269. S_CHARGING, =8
  9270. S_TERMINATING, =9
  9271. S_COMPLETE, =10
  9272. S_ALARM, =11
  9273. S_FAULT =12
  9274. }
  9275. */
  9276. //check Transaction active
  9277. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9278. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9279. {
  9280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9281. {
  9282. tempIndex = ((gun_index==2) ? 1: 0);
  9283. }
  9284. else
  9285. {
  9286. tempIndex = gun_index;
  9287. }
  9288. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9289. {
  9290. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9291. {
  9292. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9293. {
  9294. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9295. {
  9296. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9297. }
  9298. else
  9299. {
  9300. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9301. }
  9302. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9303. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9304. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9305. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9306. }
  9307. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9308. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9309. ) //S_PRECHARGE
  9310. {
  9311. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9312. }
  9313. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9314. {
  9315. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9316. }
  9317. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9318. {
  9319. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9320. }
  9321. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9322. {
  9323. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9324. }
  9325. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9326. {
  9327. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9328. }
  9329. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9330. {
  9331. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9332. }
  9333. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9334. {
  9335. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9336. }
  9337. } //end of the same index
  9338. }//end of for CHAdeMO_QUANTITY
  9339. }
  9340. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9341. {
  9342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9343. {
  9344. tempIndex = ((gun_index==2) ? 1: 0);
  9345. }
  9346. else
  9347. {
  9348. tempIndex = gun_index;
  9349. }
  9350. for (int index = 0; index < CCS_QUANTITY; index++)
  9351. {
  9352. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9353. {
  9354. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9355. {
  9356. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9357. {
  9358. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9359. }
  9360. else
  9361. {
  9362. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9363. }
  9364. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9365. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9366. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9367. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9368. }
  9369. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9370. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9371. ) //S_PRECHARGE
  9372. {
  9373. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9374. }
  9375. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9376. {
  9377. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9378. }
  9379. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9380. {
  9381. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9382. }
  9383. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9384. {
  9385. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9386. }
  9387. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9388. {
  9389. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9390. }
  9391. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9392. {
  9393. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9394. }
  9395. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9396. {
  9397. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9398. }
  9399. } //end of the same index
  9400. } // end of for CCS_QUANTITY
  9401. }
  9402. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9403. {
  9404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9405. {
  9406. tempIndex = ((gun_index==2) ? 1: 0);
  9407. }
  9408. else
  9409. {
  9410. tempIndex = gun_index;
  9411. }
  9412. for (int index = 0; index < GB_QUANTITY; index++)
  9413. {
  9414. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9415. {
  9416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9417. {
  9418. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9419. {
  9420. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9421. }
  9422. else
  9423. {
  9424. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9425. }
  9426. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9427. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9428. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9429. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9430. }
  9431. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9432. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9433. ) //S_PRECHARGE
  9434. {
  9435. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9436. }
  9437. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9438. {
  9439. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9440. }
  9441. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9442. {
  9443. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9444. }
  9445. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9446. {
  9447. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9448. }
  9449. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9450. {
  9451. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9452. }
  9453. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9454. {
  9455. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9456. }
  9457. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9458. {
  9459. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9460. }
  9461. } //end of the same index
  9462. } // end of for GB_QUANTITY
  9463. }
  9464. else if(gunType[gun_index] == GUN_TYPE_DO)
  9465. {
  9466. tempIndex = gun_index;
  9467. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9468. {
  9469. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9470. {
  9471. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9472. {
  9473. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9474. {
  9475. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9476. }
  9477. else
  9478. {
  9479. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9480. }
  9481. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9482. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9483. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9484. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9485. }
  9486. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9487. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9488. ) //S_PRECHARGE
  9489. {
  9490. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9491. }
  9492. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9493. {
  9494. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9495. }
  9496. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9497. {
  9498. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9499. }
  9500. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9501. {
  9502. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9503. }
  9504. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9505. {
  9506. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9507. }
  9508. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9509. {
  9510. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9511. }
  9512. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9513. {
  9514. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9515. }
  9516. } //end of the same index
  9517. }
  9518. }
  9519. else
  9520. {
  9521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9522. {
  9523. tempIndex = 2;
  9524. }
  9525. else
  9526. {
  9527. tempIndex = gun_index;
  9528. }
  9529. for (int index = 0; index < AC_QUANTITY; index++)
  9530. {
  9531. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9532. {
  9533. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9534. {
  9535. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  9536. {
  9537. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9538. }
  9539. else
  9540. {
  9541. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9542. }
  9543. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9544. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9545. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9546. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9547. }
  9548. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9549. {
  9550. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9551. }
  9552. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9553. {
  9554. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9555. }
  9556. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9557. {
  9558. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9559. }
  9560. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9561. {
  9562. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9563. }
  9564. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9565. {
  9566. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9567. }
  9568. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9569. {
  9570. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9571. }
  9572. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9573. {
  9574. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9575. }
  9576. }//end of the same index
  9577. }//end of for AC_QUANTITY
  9578. }
  9579. //it's option
  9580. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9581. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9582. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9583. {
  9584. isStateChanged = FALSE;
  9585. }
  9586. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9587. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9588. random_uuid(guid);
  9589. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9590. , MESSAGE_TYPE_CALL
  9591. , guid
  9592. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9593. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9594. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9595. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9596. if((server_sign == TRUE) && isStateChanged)
  9597. {
  9598. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9599. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9600. LWS_Send(message);
  9601. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9602. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9603. {
  9604. result = PASS;
  9605. }
  9606. }
  9607. else
  9608. {
  9609. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9610. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9611. result = PASS;
  9612. }
  9613. return result;
  9614. }
  9615. int sendTransactionEventRequest(int gun_index)
  9616. {
  9617. mtrace();
  9618. int result = FAIL;
  9619. char message[QUEUE_MESSAGE_LENGTH]={0};
  9620. char guid[37]={0};
  9621. char tempdata[128]={0};
  9622. uint8_t tempIndex;
  9623. json_object *TransactionEvent = json_object_new_object();
  9624. json_object *transactionInfo = json_object_new_object();
  9625. json_object *idToken = json_object_new_object();
  9626. json_object *evse = json_object_new_object();
  9627. json_object *meterValues = json_object_new_array();
  9628. char TempStopTransaction[256];
  9629. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9630. DEBUG_INFO("sendTransactionEventRequest...\n");
  9631. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9632. {
  9633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9634. {
  9635. tempIndex = ((gun_index==2) ? 1: 0);
  9636. }
  9637. else
  9638. {
  9639. tempIndex = gun_index;
  9640. }
  9641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9642. {
  9643. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9644. {
  9645. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9646. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9647. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9648. else
  9649. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9650. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9651. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9652. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9653. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9654. {
  9655. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9656. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9657. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9658. {
  9659. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9660. }
  9661. else
  9662. {
  9663. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9664. }
  9665. }
  9666. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9667. {
  9668. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9669. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9670. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9671. }
  9672. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9673. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9674. ) //S_PRECHARGE
  9675. {
  9676. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9677. {
  9678. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9679. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9680. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9682. }
  9683. else
  9684. {
  9685. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9686. }
  9687. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9688. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9689. }
  9690. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9691. {
  9692. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9693. {
  9694. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9695. {
  9696. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9697. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9698. }
  9699. else
  9700. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9701. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9702. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9703. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9704. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9705. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9706. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9707. }
  9708. else
  9709. {
  9710. storeTempStopTransaction(gun_index);
  9711. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9712. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9713. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9714. }
  9715. }
  9716. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9717. {
  9718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9719. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9720. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9721. if((access(TempStopTransaction,F_OK))!=-1)
  9722. {
  9723. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9724. }
  9725. }
  9726. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9727. {
  9728. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9729. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9730. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9731. }
  9732. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9733. {
  9734. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9735. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9736. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9737. }
  9738. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9739. {
  9740. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9741. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9742. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9743. }
  9744. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9745. {
  9746. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9747. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9748. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9749. }
  9750. } //end of the same index
  9751. }//end of for CHAdeMO_QUANTITY
  9752. }
  9753. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9754. {
  9755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9756. {
  9757. tempIndex = ((gun_index==2) ? 1: 0);
  9758. }
  9759. else
  9760. {
  9761. tempIndex = gun_index;
  9762. }
  9763. for (int index = 0; index < CCS_QUANTITY; index++)
  9764. {
  9765. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9766. {
  9767. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9768. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9769. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9770. else
  9771. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9772. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9773. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9774. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9775. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9776. {
  9777. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9778. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9779. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9780. {
  9781. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9782. }
  9783. else
  9784. {
  9785. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9786. }
  9787. }
  9788. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9789. {
  9790. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9791. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9792. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9793. }
  9794. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9795. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9796. ) //S_PRECHARGE
  9797. {
  9798. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9799. {
  9800. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9801. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9802. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9803. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9804. }
  9805. else
  9806. {
  9807. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9808. }
  9809. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9811. }
  9812. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9813. {
  9814. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9815. {
  9816. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9817. {
  9818. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9819. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9820. }
  9821. else
  9822. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9825. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9826. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9827. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9828. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9829. }
  9830. else
  9831. {
  9832. storeTempStopTransaction(gun_index);
  9833. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9836. }
  9837. }
  9838. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9839. {
  9840. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9841. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9842. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9843. if((access(TempStopTransaction,F_OK))!=-1)
  9844. {
  9845. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9846. }
  9847. }
  9848. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9849. {
  9850. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9851. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9852. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9853. }
  9854. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9855. {
  9856. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9857. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9858. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9859. }
  9860. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9861. {
  9862. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9864. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9865. }
  9866. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9867. {
  9868. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9869. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9871. }
  9872. } //end of the same index
  9873. } // end of for CCS_QUANTITY
  9874. }
  9875. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9876. {
  9877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9878. {
  9879. tempIndex = ((gun_index==2) ? 1: 0);
  9880. }
  9881. else
  9882. {
  9883. tempIndex = gun_index;
  9884. }
  9885. for (int index = 0; index < GB_QUANTITY; index++)
  9886. {
  9887. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9888. {
  9889. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9890. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9891. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9892. else
  9893. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9894. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9895. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9896. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9897. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9898. {
  9899. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9900. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9901. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9902. {
  9903. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9904. }
  9905. else
  9906. {
  9907. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9908. }
  9909. }
  9910. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9911. {
  9912. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9913. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9914. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9915. }
  9916. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9917. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9918. ) //S_PRECHARGE
  9919. {
  9920. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9921. {
  9922. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9923. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9924. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9925. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9926. }
  9927. else
  9928. {
  9929. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9930. }
  9931. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9932. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9933. }
  9934. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9935. {
  9936. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9937. {
  9938. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  9939. {
  9940. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9941. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9942. }
  9943. else
  9944. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9945. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9946. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9947. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9948. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9949. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9950. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  9951. }
  9952. else
  9953. {
  9954. storeTempStopTransaction(gun_index);
  9955. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9956. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9957. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9958. }
  9959. }
  9960. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9961. {
  9962. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9963. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9964. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9965. if((access(TempStopTransaction,F_OK))!=-1)
  9966. {
  9967. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9968. }
  9969. }
  9970. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9971. {
  9972. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9973. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9974. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9975. }
  9976. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  9977. {
  9978. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9979. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9980. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9981. }
  9982. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9983. {
  9984. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9986. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9987. }
  9988. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9989. {
  9990. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9991. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9992. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9993. }
  9994. } //end of the same index
  9995. } // end of for GB_QUANTITY
  9996. }
  9997. else if(gunType[gun_index] == GUN_TYPE_DO)
  9998. {
  9999. tempIndex = gun_index;
  10000. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10001. {
  10002. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10003. {
  10004. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10005. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10006. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10007. else
  10008. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10009. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10010. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10011. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10012. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10013. {
  10014. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10015. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10016. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  10017. {
  10018. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10019. }
  10020. else
  10021. {
  10022. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10023. }
  10024. }
  10025. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10026. {
  10027. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10028. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10029. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10030. }
  10031. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10032. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10033. ) //S_PRECHARGE
  10034. {
  10035. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10036. {
  10037. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10038. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10039. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10040. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10041. }
  10042. else
  10043. {
  10044. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10045. }
  10046. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10047. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10048. }
  10049. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10050. {
  10051. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10052. {
  10053. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  10054. {
  10055. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10056. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10057. }
  10058. else
  10059. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10060. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10061. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10062. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10063. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10064. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10065. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  10066. }
  10067. else
  10068. {
  10069. storeTempStopTransaction(gun_index);
  10070. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10071. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10072. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10073. }
  10074. }
  10075. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10076. {
  10077. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10078. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10079. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10080. if((access(TempStopTransaction,F_OK))!=-1)
  10081. {
  10082. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10083. }
  10084. }
  10085. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10086. {
  10087. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10088. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10089. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10090. }
  10091. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  10092. {
  10093. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10094. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10095. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10096. }
  10097. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10098. {
  10099. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10100. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10101. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10102. }
  10103. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10104. {
  10105. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10106. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10107. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10108. }
  10109. } //end of the same index
  10110. }
  10111. }
  10112. else
  10113. {
  10114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10115. {
  10116. tempIndex = 2;
  10117. }
  10118. else
  10119. {
  10120. tempIndex = gun_index;
  10121. }
  10122. for (int index = 0; index < AC_QUANTITY; index++)
  10123. {
  10124. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10125. {
  10126. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10127. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10128. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10129. else
  10130. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10131. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10132. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10133. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  10135. {
  10136. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10137. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  10139. {
  10140. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10141. }
  10142. else
  10143. {
  10144. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10145. }
  10146. }
  10147. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10148. {
  10149. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10150. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10151. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10152. }
  10153. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10154. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10155. ) //S_PRECHARGE
  10156. {
  10157. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10158. {
  10159. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10160. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10161. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10162. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10163. }
  10164. else
  10165. {
  10166. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10167. }
  10168. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10169. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10170. }
  10171. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10172. {
  10173. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10174. {
  10175. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10176. {
  10177. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10178. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10179. }
  10180. else
  10181. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10182. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10183. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10184. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10185. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10186. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10187. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10188. }
  10189. else
  10190. {
  10191. storeTempStopTransaction(gun_index);
  10192. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10193. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10194. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10195. }
  10196. }
  10197. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10198. {
  10199. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10200. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10201. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10202. if((access(TempStopTransaction,F_OK))!=-1)
  10203. {
  10204. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10205. }
  10206. }
  10207. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10208. {
  10209. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10210. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10211. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10212. }
  10213. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  10214. {
  10215. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10216. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10217. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10218. }
  10219. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10220. {
  10221. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10222. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10223. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10224. }
  10225. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10226. {
  10227. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10228. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10229. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10230. }
  10231. }//end of the same index
  10232. }//end of for AC_QUANTITY
  10233. }
  10234. // Check if this message is triggered by TriggerMessage
  10235. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10236. {
  10237. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10238. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10239. }
  10240. // Clear meterValue buffer for the next transaction
  10241. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10242. {
  10243. meterValueBufferClear(gun_index);
  10244. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Transaction_Begin, FALSE);
  10245. }
  10246. // Message
  10247. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10248. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10249. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10250. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10251. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10252. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10253. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10254. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10255. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10256. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10257. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10258. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10259. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10260. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10261. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10262. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10263. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10264. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10265. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10266. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10267. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10268. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10269. {
  10270. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10271. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10272. json_object_object_add(TransactionEvent, "idToken", idToken);
  10273. }
  10274. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10275. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10276. json_object_object_add(TransactionEvent, "evse", evse);
  10277. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10278. {
  10279. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10280. {
  10281. json_object *meterValue = json_object_new_object();
  10282. json_object *sampledValues = json_object_new_array();
  10283. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10284. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10285. {
  10286. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10287. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) ||
  10288. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) ||
  10289. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) ||
  10290. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  10291. {
  10292. if(((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)) ||
  10293. ((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) == NULL)))
  10294. {
  10295. json_object *sampledValue = json_object_new_object();
  10296. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10297. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10298. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10299. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10300. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10301. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10302. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10303. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10304. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10305. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10306. {
  10307. json_object *unitOfMeasure = json_object_new_object();
  10308. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10309. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10310. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10311. }
  10312. json_object_array_add(sampledValues, sampledValue);
  10313. }
  10314. }
  10315. }
  10316. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10317. json_object_array_add(meterValues, meterValue);
  10318. }
  10319. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10320. }
  10321. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10322. {
  10323. json_object *meterValues = json_object_new_array();
  10324. meterValueBufferQuery(gun_index, meterValues);
  10325. if(json_object_array_length(meterValues) > 0)
  10326. {
  10327. DEBUG_INFO("parsed meterValue: %s\n", json_object_to_json_string_ext(meterValues, JSON_C_TO_STRING_PLAIN));
  10328. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10329. }
  10330. }
  10331. random_uuid(guid);
  10332. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10333. json_object_put(TransactionEvent);
  10334. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10335. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10336. {
  10337. result = PASS;
  10338. }
  10339. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10340. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10341. {
  10342. OCPP_insert_transaction_msg(YES, message);
  10343. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  10344. }
  10345. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10346. {
  10347. OCPP_insert_transaction_msg(NO, message);
  10348. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10349. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10350. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10351. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10352. }
  10353. return result;
  10354. }
  10355. //==========================================
  10356. // send confirm routine
  10357. //==========================================
  10358. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10359. {
  10360. mtrace();
  10361. int result = FAIL;
  10362. char message[4096]={0};
  10363. json_object *CancelReservation = json_object_new_object();
  10364. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10365. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10366. sprintf(message,"[%d,\"%s\",%s]"
  10367. ,MESSAGE_TYPE_CALLRESULT
  10368. ,uuid
  10369. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10370. json_object_put(CancelReservation);
  10371. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10372. LWS_Send(message);
  10373. result = TRUE;
  10374. return result;
  10375. }
  10376. int sendCertificateSignedConfirmation(char *uuid)
  10377. {
  10378. mtrace();
  10379. int result = FAIL;
  10380. char message[4096]={0};
  10381. json_object *CertificateSigned = json_object_new_object();
  10382. json_object *statusInfo = json_object_new_object();
  10383. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10384. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10385. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10386. {
  10387. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10388. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10389. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10390. }
  10391. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10392. sprintf(message,"[%d,\"%s\",%s]"
  10393. ,MESSAGE_TYPE_CALLRESULT
  10394. ,uuid
  10395. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10396. json_object_put(CertificateSigned);
  10397. LWS_Send(message);
  10398. result = TRUE;
  10399. return result;
  10400. }
  10401. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10402. {
  10403. mtrace();
  10404. int result = FAIL;
  10405. char message[4096]={0};
  10406. json_object *ChangeAvailability = json_object_new_object();
  10407. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10408. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10409. sprintf(message,"[%d,\"%s\",%s]"
  10410. ,MESSAGE_TYPE_CALLRESULT
  10411. ,uuid
  10412. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10413. json_object_put(ChangeAvailability);
  10414. LWS_Send(message);
  10415. result = TRUE;
  10416. return result;
  10417. }
  10418. int sendClearCacheConfirmation(char *uuid)
  10419. {
  10420. mtrace();
  10421. int result = FAIL;
  10422. char message[4096]={0};
  10423. json_object *ClearCache = json_object_new_object();
  10424. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10425. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10426. sprintf(message,"[%d,\"%s\",%s]"
  10427. ,MESSAGE_TYPE_CALLRESULT
  10428. ,uuid
  10429. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10430. json_object_put(ClearCache);
  10431. LWS_Send(message);
  10432. result = TRUE;
  10433. return result;
  10434. }
  10435. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10436. {
  10437. mtrace();
  10438. int result = FAIL;
  10439. char message[500]={0};
  10440. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10441. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10442. LWS_Send(message);
  10443. return result;
  10444. }
  10445. int sendClearDisplayMessageConfirmation(char *uuid)
  10446. {
  10447. mtrace();
  10448. int result = FAIL;
  10449. char message[4096]={0};
  10450. json_object *ClearDisplayMessage = json_object_new_object();
  10451. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10452. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10453. sprintf(message,"[%d,\"%s\",%s]"
  10454. ,MESSAGE_TYPE_CALLRESULT
  10455. ,uuid
  10456. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10457. json_object_put(ClearDisplayMessage);
  10458. LWS_Send(message);
  10459. result = TRUE;
  10460. return result;
  10461. }
  10462. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10463. {
  10464. mtrace();
  10465. int result = FAIL;
  10466. char message[4096]={0};
  10467. json_object *ClearVariableMonitoring = json_object_new_object();
  10468. json_object *clearMonitoringResults = json_object_new_array();
  10469. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10470. for(int idx=0;idx<variableQuantity;idx++)
  10471. {
  10472. json_object *clearMonitoringResult = json_object_new_object();
  10473. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10474. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10475. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10476. }
  10477. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10478. sprintf(message,"[%d,\"%s\",%s]"
  10479. ,MESSAGE_TYPE_CALLRESULT
  10480. ,uuid
  10481. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10482. json_object_put(ClearVariableMonitoring);
  10483. LWS_Send(message);
  10484. result = TRUE;
  10485. return result;
  10486. }
  10487. int sendCostUpdatedConfirmation(char *uuid)
  10488. {
  10489. mtrace();
  10490. int result = FAIL;
  10491. char message[4096]={0};
  10492. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10493. sprintf(message,"[%d,\"%s\",{}]"
  10494. ,MESSAGE_TYPE_CALLRESULT
  10495. ,uuid);
  10496. LWS_Send(message);
  10497. result = TRUE;
  10498. return result;
  10499. }
  10500. int sendCustomerInformationConfirmation(char *uuid)
  10501. {
  10502. mtrace();
  10503. int result = FAIL;
  10504. char message[4096]={0};
  10505. json_object *CustomerInformation = json_object_new_object();
  10506. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10507. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10508. sprintf(message,"[%d,\"%s\",%s]"
  10509. ,MESSAGE_TYPE_CALLRESULT
  10510. ,uuid
  10511. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10512. json_object_put(CustomerInformation);
  10513. LWS_Send(message);
  10514. result = TRUE;
  10515. return result;
  10516. }
  10517. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10518. {
  10519. mtrace();
  10520. int result = FAIL;
  10521. char message[4096]={0};
  10522. json_object *DataTransfer = json_object_new_object();
  10523. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10524. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10525. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10526. sprintf(message,"[%d,\"%s\",%s]"
  10527. ,MESSAGE_TYPE_CALLRESULT
  10528. ,uuid
  10529. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10530. json_object_put(DataTransfer);
  10531. LWS_Send(message);
  10532. result = TRUE;
  10533. return result;
  10534. }
  10535. int sendDeleteCertificateConfirmation(char *uuid)
  10536. {
  10537. mtrace();
  10538. int result = FAIL;
  10539. char message[4096]={0};
  10540. json_object *DeleteCertificate = json_object_new_object();
  10541. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10542. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10543. sprintf(message,"[%d,\"%s\",%s]"
  10544. ,MESSAGE_TYPE_CALLRESULT
  10545. ,uuid
  10546. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10547. json_object_put(DeleteCertificate);
  10548. LWS_Send(message);
  10549. result = TRUE;
  10550. return result;
  10551. }
  10552. int sendGetBaseReportConfirmation(char *uuid)
  10553. {
  10554. mtrace();
  10555. int result = FAIL;
  10556. char message[4096]={0};
  10557. json_object *GetBaseReport = json_object_new_object();
  10558. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10559. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10560. sprintf(message,"[%d,\"%s\",%s]"
  10561. ,MESSAGE_TYPE_CALLRESULT
  10562. ,uuid
  10563. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10564. json_object_put(GetBaseReport);
  10565. LWS_Send(message);
  10566. result = TRUE;
  10567. return result;
  10568. }
  10569. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10570. {
  10571. mtrace();
  10572. int result = FAIL;
  10573. char message[4096]={0};
  10574. json_object *GetChargingProfiles = json_object_new_object();
  10575. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10576. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10577. sprintf(message,"[%d,\"%s\",%s]"
  10578. ,MESSAGE_TYPE_CALLRESULT
  10579. ,uuid
  10580. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10581. json_object_put(GetChargingProfiles);
  10582. LWS_Send(message);
  10583. result = TRUE;
  10584. return result;
  10585. }
  10586. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int evseIdInt, int nPeriod)
  10587. {
  10588. mtrace();
  10589. int result = FAIL;
  10590. char message[4096]={0};
  10591. int CompositeScheduleIndex = 0;
  10592. json_object *GetCompositeSchedule = json_object_new_object();
  10593. json_object *schedule = json_object_new_object();
  10594. json_object *chargingSchedule = json_object_new_object();
  10595. json_object *chargingSchedulePeriod = json_object_new_array();
  10596. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10597. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10598. CompositeScheduleIndex = (evseIdInt > 0) ?(evseIdInt -1) : 0;
  10599. json_object_object_add(schedule, "evseId", json_object_new_int(evseIdInt));
  10600. if(nPeriod == 0)
  10601. {
  10602. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10603. {
  10604. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10605. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10606. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10607. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10608. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10609. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10610. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10611. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10612. uint8_t isNullSchedulePeriod = TRUE;
  10613. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10614. {
  10615. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10616. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10617. {
  10618. json_object *Period = json_object_new_object();
  10619. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10620. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10621. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10622. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10623. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10624. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10625. json_object_array_add(chargingSchedulePeriod, Period);
  10626. isNullSchedulePeriod = FALSE;
  10627. }
  10628. }
  10629. if(isNullSchedulePeriod == TRUE)
  10630. {
  10631. json_object *Period = json_object_new_object();
  10632. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10633. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10634. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10635. json_object_array_add(chargingSchedulePeriod, Period);
  10636. }
  10637. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10638. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10639. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10640. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10641. }
  10642. }
  10643. else
  10644. {
  10645. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10646. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10647. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10648. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10649. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10650. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10651. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10652. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10654. {
  10655. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10656. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10657. {
  10658. json_object *Period = json_object_new_object();
  10659. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10660. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10661. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10662. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10663. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10664. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10665. json_object_array_add(chargingSchedulePeriod, Period);
  10666. }
  10667. }
  10668. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10669. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10670. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10671. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10672. }
  10673. sprintf(message,"[%d,\"%s\",%s]"
  10674. ,MESSAGE_TYPE_CALLRESULT
  10675. ,uuid
  10676. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10677. json_object_put(GetCompositeSchedule);
  10678. LWS_Send(message);
  10679. result = TRUE;
  10680. return result;
  10681. }
  10682. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10683. {
  10684. mtrace();
  10685. int result = FAIL;
  10686. char message[4096]={0};
  10687. json_object *GetGetDisplayMessages = json_object_new_object();
  10688. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10689. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10690. sprintf(message,"[%d,\"%s\",%s]"
  10691. ,MESSAGE_TYPE_CALLRESULT
  10692. ,uuid
  10693. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10694. json_object_put(GetGetDisplayMessages);
  10695. LWS_Send(message);
  10696. result = TRUE;
  10697. return result;
  10698. }
  10699. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10700. {
  10701. mtrace();
  10702. int result = FAIL;
  10703. char message[4096]={0};
  10704. json_object *GetInstalledCertificateIds = json_object_new_object();
  10705. json_object *certificateHashDataChains = json_object_new_array();
  10706. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10707. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10708. for(int idx=0;idx<certQuantity;idx++)
  10709. {
  10710. json_object *cert = json_object_new_object();
  10711. json_object *certificateHashData = json_object_new_object();
  10712. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10713. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10714. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10715. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10716. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10717. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10718. json_object_array_add(certificateHashDataChains, cert);
  10719. }
  10720. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10721. sprintf(message,"[%d,\"%s\",%s]"
  10722. ,MESSAGE_TYPE_CALLRESULT
  10723. ,uuid
  10724. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10725. json_object_put(GetInstalledCertificateIds);
  10726. LWS_Send(message);
  10727. result = TRUE;
  10728. return result;
  10729. }
  10730. int sendGetLocalListVersionConfirmation(char *uuid)
  10731. {
  10732. mtrace();
  10733. int result = FAIL;
  10734. char message[4096]={0};
  10735. json_object *GetLocalListVersion = json_object_new_object();
  10736. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10737. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10738. sprintf(message,"[%d,\"%s\",%s]"
  10739. ,MESSAGE_TYPE_CALLRESULT
  10740. ,uuid
  10741. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10742. json_object_put(GetLocalListVersion);
  10743. LWS_Send(message);
  10744. result = TRUE;
  10745. return result;
  10746. }
  10747. int sendGetLogConfirmation(char *uuid)
  10748. {
  10749. mtrace();
  10750. int result = FAIL;
  10751. char message[4096]={0};
  10752. json_object *GetLog = json_object_new_object();
  10753. DEBUG_INFO("sendGetLogConfirmation...\n");
  10754. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10755. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10756. sprintf(message,"[%d,\"%s\",%s]"
  10757. ,MESSAGE_TYPE_CALLRESULT
  10758. ,uuid
  10759. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10760. json_object_put(GetLog);
  10761. LWS_Send(message);
  10762. result = TRUE;
  10763. return result;
  10764. }
  10765. int sendGetMonitoringReportConfirmation(char *uuid)
  10766. {
  10767. mtrace();
  10768. int result = FAIL;
  10769. char message[4096]={0};
  10770. json_object *GetMonitoringReport = json_object_new_object();
  10771. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10772. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10773. sprintf(message,"[%d,\"%s\",%s]"
  10774. ,MESSAGE_TYPE_CALLRESULT
  10775. ,uuid
  10776. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10777. json_object_put(GetMonitoringReport);
  10778. LWS_Send(message);
  10779. result = TRUE;
  10780. return result;
  10781. }
  10782. int sendGetReportConfirmation(char *uuid)
  10783. {
  10784. mtrace();
  10785. int result = FAIL;
  10786. char message[4096]={0};
  10787. json_object *GetReport = json_object_new_object();
  10788. DEBUG_INFO("sendGetReportConfirmation...\n");
  10789. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10790. sprintf(message,"[%d,\"%s\",%s]"
  10791. ,MESSAGE_TYPE_CALLRESULT
  10792. ,uuid
  10793. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10794. json_object_put(GetReport);
  10795. LWS_Send(message);
  10796. result = TRUE;
  10797. return result;
  10798. }
  10799. int sendGetTransactionStatusConfirmation(char *uuid)
  10800. {
  10801. mtrace();
  10802. int result = FAIL;
  10803. char message[4096]={0};
  10804. json_object *GetTransactionStatus = json_object_new_object();
  10805. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10806. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator));
  10807. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue));
  10808. sprintf(message,"[%d,\"%s\",%s]"
  10809. ,MESSAGE_TYPE_CALLRESULT
  10810. ,uuid
  10811. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10812. json_object_put(GetTransactionStatus);
  10813. LWS_Send(message);
  10814. result = TRUE;
  10815. return result;
  10816. }
  10817. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10818. {
  10819. mtrace();
  10820. int result = FAIL;
  10821. char message[4096]={0};
  10822. json_object *GetVariables = json_object_new_object();
  10823. json_object *getVariableResults = json_object_new_array();
  10824. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10825. for(int idx=0;idx<variableQuantity;idx++)
  10826. {
  10827. json_object *variableResult = json_object_new_object();
  10828. json_object *component = json_object_new_object();
  10829. json_object *variable = json_object_new_object();
  10830. json_object *evse = json_object_new_object();
  10831. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10832. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10833. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10834. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10835. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10836. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10837. {
  10838. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10839. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10840. json_object_object_add(component, "evse", evse);
  10841. }
  10842. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10843. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10844. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10845. json_object_object_add(variableResult, "component", component);
  10846. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10847. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10848. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10849. json_object_object_add(variableResult, "variable", variable);
  10850. json_object_array_add(getVariableResults, variableResult);
  10851. }
  10852. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10853. sprintf(message,"[%d,\"%s\",%s]"
  10854. ,MESSAGE_TYPE_CALLRESULT
  10855. ,uuid
  10856. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10857. json_object_put(GetVariables);
  10858. LWS_Send(message);
  10859. result = TRUE;
  10860. return result;
  10861. }
  10862. int sendInstallCertificateConfirmation(char *uuid)
  10863. {
  10864. mtrace();
  10865. int result = FAIL;
  10866. char message[4096]={0};
  10867. json_object *InstallCertificate = json_object_new_object();
  10868. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10869. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10870. sprintf(message,"[%d,\"%s\",%s]"
  10871. ,MESSAGE_TYPE_CALLRESULT
  10872. ,uuid
  10873. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10874. json_object_put(InstallCertificate);
  10875. LWS_Send(message);
  10876. result = TRUE;
  10877. return result;
  10878. }
  10879. int sendPublishFirmwareConfirmation(char *uuid)
  10880. {
  10881. mtrace();
  10882. int result = FAIL;
  10883. char message[4096]={0};
  10884. json_object *PublishFirmware = json_object_new_object();
  10885. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10886. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10887. sprintf(message,"[%d,\"%s\",%s]"
  10888. ,MESSAGE_TYPE_CALLRESULT
  10889. ,uuid
  10890. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10891. json_object_put(PublishFirmware);
  10892. LWS_Send(message);
  10893. result = TRUE;
  10894. return result;
  10895. }
  10896. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10897. {
  10898. mtrace();
  10899. int result = FAIL;
  10900. char message[4096]={0};
  10901. json_object *RemoteStartTransaction = json_object_new_object();
  10902. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10903. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10904. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10905. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10906. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10907. sprintf(message,"[%d,\"%s\",%s]"
  10908. ,MESSAGE_TYPE_CALLRESULT
  10909. ,uuid
  10910. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10911. json_object_put(RemoteStartTransaction);
  10912. LWS_Send(message);
  10913. result = TRUE;
  10914. return result;
  10915. }
  10916. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10917. {
  10918. mtrace();
  10919. int result = FAIL;
  10920. char message[4096]={0};
  10921. json_object *RemoteStopTransaction = json_object_new_object();
  10922. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  10923. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  10924. sprintf(message,"[%d,\"%s\",%s]"
  10925. ,MESSAGE_TYPE_CALLRESULT
  10926. ,uuid
  10927. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  10928. json_object_put(RemoteStopTransaction);
  10929. LWS_Send(message);
  10930. result = TRUE;
  10931. return result;
  10932. }
  10933. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  10934. {
  10935. mtrace();
  10936. int result = FAIL;
  10937. char message[4096]={0};
  10938. json_object *ReserveNow = json_object_new_object();
  10939. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  10940. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  10941. sprintf(message,"[%d,\"%s\",%s]"
  10942. ,MESSAGE_TYPE_CALLRESULT
  10943. ,uuid
  10944. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10945. json_object_put(ReserveNow);
  10946. LWS_Send(message);
  10947. result = TRUE;
  10948. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10949. return result;
  10950. }
  10951. int sendResetConfirmation(char *uuid)
  10952. {
  10953. mtrace();
  10954. int result = FAIL;
  10955. char message[4096]={0};
  10956. json_object *Reset = json_object_new_object();
  10957. DEBUG_INFO("sendResetConfirmation...\n");
  10958. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10959. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10960. sprintf(message,"[%d,\"%s\",%s]"
  10961. ,MESSAGE_TYPE_CALLRESULT
  10962. ,uuid
  10963. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10964. json_object_put(Reset);
  10965. LWS_Send(message);
  10966. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10967. {
  10968. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10969. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10970. }
  10971. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10972. {
  10973. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10974. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10975. }
  10976. result = TRUE;
  10977. return result;
  10978. }
  10979. int sendSendLocalListConfirmation(char *uuid)
  10980. {
  10981. mtrace();
  10982. int result = FAIL;
  10983. char message[4096]={0};
  10984. json_object *SendLocalList = json_object_new_object();
  10985. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  10986. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10987. sprintf(message,"[%d,\"%s\",%s]"
  10988. ,MESSAGE_TYPE_CALLRESULT
  10989. ,uuid
  10990. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10991. json_object_put(SendLocalList);
  10992. LWS_Send(message);
  10993. result = TRUE;
  10994. return result;
  10995. }
  10996. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10997. {
  10998. mtrace();
  10999. int result = FAIL;
  11000. char message[4096]={0};
  11001. json_object *SetChargingProfile = json_object_new_object();
  11002. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  11003. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  11004. sprintf(message,"[%d,\"%s\",%s]"
  11005. ,MESSAGE_TYPE_CALLRESULT
  11006. ,uuid
  11007. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11008. json_object_put(SetChargingProfile);
  11009. LWS_Send(message);
  11010. result = TRUE;
  11011. return result;
  11012. }
  11013. int sendSetDisplayMessagesConfirmation(char *uuid)
  11014. {
  11015. mtrace();
  11016. int result = FAIL;
  11017. char message[4096]={0};
  11018. json_object *SetDisplayMessage = json_object_new_object();
  11019. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  11020. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  11021. sprintf(message,"[%d,\"%s\",%s]"
  11022. ,MESSAGE_TYPE_CALLRESULT
  11023. ,uuid
  11024. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  11025. json_object_put(SetDisplayMessage);
  11026. LWS_Send(message);
  11027. result = TRUE;
  11028. return result;
  11029. }
  11030. int sendSetMonitoringBaseConfirmation(char *uuid)
  11031. {
  11032. mtrace();
  11033. int result = FAIL;
  11034. char message[4096]={0};
  11035. json_object *SetMonitoringBase = json_object_new_object();
  11036. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  11037. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  11038. sprintf(message,"[%d,\"%s\",%s]"
  11039. ,MESSAGE_TYPE_CALLRESULT
  11040. ,uuid
  11041. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  11042. json_object_put(SetMonitoringBase);
  11043. LWS_Send(message);
  11044. result = TRUE;
  11045. return result;
  11046. }
  11047. int sendSetMonitoringLevelConfirmation(char *uuid)
  11048. {
  11049. mtrace();
  11050. int result = FAIL;
  11051. char message[4096]={0};
  11052. json_object *SetMonitoringLevel = json_object_new_object();
  11053. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  11054. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  11055. sprintf(message,"[%d,\"%s\",%s]"
  11056. ,MESSAGE_TYPE_CALLRESULT
  11057. ,uuid
  11058. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  11059. json_object_put(SetMonitoringLevel);
  11060. LWS_Send(message);
  11061. result = TRUE;
  11062. return result;
  11063. }
  11064. int sendSetNetworkProfileConfirmation(char *uuid)
  11065. {
  11066. mtrace();
  11067. int result = FAIL;
  11068. char message[4096]={0};
  11069. json_object *SetNetworkProfile = json_object_new_object();
  11070. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  11071. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  11072. sprintf(message,"[%d,\"%s\",%s]"
  11073. ,MESSAGE_TYPE_CALLRESULT
  11074. ,uuid
  11075. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  11076. json_object_put(SetNetworkProfile);
  11077. LWS_Send(message);
  11078. result = TRUE;
  11079. return result;
  11080. }
  11081. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  11082. {
  11083. mtrace();
  11084. int result = FAIL;
  11085. char message[4096]={0};
  11086. json_object *SetVariableMonitoring = json_object_new_object();
  11087. json_object *setMonitoringResults = json_object_new_array();
  11088. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  11089. for(int idx=0;idx<variableQuantity;idx++)
  11090. {
  11091. json_object *variableMonitorResult = json_object_new_object();
  11092. json_object *component = json_object_new_object();
  11093. json_object *variable = json_object_new_object();
  11094. json_object *evse = json_object_new_object();
  11095. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  11096. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  11097. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  11098. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  11099. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  11100. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  11101. json_object_object_add(component, "evse", evse);
  11102. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  11103. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  11104. json_object_object_add(variableMonitorResult, "component", component);
  11105. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  11106. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  11107. json_object_object_add(variableMonitorResult, "variable", variable);
  11108. json_object_array_add(setMonitoringResults, variableMonitorResult);
  11109. }
  11110. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  11111. sprintf(message,"[%d,\"%s\",%s]"
  11112. ,MESSAGE_TYPE_CALLRESULT
  11113. ,uuid
  11114. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  11115. json_object_put(SetVariableMonitoring);
  11116. LWS_Send(message);
  11117. result = TRUE;
  11118. return result;
  11119. }
  11120. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  11121. {
  11122. mtrace();
  11123. int result = FAIL;
  11124. char message[4096]={0};
  11125. json_object *SetVariable = json_object_new_object();
  11126. json_object *setVariableResults = json_object_new_array();
  11127. DEBUG_INFO("sendSetVariableConfirmation...\n");
  11128. for(int idx=0;idx<variableQuantity;idx++)
  11129. {
  11130. json_object *variableResult = json_object_new_object();
  11131. json_object *component = json_object_new_object();
  11132. json_object *variable = json_object_new_object();
  11133. json_object *evse = json_object_new_object();
  11134. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  11135. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  11136. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  11137. {
  11138. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  11139. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  11140. json_object_object_add(component, "evse", evse);
  11141. }
  11142. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  11143. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  11144. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  11145. json_object_object_add(variableResult, "component", component);
  11146. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  11147. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  11148. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  11149. json_object_object_add(variableResult, "variable", variable);
  11150. json_object_array_add(setVariableResults, variableResult);
  11151. }
  11152. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  11153. sprintf(message,"[%d,\"%s\",%s]"
  11154. ,MESSAGE_TYPE_CALLRESULT
  11155. ,uuid
  11156. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  11157. json_object_put(SetVariable);
  11158. LWS_Send(message);
  11159. result = TRUE;
  11160. return result;
  11161. }
  11162. int sendTriggerMessageConfirmation(char *uuid)
  11163. {
  11164. mtrace();
  11165. int result = FAIL;
  11166. char message[4096]={0};
  11167. json_object *TriggerMessage = json_object_new_object();
  11168. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  11169. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  11170. sprintf(message,"[%d,\"%s\",%s]",
  11171. MESSAGE_TYPE_CALLRESULT,
  11172. uuid,
  11173. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  11174. json_object_put(TriggerMessage);
  11175. LWS_Send(message);
  11176. result = TRUE;
  11177. return result;
  11178. }
  11179. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  11180. {
  11181. mtrace();
  11182. int result = FAIL;
  11183. char message[4096]={0};
  11184. json_object *UnlockConnector = json_object_new_object();
  11185. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  11186. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  11187. sprintf(message,"[%d,\"%s\",%s]",
  11188. MESSAGE_TYPE_CALLRESULT,
  11189. uuid,
  11190. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  11191. json_object_put(UnlockConnector);
  11192. LWS_Send(message);
  11193. result = TRUE;
  11194. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  11195. return result;
  11196. }
  11197. int sendUnpublishFirmwareConfirmation(char *uuid)
  11198. {
  11199. mtrace();
  11200. int result = FAIL;
  11201. char message[4096]={0};
  11202. json_object *UnpublishFirmware = json_object_new_object();
  11203. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11204. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11205. sprintf(message,"[%d,\"%s\",%s]"
  11206. ,MESSAGE_TYPE_CALLRESULT
  11207. ,uuid
  11208. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11209. json_object_put(UnpublishFirmware);
  11210. LWS_Send(message);
  11211. result = TRUE;
  11212. return result;
  11213. }
  11214. int sendUpdateFirmwareConfirmation(char *uuid)
  11215. {
  11216. mtrace();
  11217. int result = FAIL;
  11218. char message[4096]={0};
  11219. json_object *UpdateFirmware = json_object_new_object();
  11220. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11221. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11222. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11223. sprintf(message,"[%d,\"%s\",%s]"
  11224. ,MESSAGE_TYPE_CALLRESULT
  11225. ,uuid
  11226. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11227. json_object_put(UpdateFirmware);
  11228. LWS_Send(message);
  11229. result = TRUE;
  11230. return result;
  11231. }
  11232. int sendUnknownConfirmation(char *uuid)
  11233. {
  11234. mtrace();
  11235. int result = FAIL;
  11236. char message[256]={0};
  11237. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11238. DEBUG_INFO("sendUnknownConfirmation...\n");
  11239. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11240. LWS_Send(message);
  11241. result = TRUE;
  11242. return result;
  11243. }
  11244. //==========================================
  11245. // send CallError routine
  11246. //==========================================
  11247. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11248. {
  11249. mtrace();
  11250. char message[220]={0};
  11251. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11252. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11253. LWS_Send(message);
  11254. }
  11255. //==========================================
  11256. // Handle server request routine Start
  11257. //==========================================
  11258. int handleCancelReservationRequest(char *uuid, char *payload)
  11259. {
  11260. mtrace();
  11261. int result = FAIL;
  11262. int gunNO = 0;
  11263. int reservationIdInt = -1;
  11264. DEBUG_INFO("handleCancelReservationRequest...\n");
  11265. json_object *CancelReservation;
  11266. CancelReservation = json_tokener_parse(payload);
  11267. if(!is_error(CancelReservation))
  11268. {
  11269. // Required data
  11270. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11271. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11272. }
  11273. json_object_put(CancelReservation);
  11274. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11275. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11276. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11277. if(reservationIdInt != -1)
  11278. {
  11279. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11280. //check Transaction active
  11281. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11283. {
  11284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11285. {
  11286. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11287. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11288. {
  11289. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11290. }
  11291. else
  11292. {
  11293. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11294. }
  11295. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11296. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11297. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11298. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11299. goto end;
  11300. }
  11301. }
  11302. for (int index = 0; index < CCS_QUANTITY; index++)
  11303. {
  11304. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11305. {
  11306. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11307. if(gunType[2] == GUN_TYPE_CCS)
  11308. {
  11309. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11310. }
  11311. else
  11312. {
  11313. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11314. }
  11315. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11316. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11317. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11318. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11319. goto end;
  11320. }
  11321. }
  11322. for (int index = 0; index < GB_QUANTITY; index++)
  11323. {
  11324. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11325. {
  11326. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11327. if(gunType[2] == GUN_TYPE_GBT)
  11328. {
  11329. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11330. }
  11331. else
  11332. {
  11333. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11334. }
  11335. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11336. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11337. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11338. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11339. goto end;
  11340. }
  11341. }
  11342. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11343. {
  11344. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11345. {
  11346. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11347. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11348. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11349. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11350. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11351. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11352. goto end;
  11353. }
  11354. }
  11355. for (int index = 0; index < AC_QUANTITY; index++)
  11356. {
  11357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11358. {
  11359. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11361. {
  11362. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11363. }
  11364. else
  11365. {
  11366. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11367. }
  11368. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11369. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11370. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11371. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11372. goto end;
  11373. }
  11374. }
  11375. }
  11376. //The reservationId does NOT match the reservationId
  11377. sendCancelReservationConfirmation(uuid, gunNO);
  11378. end:
  11379. // Fill in ocpp packet uuid
  11380. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11381. return result;
  11382. }
  11383. int handleCertificateSignedRequest(char *uuid, char *payload)
  11384. {
  11385. mtrace();
  11386. int result = FAIL;
  11387. json_object *CertificateSigned;
  11388. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11389. CertificateSigned = json_tokener_parse(payload);
  11390. if(!is_error(CertificateSigned))
  11391. {
  11392. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11393. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11394. // Required data
  11395. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11396. // Optional data
  11397. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11398. {
  11399. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11400. }
  11401. else
  11402. {
  11403. if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11404. {
  11405. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]);
  11406. }
  11407. else if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11408. {
  11409. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]);
  11410. }
  11411. }
  11412. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11413. {
  11414. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  11415. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11416. fclose(fp);
  11417. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11418. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11419. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  11420. {
  11421. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11422. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  11423. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  11424. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  11425. }
  11426. else
  11427. {
  11428. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11429. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11430. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11431. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11432. }
  11433. }
  11434. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11435. {
  11436. FILE *fp = fopen("/Storage/OCPP/tempV2G.pem", "w");
  11437. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11438. fclose(fp);
  11439. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11440. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11441. if(certVerify(PRIVATE_KEY_V2G, "/Storage/OCPP/tempV2G.pem") == PASS)
  11442. {
  11443. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11444. system("rm -f /Storage/OCPP/certV2G_fallback.pem");
  11445. rename(CERTIFICATE_V2G, "/Storage/OCPP/certV2G_fallback.pem");
  11446. rename("/Storage/OCPP/tempV2G.pem", CERTIFICATE_V2G);
  11447. }
  11448. else
  11449. {
  11450. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11451. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11452. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11453. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11454. }
  11455. }
  11456. else
  11457. {
  11458. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11459. }
  11460. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11461. }
  11462. else
  11463. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11464. json_object_put(CertificateSigned);
  11465. sendCertificateSignedConfirmation(uuid);
  11466. return result;
  11467. }
  11468. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11469. {
  11470. mtrace();
  11471. int result = FAIL;
  11472. int evseId = 0, gunIndex = 0;
  11473. char operationalStatus[16]={0};
  11474. char comfirmstr[20];
  11475. //int specificId = FALSE;
  11476. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11477. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11478. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11479. json_object *ChangeAvailability;
  11480. ChangeAvailability = json_tokener_parse(payload);
  11481. if(!is_error(ChangeAvailability))
  11482. {
  11483. // Required data
  11484. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11485. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11486. // Requested evse. (When omitted, the message refers to the Charging Station as a whole.)
  11487. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11488. {
  11489. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id") != NULL)
  11490. {
  11491. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11492. if(evseId > 0){}
  11493. //specificId = TRUE;
  11494. else
  11495. goto end;
  11496. }
  11497. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11498. {
  11499. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11500. if(gunIndex != 1)
  11501. goto end;
  11502. }
  11503. }
  11504. }
  11505. json_object_put(ChangeAvailability);
  11506. if((evseId != 0) && (evseId <= gunTotalNumber))
  11507. {
  11508. ShmOCPP20Data->ChangeAvailability[evseId-1].evse.id = evseId;
  11509. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11510. }
  11511. else if(evseId == 0)
  11512. {
  11513. for(int i=0; i < gunTotalNumber; i++)
  11514. {
  11515. ShmOCPP20Data->ChangeAvailability[i].evse.id = i+1;
  11516. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11517. }
  11518. }
  11519. /*if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11520. {
  11521. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = 1;
  11522. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11523. }
  11524. else if(gunIndex == 0)
  11525. {
  11526. for(int i=0; i < gunTotalNumber; i++)
  11527. {
  11528. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = 1;
  11529. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11530. }
  11531. }*/
  11532. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11533. {
  11534. //----------------------evseId is 0 ------------------------------------------------//
  11535. if(evseId == 0)
  11536. {
  11537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11538. {
  11539. for(int i=0; i < gunTotalNumber; i++)
  11540. {
  11541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11542. {
  11543. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11544. {
  11545. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11546. {
  11547. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11548. goto end;
  11549. }
  11550. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11551. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11552. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11553. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11554. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11555. {
  11556. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11557. goto end;
  11558. }
  11559. }
  11560. }//END FOR CHAdeMO_QUANTITY
  11561. for (int index = 0; index < CCS_QUANTITY; index++)
  11562. {
  11563. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11564. {
  11565. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11566. {
  11567. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11568. goto end;
  11569. }
  11570. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11571. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11572. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11573. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11574. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11575. {
  11576. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11577. goto end;
  11578. }
  11579. }
  11580. }//END FOR CCS_QUANTITY
  11581. for (int index = 0; index < GB_QUANTITY; index++)
  11582. {
  11583. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11584. {
  11585. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11586. {
  11587. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11588. goto end;
  11589. }
  11590. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11591. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11592. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11593. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11594. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11595. {
  11596. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11597. goto end;
  11598. }
  11599. }
  11600. }// END FOR GB_QUANTITY
  11601. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11602. {
  11603. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11604. {
  11605. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11606. {
  11607. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11608. goto end;
  11609. }
  11610. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11611. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11612. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11613. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11614. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11615. {
  11616. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11617. goto end;
  11618. }
  11619. }
  11620. }// END FOR DO_QUANTITY
  11621. for (int index = 0; index < AC_QUANTITY; index++)
  11622. {
  11623. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11624. {
  11625. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11626. {
  11627. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11628. goto end;
  11629. }
  11630. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11631. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11633. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11634. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11635. {
  11636. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11637. goto end;
  11638. }
  11639. }
  11640. }//END FOR AC_QUANTITY
  11641. }// END FOR gunTotalNumber
  11642. }
  11643. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11644. {
  11645. for(int i=0; i < gunTotalNumber; i++)
  11646. {
  11647. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11648. {
  11649. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11650. goto end;
  11651. }
  11652. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11653. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11654. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11655. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11656. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11657. {
  11658. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11659. goto end;
  11660. }
  11661. }
  11662. }
  11663. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11664. goto end;
  11665. }
  11666. //----------------------gunIndex is not 0 ------------------------------------------------//
  11667. //check Transaction active
  11668. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11669. {
  11670. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO))
  11671. {
  11672. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11673. {
  11674. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11675. goto end;
  11676. }
  11677. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11678. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11679. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11680. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11682. {
  11683. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11684. goto end;
  11685. }
  11686. else
  11687. {
  11688. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11689. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11690. goto end;
  11691. }
  11692. }
  11693. }//END FOR CHAdeMO_QUANTITY
  11694. for (int index = 0; index < CCS_QUANTITY; index++)
  11695. {
  11696. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS))
  11697. {
  11698. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11699. {
  11700. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11701. goto end;
  11702. }
  11703. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11704. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11705. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11706. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11707. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11708. {
  11709. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11710. goto end;
  11711. }
  11712. else
  11713. {
  11714. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11715. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11716. goto end;
  11717. }
  11718. }
  11719. }//END FOR CCS_QUANTITY
  11720. for (int index = 0; index < GB_QUANTITY; index++)
  11721. {
  11722. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))
  11723. {
  11724. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11725. {
  11726. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11727. goto end;
  11728. }
  11729. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11730. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11731. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11732. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11733. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11734. {
  11735. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11736. goto end;
  11737. }
  11738. else
  11739. {
  11740. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11741. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11742. goto end;
  11743. }
  11744. }
  11745. }// END FOR GB_QUANTITY
  11746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11747. {
  11748. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))
  11749. {
  11750. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11751. {
  11752. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11753. goto end;
  11754. }
  11755. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11756. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11757. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11758. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11760. {
  11761. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11762. goto end;
  11763. }
  11764. else
  11765. {
  11766. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11767. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11768. goto end;
  11769. }
  11770. }
  11771. }// END FOR DO_QUANTITY
  11772. for (int index = 0; index < AC_QUANTITY; index++)
  11773. {
  11774. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC))
  11775. {
  11776. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11777. {
  11778. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11779. goto end;
  11780. }
  11781. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11782. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11783. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11784. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11785. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11786. {
  11787. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11788. goto end;
  11789. }
  11790. else
  11791. {
  11792. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11793. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11794. goto end;
  11795. }
  11796. }
  11797. }//END FOR AC_QUANTITY
  11798. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11799. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11800. {
  11801. //----------------------gunIndex is 0 ------------------------------------------------//
  11802. if(evseId == 0)
  11803. {
  11804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11805. {
  11806. for(int i=0; i < gunTotalNumber; i++)
  11807. {
  11808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11809. {
  11810. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11811. {
  11812. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11813. goto end;
  11814. }
  11815. }//END FOR CHAdeMO_QUANTITY
  11816. for (int index = 0; index < CCS_QUANTITY; index++)
  11817. {
  11818. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11819. {
  11820. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11821. goto end;
  11822. }
  11823. }//END FOR CCS_QUANTITY
  11824. for (int index = 0; index < GB_QUANTITY; index++)
  11825. {
  11826. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11827. {
  11828. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11829. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11830. goto end;
  11831. }
  11832. }// END FOR GB_QUANTITY
  11833. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11834. {
  11835. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11836. {
  11837. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11838. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11839. goto end;
  11840. }
  11841. }// END FOR DO_QUANTITY
  11842. for (int index = 0; index < AC_QUANTITY; index++)
  11843. {
  11844. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11845. {
  11846. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11847. goto end;
  11848. }
  11849. }//END FOR CHAdeMO_QUANTITY
  11850. }// END FOR gunTotalNumber
  11851. }
  11852. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11853. {
  11854. for(int i=0; i < gunTotalNumber; i++)
  11855. {
  11856. for (int index = 0; index < AC_QUANTITY; index++)
  11857. {
  11858. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11859. {
  11860. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11861. goto end;
  11862. }
  11863. }//END FOR CHAdeMO_QUANTITY
  11864. } // END FOR gunTotalNumber
  11865. }
  11866. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11867. goto end;
  11868. }
  11869. //----------------------gunIndex is not 0 ------------------------------------------------//
  11870. //check Transaction active
  11871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11872. {
  11873. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11874. {
  11875. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11876. goto end;
  11877. }
  11878. }//END FOR CHAdeMO_QUANTITY
  11879. for (int index = 0; index < CCS_QUANTITY; index++)
  11880. {
  11881. if ((((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11882. {
  11883. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11884. goto end;
  11885. }
  11886. }//END FOR CCS_QUANTITY
  11887. for (int index = 0; index < GB_QUANTITY; index++)
  11888. {
  11889. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11890. {
  11891. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11892. goto end;
  11893. }
  11894. }// END FOR GB_QUANTITY
  11895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11896. {
  11897. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11898. {
  11899. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11900. goto end;
  11901. }
  11902. }// END FOR DO_QUANTITY
  11903. for (int index = 0; index < AC_QUANTITY; index++)
  11904. {
  11905. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11906. {
  11907. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11908. goto end;
  11909. }
  11910. }//END FOR AC_QUANTITY
  11911. }//END FOR AvailabilityEnumTypeStr[Operative]
  11912. end:
  11913. if((evseId > 0) && (evseId <= gunTotalNumber))
  11914. {
  11915. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].Response_status, "%s", comfirmstr );
  11916. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11917. ShmOCPP20Data->CsMsg.bits[evseId-1].ChangeAvailabilityReq = ON;
  11918. }
  11919. else if(evseId == 0)
  11920. {
  11921. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11922. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11923. {
  11924. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  11925. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  11926. }
  11927. }
  11928. else
  11929. {
  11930. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11931. }
  11932. sendChangeAvailabilityConfirmation(uuid, (evseId==0?evseId:evseId-1));
  11933. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11934. return result;
  11935. }
  11936. int handleClearCacheRequest(char *uuid, char *payload)
  11937. {
  11938. mtrace();
  11939. int result = FAIL;
  11940. char rmFileCmd[100]={0};
  11941. struct stat stats;
  11942. DEBUG_INFO("handleClearCacheRequest...\n");
  11943. stat("/Storage/OCPP", &stats);
  11944. // Check for directory existence
  11945. if (S_ISDIR(stats.st_mode) == 1)
  11946. {}
  11947. else
  11948. {
  11949. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  11950. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  11951. system(rmFileCmd);
  11952. }
  11953. if(DB_cleanLocalCache() != PASS)
  11954. {
  11955. DEBUG_INFO("open AuthorizationCache file failed\n");
  11956. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  11957. }
  11958. else
  11959. {
  11960. DEBUG_INFO("open AuthorizationCache file successful\n");
  11961. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  11962. }
  11963. sendClearCacheConfirmation(uuid);
  11964. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11965. return result;
  11966. }
  11967. int handleClearChargingProfileRequest(char *uuid, char *payload)
  11968. {
  11969. mtrace();
  11970. int result = FAIL;
  11971. int resultRename;
  11972. int evseIdInt, chargingProfileIdInt, stackLevelInt;
  11973. char chargingProfilePurposeStr[26]={0};
  11974. int tempevseIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  11975. char tempchargingProfilePurposeStr[26]={0};
  11976. char sstr[160]={0};
  11977. char str[100]={0};
  11978. int c = 0;
  11979. char *loc;
  11980. char fname[200]={0};
  11981. char comfirmstr[20]={0};
  11982. char word[1600]={0};
  11983. int clearflag = FALSE;
  11984. int chargingProfileIdIsNULL = FALSE;
  11985. int evseIsNULL = FALSE;
  11986. int chargingProfilePurposeIsNULL = FALSE;
  11987. int stackLevelIsNULL = FALSE;
  11988. //int GotoEnd = FALSE;
  11989. FILE *fptr1, *fptr2;
  11990. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  11991. int n_chargingProfile=0;
  11992. int isEmptyFile = FALSE;
  11993. char sLineWord[1600]={0};
  11994. char chargingProfiles[10][100]={0};
  11995. int ChargeProfileCount = 0;
  11996. int ch;
  11997. evseIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11998. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11999. json_object *ClearChargingProfile;
  12000. ClearChargingProfile = json_tokener_parse(payload);
  12001. if(!is_error(ClearChargingProfile))
  12002. {
  12003. // Optional data
  12004. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  12005. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  12006. else
  12007. chargingProfileIdIsNULL = TRUE;
  12008. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  12009. evseIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  12010. else
  12011. evseIsNULL = TRUE;
  12012. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  12013. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  12014. else
  12015. chargingProfilePurposeIsNULL = TRUE;
  12016. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  12017. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  12018. else
  12019. stackLevelIsNULL = TRUE;
  12020. }
  12021. json_object_put(ClearChargingProfile);
  12022. if(evseIsNULL == FALSE)
  12023. {
  12024. switch(evseIdInt)
  12025. {
  12026. case 0:
  12027. if(chargingProfilePurposeIsNULL == TRUE)
  12028. {
  12029. int l = 0;
  12030. strcpy(fname, ChargingStationMaxProfile_JSON);
  12031. if((access(fname,F_OK))!=-1)
  12032. {
  12033. strcpy(chargingProfiles[l], fname);
  12034. l = l + 1;
  12035. }
  12036. strcpy(fname, TxDefaultProfile_0_JSON);
  12037. if((access(fname,F_OK))!=-1)
  12038. {
  12039. strcpy(chargingProfiles[l], fname);
  12040. l = l + 1;
  12041. }
  12042. ChargeProfileCount = l;
  12043. }
  12044. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  12045. {
  12046. strcpy(fname, ChargingStationMaxProfile_JSON);
  12047. if((access(fname,F_OK))!=-1)
  12048. {
  12049. strcpy(chargingProfiles[0], fname);
  12050. ChargeProfileCount = 1;
  12051. }
  12052. }
  12053. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12054. {
  12055. strcpy(fname, TxDefaultProfile_0_JSON);
  12056. if((access(fname,F_OK))!=-1)
  12057. {
  12058. strcpy(chargingProfiles[0], fname);
  12059. ChargeProfileCount = 1;
  12060. }
  12061. }
  12062. break;
  12063. default:
  12064. if(chargingProfilePurposeIsNULL == TRUE)
  12065. {
  12066. int m = 0;
  12067. memset(fname, 0, ARRAY_SIZE(fname));
  12068. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12069. if((access(fname,F_OK))!=-1)
  12070. {
  12071. strcpy(chargingProfiles[m], fname);
  12072. m = m + 1;
  12073. }
  12074. memset(fname, 0, ARRAY_SIZE(fname));
  12075. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12076. if((access(fname,F_OK))!=-1)
  12077. {
  12078. strcpy(chargingProfiles[m], fname);
  12079. m = m + 1;
  12080. }
  12081. ChargeProfileCount = m;
  12082. }
  12083. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12084. {
  12085. //strcpy(fname, TxDefaultProfile_1_JSON);
  12086. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12087. if((access(fname,F_OK))!=-1)
  12088. {
  12089. strcpy(chargingProfiles[0], fname);
  12090. ChargeProfileCount = 1;
  12091. }
  12092. }
  12093. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  12094. {
  12095. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12096. if((access(fname,F_OK))!=-1)
  12097. {
  12098. strcpy(chargingProfiles[0], fname);
  12099. ChargeProfileCount = 1;
  12100. }
  12101. }
  12102. //strcpy(fname, ChargePointMaxProfile_JSON );
  12103. break;
  12104. }
  12105. }
  12106. else // Check all Charging Profiles
  12107. {
  12108. int i = 0;
  12109. char fnametemp[200]={0};
  12110. ChargeProfileCount = 0;
  12111. //Check ChargePointMaxProfile.json exit
  12112. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12113. {
  12114. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  12115. i = i + 1;
  12116. }
  12117. //Check TxDefaultProfile_%d.json
  12118. for(int j=1; j <= gunTotalNumber; j++)
  12119. {
  12120. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12121. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  12122. if((access(fnametemp,F_OK))!=-1)
  12123. {
  12124. strcpy(chargingProfiles[i], fnametemp);
  12125. i = i + 1;
  12126. }
  12127. }
  12128. //Check TxProfile_%d.json
  12129. for(int j=1; j <= gunTotalNumber; j++)
  12130. {
  12131. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12132. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  12133. if((access(fnametemp,F_OK))!=-1)
  12134. {
  12135. strcpy(chargingProfiles[i], fnametemp);
  12136. i = i + 1;
  12137. }
  12138. }
  12139. ChargeProfileCount = i;
  12140. }// End connectorIsNULL is TRUE
  12141. if(ChargeProfileCount == 0)
  12142. {
  12143. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12144. goto end;
  12145. }
  12146. if(evseIsNULL == FALSE && (evseIdInt != 0) && ( (evseIdInt-1) > gunTotalNumber) )
  12147. {
  12148. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12149. goto end;
  12150. }
  12151. if((evseIsNULL == FALSE) && (evseIdInt == 0) )
  12152. {
  12153. memset(str, 0, ARRAY_SIZE(str));
  12154. // clear temp file
  12155. sprintf(str,"rm -f %s",temp);
  12156. system(str);
  12157. for(int k=0; k < ChargeProfileCount; k++)
  12158. {
  12159. memset(str, 0, ARRAY_SIZE(str));
  12160. //clear file in C
  12161. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12162. system(str);
  12163. }
  12164. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12165. goto end;
  12166. }
  12167. else if(evseIsNULL == TRUE)
  12168. {
  12169. for(int k=0; k < ChargeProfileCount; k++)
  12170. {
  12171. fptr1 = fopen(chargingProfiles[k], "r");
  12172. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  12173. //Check Charging Profile Count
  12174. while(fscanf(fptr1, "%s", word) != EOF)
  12175. {
  12176. //DEBUG_INFO("word=%s\n",word);
  12177. if(strstr(word, "id")!= NULL)
  12178. {
  12179. //DEBUG_INFO("test id \n");
  12180. n_chargingProfile = n_chargingProfile + 1;
  12181. //DEBUG_INFO("id Found\n");
  12182. }
  12183. }
  12184. rewind(fptr1);
  12185. //search Charging Profile Element
  12186. //int i= 0;
  12187. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12188. {
  12189. //------------------------tempconnectorIdInt------------------------//
  12190. loc = strstr(sLineWord, "evseId");
  12191. c = 0;
  12192. memset(sstr ,0, sizeof(sstr) );
  12193. while (loc[strlen("evseId")+2+c] != ',')
  12194. {
  12195. sstr[c] = loc[strlen("evseId")+2+c];
  12196. c++;
  12197. }
  12198. sstr[c] = '\0';
  12199. tempevseIdInt = atoi(sstr);
  12200. printf("file's gun number is %d\n", tempevseIdInt);
  12201. //--------------------------id--------------------//
  12202. c = 0;
  12203. loc = strstr(sLineWord, "id");
  12204. memset(sstr ,0, ARRAY_SIZE(sstr));
  12205. while (loc[strlen("id")+2+c] != ',')
  12206. {
  12207. sstr[c] = loc[strlen("id")+2+c];
  12208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12209. c++;
  12210. }
  12211. sstr[c] = '\0';
  12212. tempchargingProfileIdInt = atoi(sstr);
  12213. //stackLevel
  12214. c = 0;
  12215. loc = strstr(sLineWord, "stackLevel");
  12216. memset(sstr ,0, ARRAY_SIZE(sstr));
  12217. while (loc[strlen("stackLevel")+2+c] != ',')
  12218. {
  12219. sstr[c] = loc[strlen("stackLevel")+2+c];
  12220. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12221. c++;
  12222. }
  12223. sstr[c] = '\0';
  12224. tempstackLevelInt = atoi(sstr);
  12225. c = 0;
  12226. loc = strstr(sLineWord, "chargingProfilePurpose");
  12227. memset(sstr ,0, ARRAY_SIZE(sstr));
  12228. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12229. {
  12230. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12231. c++;
  12232. }
  12233. sstr[c] = '\0';
  12234. strcpy(tempchargingProfilePurposeStr, sstr);
  12235. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12236. {
  12237. //------- not write to fptr2-------//
  12238. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12239. //clearflag = TRUE;
  12240. }
  12241. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12242. {
  12243. //------- not write to fptr2-------//
  12244. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12245. }
  12246. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12247. {
  12248. //------- not write to fptr2-------//
  12249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12250. }
  12251. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12252. {
  12253. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12254. }
  12255. else
  12256. {
  12257. fprintf(fptr2, sLineWord);//writing data into file
  12258. }
  12259. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12260. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12261. if(clearflag == TRUE)
  12262. {
  12263. fclose(fptr1);
  12264. fclose(fptr2);
  12265. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12266. system(str);
  12267. // clear temp file
  12268. sprintf(str,"rm -f %s",temp);
  12269. system(str);
  12270. }
  12271. else
  12272. {
  12273. fclose(fptr1);
  12274. fclose(fptr2);
  12275. memset(str, 0, ARRAY_SIZE(str));
  12276. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12277. system(str);
  12278. resultRename = rename(temp, chargingProfiles[k]);
  12279. if(resultRename == 0)
  12280. {
  12281. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12282. }
  12283. else
  12284. {
  12285. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12286. }
  12287. if(comfirmstr[0]== 0)
  12288. {
  12289. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12290. }
  12291. //Check chargingProfile is empty file
  12292. /*------ Read the file ----------------*/
  12293. fptr1=fopen(chargingProfiles[k],"r");
  12294. ch=fgetc(fptr1);
  12295. rewind(fptr1);
  12296. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12297. if(ch!=EOF)
  12298. {
  12299. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12300. {
  12301. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12302. if(sLineWord[0]=='\0')
  12303. {
  12304. isEmptyFile = TRUE;
  12305. break;
  12306. }
  12307. else
  12308. {
  12309. isEmptyFile = FALSE;
  12310. break;
  12311. }
  12312. }
  12313. }
  12314. else
  12315. isEmptyFile = TRUE;
  12316. fclose(fptr1);
  12317. if(isEmptyFile == TRUE)
  12318. {
  12319. memset(str, 0, ARRAY_SIZE(str));
  12320. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12321. system(str);
  12322. }
  12323. }
  12324. }// End of while(int k=0; k < ChargePointCount; k++)
  12325. }
  12326. else if((evseIsNULL == FALSE) && (evseIdInt != 0) )
  12327. {
  12328. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12329. for(int k=0; k < ChargeProfileCount; k++)
  12330. {
  12331. fptr1 = fopen(chargingProfiles[k], "r");
  12332. fptr2 = fopen(temp, "w+");
  12333. //Check Charging Profile Count
  12334. while(fscanf(fptr1, "%s", word) != EOF)
  12335. {
  12336. //DEBUG_INFO("word=%s\n",word);
  12337. if(strstr(word, "id")!= NULL)
  12338. {
  12339. n_chargingProfile = n_chargingProfile + 1;
  12340. }
  12341. }
  12342. rewind(fptr1);
  12343. //search Charging Profile Element
  12344. //int i= 0;
  12345. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12346. {
  12347. //*************************tempevseIdInt*********************************/
  12348. loc = strstr(sLineWord, "evseId");
  12349. c = 0;
  12350. memset(sstr ,0, ARRAY_SIZE(sstr));
  12351. while (loc[strlen("evseId")+2+c] != ',')
  12352. {
  12353. sstr[c] = loc[strlen("evseId")+2+c];
  12354. c++;
  12355. }
  12356. sstr[c] = '\0';
  12357. tempevseIdInt = atoi(sstr);
  12358. //id
  12359. c = 0;
  12360. loc = strstr(sLineWord, "id");
  12361. memset(sstr ,0, ARRAY_SIZE(sstr));
  12362. while (loc[strlen("id")+2+c] != ',')
  12363. {
  12364. sstr[c] = loc[strlen("id")+2+c];
  12365. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12366. c++;
  12367. }
  12368. sstr[c] = '\0';
  12369. tempchargingProfileIdInt = atoi(sstr);
  12370. //stackLevel
  12371. c = 0;
  12372. loc = strstr(sLineWord, "stackLevel");
  12373. memset(sstr ,0, ARRAY_SIZE(sstr));
  12374. while (loc[strlen("stackLevel")+2+c] != ',')
  12375. {
  12376. sstr[c] = loc[strlen("stackLevel")+2+c];
  12377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12378. c++;
  12379. }
  12380. sstr[c] = '\0';
  12381. tempstackLevelInt = atoi(sstr);
  12382. c = 0;
  12383. loc = strstr(sLineWord, "chargingProfilePurpose");
  12384. memset(sstr ,0, ARRAY_SIZE(sstr));
  12385. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12386. {
  12387. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12388. c++;
  12389. }
  12390. sstr[c] = '\0';
  12391. strcpy(tempchargingProfilePurposeStr, sstr);
  12392. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12393. {
  12394. //------- not write to fptr2-------//
  12395. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12396. //clearflag = TRUE;
  12397. }
  12398. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12399. {
  12400. //------- not write to fptr2-------//
  12401. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12402. }
  12403. else if(stackLevelIsNULL == TRUE)
  12404. {
  12405. //Clear Whole File
  12406. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12407. clearflag = TRUE;
  12408. break;
  12409. }
  12410. else
  12411. {
  12412. fprintf(fptr2, sLineWord);//writing data into file
  12413. }
  12414. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12415. }
  12416. if(clearflag == TRUE)
  12417. {
  12418. fclose(fptr1);
  12419. fclose(fptr2);
  12420. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12421. system(str);
  12422. // clear temp file
  12423. sprintf(str,"rm -f %s",temp);
  12424. system(str);
  12425. }
  12426. else
  12427. {
  12428. fclose(fptr1);
  12429. fclose(fptr2);
  12430. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12431. system(str);
  12432. resultRename = rename(temp, chargingProfiles[k]);
  12433. if(resultRename == 0)
  12434. {
  12435. DEBUG_INFO("File ChargingProfile renamed successfully");
  12436. }
  12437. else
  12438. {
  12439. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12440. }
  12441. if(comfirmstr[0]== 0)
  12442. {
  12443. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12444. }
  12445. //Check chargingProfile is empty file
  12446. /*------ Read the file ----------------*/
  12447. fptr1=fopen(chargingProfiles[k],"r");
  12448. ch=fgetc(fptr1);
  12449. rewind(fptr1);
  12450. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12451. if(ch!=EOF)
  12452. {
  12453. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12454. {
  12455. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12456. if(sLineWord[0]=='\0')
  12457. {
  12458. isEmptyFile = TRUE;
  12459. break;
  12460. }
  12461. else
  12462. {
  12463. isEmptyFile = FALSE;
  12464. break;
  12465. }
  12466. }
  12467. }
  12468. else
  12469. isEmptyFile = TRUE;
  12470. fclose(fptr1);
  12471. if(isEmptyFile == TRUE)
  12472. {
  12473. memset(str, 0, ARRAY_SIZE(str));
  12474. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12475. system(str);
  12476. }
  12477. /*------- End of reading ---------------*/
  12478. }
  12479. } // while(int k=0; k < ChargeProfileCount; k++)
  12480. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12481. end:
  12482. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12483. {
  12484. if(evseIdInt == 0)
  12485. {
  12486. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12487. {
  12488. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12489. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12490. }
  12491. }
  12492. else
  12493. {
  12494. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12495. checkCompositeSchedule(evseIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[evseIdInt-1], 0, TRUE);
  12496. }
  12497. }
  12498. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12499. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12500. return result;
  12501. }
  12502. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12503. {
  12504. mtrace();
  12505. int result = FAIL;
  12506. json_object *ClearDisplayMessage;
  12507. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12508. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12509. ClearDisplayMessage = json_tokener_parse(payload);
  12510. if(!is_error(ClearDisplayMessage))
  12511. {
  12512. // Required data
  12513. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12514. {
  12515. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12516. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12517. }
  12518. }
  12519. json_object_put(ClearDisplayMessage);
  12520. sendCostUpdatedConfirmation(uuid);
  12521. return result;
  12522. }
  12523. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12524. {
  12525. mtrace();
  12526. int result = FAIL;
  12527. json_object *ClearVariableMonitorin;
  12528. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12529. ClearVariableMonitorin = json_tokener_parse(payload);
  12530. if(!is_error(ClearVariableMonitorin))
  12531. {
  12532. // Required data
  12533. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12534. {
  12535. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12536. {
  12537. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12538. /*
  12539. * TODO:
  12540. * 1. Check response
  12541. */
  12542. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12543. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12544. }
  12545. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12546. }
  12547. }
  12548. json_object_put(ClearVariableMonitorin);
  12549. return result;
  12550. }
  12551. int handleCostUpdatedRequest(char *uuid, char *payload)
  12552. {
  12553. mtrace();
  12554. int result = FAIL;
  12555. json_object *CostUpdate;
  12556. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12557. CostUpdate = json_tokener_parse(payload);
  12558. if(!is_error(CostUpdate))
  12559. {
  12560. // Required data
  12561. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12562. {
  12563. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12564. }
  12565. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12566. {
  12567. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12568. }
  12569. }
  12570. json_object_put(CostUpdate);
  12571. sendCostUpdatedConfirmation(uuid);
  12572. return result;
  12573. }
  12574. int handleCustomerInformationRequest(char *uuid, char *payload)
  12575. {
  12576. mtrace();
  12577. int result = FAIL;
  12578. json_object *CustomerInformation;
  12579. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12580. CustomerInformation = json_tokener_parse(payload);
  12581. if(!is_error(CustomerInformation))
  12582. {
  12583. // Required data
  12584. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12585. {
  12586. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12587. }
  12588. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12589. {
  12590. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12591. }
  12592. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12593. {
  12594. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12595. }
  12596. // Optional data
  12597. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12598. {
  12599. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12600. {
  12601. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12602. }
  12603. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12604. {
  12605. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12606. }
  12607. }
  12608. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12609. {
  12610. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12611. {
  12612. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12613. }
  12614. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12615. {
  12616. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12617. }
  12618. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12619. {
  12620. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12621. }
  12622. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12623. {
  12624. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12625. }
  12626. }
  12627. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12628. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12629. }
  12630. else
  12631. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12632. json_object_put(CustomerInformation);
  12633. sendCustomerInformationConfirmation(uuid);
  12634. return result;
  12635. }
  12636. void createFirmwareVersionByDataTransfer(void)
  12637. {
  12638. json_object *FirmwareDataTransfer = json_object_new_object();
  12639. // AC & DC model
  12640. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12641. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12642. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12643. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12644. // DC model
  12645. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12646. {
  12647. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12648. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12649. (gunType[3] != GUN_TYPE_UNKNOWN))
  12650. {
  12651. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12652. }
  12653. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12654. {
  12655. // DS DM DW
  12656. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12657. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12658. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12659. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12660. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12661. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12662. }
  12663. else
  12664. {
  12665. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12666. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12667. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12668. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12669. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12670. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12671. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12672. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12673. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12674. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12675. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12676. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12677. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12678. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12679. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12680. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12681. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12682. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12683. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12684. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12685. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12686. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12687. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12688. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12689. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12690. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12691. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12692. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12693. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12694. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12695. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12696. }
  12697. }
  12698. // 4G model
  12699. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12700. {
  12701. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12702. }
  12703. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12704. json_object_put(FirmwareDataTransfer);
  12705. }
  12706. int handleDataTransferRequest(char *uuid, char *payload)
  12707. {
  12708. mtrace();
  12709. int result = PASS;
  12710. DEBUG_INFO("handleDataTransferRequest...\n");
  12711. if((uuid != NULL) && (payload != NULL))
  12712. {
  12713. json_object *DataTransfer;
  12714. DataTransfer = json_tokener_parse(payload);
  12715. if(!is_error(DataTransfer))
  12716. {
  12717. // Required data
  12718. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12719. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12720. // Optional data
  12721. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12722. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12723. if(json_object_object_get(DataTransfer, "data") != NULL)
  12724. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12725. result = PASS;
  12726. }
  12727. json_object_put(DataTransfer);
  12728. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12729. {
  12730. // Send all moudle firmware version on EVSE
  12731. createFirmwareVersionByDataTransfer();
  12732. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12733. }
  12734. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12735. {
  12736. system("/usr/bin/run_tmate_restart.sh &");
  12737. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12738. }
  12739. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12740. {
  12741. json_object *data;
  12742. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12743. if(!is_error(data))
  12744. {
  12745. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  12746. {
  12747. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12748. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12749. if(json_object_object_get(data, "SOC") != NULL)
  12750. {
  12751. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12752. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12753. }
  12754. if(json_object_object_get(data, "Energy") != NULL)
  12755. {
  12756. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12757. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12758. }
  12759. if(json_object_object_get(data, "Duration") != NULL)
  12760. {
  12761. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12762. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12763. }
  12764. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12765. }
  12766. else
  12767. {
  12768. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12769. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12770. }
  12771. }
  12772. else
  12773. {
  12774. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12775. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12776. }
  12777. json_object_put(data);
  12778. }
  12779. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12780. {
  12781. json_object *data;
  12782. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12783. if(!is_error(data))
  12784. {
  12785. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12786. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12787. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12788. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12789. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12790. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12791. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12792. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12793. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12794. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12795. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12796. }
  12797. else
  12798. {
  12799. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12800. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12801. }
  12802. json_object_put(data);
  12803. }
  12804. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12805. {
  12806. json_object *data;
  12807. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12808. if(!is_error(data))
  12809. {
  12810. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12811. if(json_object_object_get(data, "Content_Type") != NULL)
  12812. {
  12813. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  12814. {
  12815. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12816. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12817. {
  12818. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12819. }
  12820. }
  12821. else
  12822. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12823. }
  12824. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12825. }
  12826. else
  12827. {
  12828. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12829. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12830. }
  12831. json_object_put(data);
  12832. }
  12833. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12834. {
  12835. json_object *data;
  12836. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12837. if(!is_error(data))
  12838. {
  12839. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12840. if(json_object_object_get(data, "ConnectorId") != NULL)
  12841. {
  12842. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12843. }
  12844. if(json_object_object_get(data, "Page_Index") != NULL)
  12845. {
  12846. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12847. }
  12848. if(json_object_object_get(data, "Duration") != NULL)
  12849. {
  12850. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12851. }
  12852. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12853. }
  12854. else
  12855. {
  12856. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12857. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12858. }
  12859. json_object_put(data);
  12860. }
  12861. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12862. {
  12863. json_object *data;
  12864. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12865. if(!is_error(data))
  12866. {
  12867. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12868. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12869. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12870. {
  12871. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12872. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12873. else
  12874. {
  12875. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12876. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12877. }
  12878. }
  12879. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12880. {
  12881. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12882. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12883. else
  12884. {
  12885. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12886. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12887. }
  12888. }
  12889. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12890. {
  12891. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12892. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12893. else
  12894. {
  12895. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12896. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12897. }
  12898. }
  12899. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12900. {
  12901. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12902. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12903. else
  12904. {
  12905. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12906. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12907. }
  12908. }
  12909. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12910. {
  12911. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12912. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12913. else
  12914. {
  12915. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12916. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12917. }
  12918. }
  12919. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12920. {
  12921. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  12922. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  12923. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  12924. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  12925. else
  12926. {
  12927. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12928. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12929. }
  12930. }
  12931. if(json_object_object_get(data, "isAuthentication") != NULL)
  12932. {
  12933. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  12934. {
  12935. case 0:
  12936. case 1:
  12937. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  12938. break;
  12939. default:
  12940. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12941. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12942. break;
  12943. }
  12944. }
  12945. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  12946. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12947. }
  12948. else
  12949. {
  12950. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12951. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12952. }
  12953. json_object_put(data);
  12954. }
  12955. else
  12956. {
  12957. // Can not find valid message id
  12958. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12959. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  12960. ,ShmOCPP20Data->DataTransfer[0].vendorId
  12961. ,ShmOCPP20Data->DataTransfer[0].messageId
  12962. ,ShmOCPP20Data->DataTransfer[0].data);
  12963. }
  12964. }
  12965. else
  12966. {
  12967. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12968. result = FAIL;
  12969. }
  12970. sendDataTransferConfirmation(uuid, 0);
  12971. return result;
  12972. }
  12973. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12974. {
  12975. mtrace();
  12976. int result = FAIL;
  12977. json_object *DeleteCertificate;
  12978. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12979. DeleteCertificate = json_tokener_parse(payload);
  12980. if(!is_error(DeleteCertificate))
  12981. {
  12982. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  12983. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  12984. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12985. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12986. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12987. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12988. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12989. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12990. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12991. DEBUG_INFO("serialNumber: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber);
  12992. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  12993. {
  12994. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  12995. }
  12996. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  12997. {
  12998. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  12999. }
  13000. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  13001. {
  13002. ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  13003. }
  13004. char temp[256] = {0};
  13005. char compareData[256] = {0};
  13006. int isMatch = TRUE;
  13007. // Check CentralSystemRootCertificate
  13008. if(access(ROOTCA_CS,F_OK) != -1)
  13009. {
  13010. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  13011. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  13012. for(int i = 0; compareData[i]; i++)
  13013. {
  13014. compareData[i] = tolower(compareData[i]);
  13015. }
  13016. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13017. isMatch = FALSE;
  13018. if(isMatch == TRUE)
  13019. {
  13020. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  13021. for(int i = 0; compareData[i]; i++)
  13022. {
  13023. compareData[i] = tolower(compareData[i]);
  13024. }
  13025. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13026. isMatch = FALSE;
  13027. }
  13028. if(isMatch == TRUE)
  13029. {
  13030. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  13031. for(int i = 0; compareData[i]; i++)
  13032. {
  13033. compareData[i] = tolower(compareData[i]);
  13034. }
  13035. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13036. isMatch = FALSE;
  13037. }
  13038. if(isMatch == TRUE)
  13039. {
  13040. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  13041. sprintf(temp, "rm -f %s", ROOTCA_CS);
  13042. system(temp);
  13043. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13044. goto End;
  13045. }
  13046. }
  13047. // Check ManufacturerRootCertificate
  13048. if(access(ROOTCA_MF,F_OK) != -1)
  13049. {
  13050. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  13051. isMatch = TRUE;
  13052. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  13053. for(int i = 0; compareData[i]; i++)
  13054. {
  13055. compareData[i] = tolower(compareData[i]);
  13056. }
  13057. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13058. isMatch = FALSE;
  13059. if(isMatch == TRUE)
  13060. {
  13061. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  13062. for(int i = 0; compareData[i]; i++)
  13063. {
  13064. compareData[i] = tolower(compareData[i]);
  13065. }
  13066. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13067. isMatch = FALSE;
  13068. }
  13069. if(isMatch == TRUE)
  13070. {
  13071. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  13072. for(int i = 0; compareData[i]; i++)
  13073. {
  13074. compareData[i] = tolower(compareData[i]);
  13075. }
  13076. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13077. isMatch = FALSE;
  13078. }
  13079. if(isMatch == TRUE)
  13080. {
  13081. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  13082. sprintf(temp, "rm -f %s", ROOTCA_MF);
  13083. system(temp);
  13084. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13085. goto End;
  13086. }
  13087. }
  13088. if(access(ROOTCA_V2G,F_OK) != -1)
  13089. {
  13090. DEBUG_INFO("Checking V2GRootCertificate...\n");
  13091. isMatch = TRUE;
  13092. parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, compareData);
  13093. for(int i = 0; compareData[i]; i++)
  13094. {
  13095. compareData[i] = tolower(compareData[i]);
  13096. }
  13097. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13098. isMatch = FALSE;
  13099. if(isMatch == TRUE)
  13100. {
  13101. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, compareData);
  13102. for(int i = 0; compareData[i]; i++)
  13103. {
  13104. compareData[i] = tolower(compareData[i]);
  13105. }
  13106. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13107. isMatch = FALSE;
  13108. }
  13109. if(isMatch == TRUE)
  13110. {
  13111. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  13112. for(int i = 0; compareData[i]; i++)
  13113. {
  13114. compareData[i] = tolower(compareData[i]);
  13115. }
  13116. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13117. isMatch = FALSE;
  13118. }
  13119. if(isMatch == TRUE)
  13120. {
  13121. DEBUG_INFO("Deleting V2GRootCertificate...\n");
  13122. sprintf(temp, "rm -f %s", ROOTCA_V2G);
  13123. system(temp);
  13124. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13125. goto End;
  13126. }
  13127. }
  13128. if(access(ROOTCA_MO,F_OK) != -1)
  13129. {
  13130. DEBUG_INFO("Checking MORootCertificate...\n");
  13131. isMatch = TRUE;
  13132. parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, compareData);
  13133. for(int i = 0; compareData[i]; i++)
  13134. {
  13135. compareData[i] = tolower(compareData[i]);
  13136. }
  13137. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13138. isMatch = FALSE;
  13139. if(isMatch == TRUE)
  13140. {
  13141. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, compareData);
  13142. for(int i = 0; compareData[i]; i++)
  13143. {
  13144. compareData[i] = tolower(compareData[i]);
  13145. }
  13146. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13147. isMatch = FALSE;
  13148. }
  13149. if(isMatch == TRUE)
  13150. {
  13151. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, compareData);
  13152. for(int i = 0; compareData[i]; i++)
  13153. {
  13154. compareData[i] = tolower(compareData[i]);
  13155. }
  13156. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13157. isMatch = FALSE;
  13158. }
  13159. if(isMatch == TRUE)
  13160. {
  13161. DEBUG_INFO("Deleting MORootCertificate...\n");
  13162. sprintf(temp, "rm -f %s", ROOTCA_MO);
  13163. system(temp);
  13164. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13165. goto End;
  13166. }
  13167. }
  13168. // Check certCP
  13169. if(access(CERTIFICATE_CP,F_OK) != -1)
  13170. {
  13171. DEBUG_INFO("Checking certCP...\n");
  13172. isMatch = TRUE;
  13173. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  13174. for(int i = 0; compareData[i]; i++)
  13175. {
  13176. compareData[i] = tolower(compareData[i]);
  13177. }
  13178. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13179. isMatch = FALSE;
  13180. if(isMatch == TRUE)
  13181. {
  13182. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  13183. for(int i = 0; compareData[i]; i++)
  13184. {
  13185. compareData[i] = tolower(compareData[i]);
  13186. }
  13187. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13188. isMatch = FALSE;
  13189. }
  13190. if(isMatch == TRUE)
  13191. {
  13192. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  13193. for(int i = 0; compareData[i]; i++)
  13194. {
  13195. compareData[i] = tolower(compareData[i]);
  13196. }
  13197. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13198. isMatch = FALSE;
  13199. }
  13200. if(isMatch == TRUE)
  13201. {
  13202. DEBUG_INFO("Deleting certCP...\n");
  13203. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  13204. system(temp);
  13205. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13206. goto End;
  13207. }
  13208. }
  13209. }
  13210. else
  13211. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  13212. End:
  13213. json_object_put(DeleteCertificate);
  13214. ShmOCPP20Data->MsMsg.bits.DeleteCertificateReq = 1;
  13215. sendDeleteCertificateConfirmation(uuid);
  13216. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13217. return result;
  13218. }
  13219. int handleGetBaseReportRequest(char *uuid, char *payload)
  13220. {
  13221. mtrace();
  13222. int result = FAIL;
  13223. json_object *GetBaseRepor;
  13224. DEBUG_INFO("handleGetBaseReportRequest...\n");
  13225. GetBaseRepor = json_tokener_parse(payload);
  13226. if(!is_error(GetBaseRepor))
  13227. {
  13228. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  13229. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  13230. // Required data
  13231. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  13232. {
  13233. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  13234. }
  13235. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  13236. {
  13237. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  13238. }
  13239. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  13240. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13241. else
  13242. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13243. }
  13244. else
  13245. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13246. json_object_put(GetBaseRepor);
  13247. sendGetBaseReportConfirmation(uuid);
  13248. return result;
  13249. }
  13250. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  13251. {
  13252. mtrace();
  13253. int result = FAIL;
  13254. int gun_index = -1;
  13255. json_object *GetChargingProfiles;
  13256. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  13257. GetChargingProfiles = json_tokener_parse(payload);
  13258. if(!is_error(GetChargingProfiles))
  13259. {
  13260. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  13261. {
  13262. gun_index = json_object_get_int(json_object_object_get(GetChargingProfiles, "evseId"))>0?json_object_get_int(json_object_object_get(GetChargingProfiles, "evseId"))-1:0;
  13263. }
  13264. if(gun_index >-1)
  13265. {
  13266. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  13267. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  13268. // Required data
  13269. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  13270. {
  13271. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  13272. }
  13273. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  13274. {
  13275. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  13276. {
  13277. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  13278. }
  13279. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  13280. {
  13281. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  13282. }
  13283. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  13284. {
  13285. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  13286. {
  13287. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingLimitSource[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"), idx)));
  13288. }
  13289. }
  13290. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  13291. {
  13292. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  13293. {
  13294. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfileId[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"), idx));
  13295. }
  13296. }
  13297. }
  13298. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  13299. }
  13300. else
  13301. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  13302. }
  13303. json_object_put(GetChargingProfiles);
  13304. sendGetChargingProfilesConfirmation(uuid, gun_index);
  13305. return result;
  13306. }
  13307. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  13308. {
  13309. mtrace();
  13310. int result = FAIL;
  13311. int evseIdInt, durationInt;
  13312. char chargingRateUnitStr[4]={0};
  13313. char comfirmstr[20];
  13314. int confirmPeriods = 0;
  13315. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  13316. json_object *GetCompositeSchedule;
  13317. GetCompositeSchedule = json_tokener_parse(payload);
  13318. if(!is_error(GetCompositeSchedule))
  13319. {
  13320. // Required data
  13321. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  13322. evseIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  13323. else
  13324. evseIdInt = -1;
  13325. if(json_object_object_get(GetCompositeSchedule, "duration"))
  13326. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  13327. else
  13328. durationInt = 86400;
  13329. // Optional data
  13330. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  13331. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  13332. }
  13333. json_object_put(GetCompositeSchedule);
  13334. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  13335. if((evseIdInt == 0) ||
  13336. ((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber)))
  13337. {
  13338. int gun_index = (evseIdInt==0?0:evseIdInt-1);
  13339. struct ChargingProfileType tmpProfile[1];
  13340. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  13341. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  13342. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  13343. {
  13344. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  13345. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  13346. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  13347. }
  13348. else
  13349. {
  13350. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  13351. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  13352. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  13353. }
  13354. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13355. {
  13356. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  13357. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  13358. }
  13359. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  13360. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  13361. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13362. {
  13363. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  13364. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  13365. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  13366. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  13367. (idx<(ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod)-1)?(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx+1].startPeriod==0):TRUE))
  13368. {
  13369. confirmPeriods = idx;
  13370. break;
  13371. }
  13372. }
  13373. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  13374. {
  13375. confirmPeriods += 1;
  13376. }
  13377. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13378. }
  13379. else
  13380. {
  13381. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  13382. }
  13383. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, evseIdInt, confirmPeriods);
  13384. return result;
  13385. }
  13386. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  13387. {
  13388. mtrace();
  13389. int result = FAIL;
  13390. json_object *GetDisplayMessages;
  13391. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  13392. GetDisplayMessages = json_tokener_parse(payload);
  13393. if(!is_error(GetDisplayMessages))
  13394. {
  13395. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  13396. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  13397. // Required data
  13398. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  13399. {
  13400. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  13401. }
  13402. // Optional data
  13403. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  13404. {
  13405. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  13406. }
  13407. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  13408. {
  13409. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  13410. }
  13411. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  13412. {
  13413. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  13414. {
  13415. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  13416. }
  13417. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  13418. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  13419. }
  13420. else
  13421. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  13422. }
  13423. json_object_put(GetDisplayMessages);
  13424. return result;
  13425. }
  13426. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13427. {
  13428. mtrace();
  13429. int result = FAIL;
  13430. int certCnt = 0;
  13431. unsigned char foundCertCnt = 0;
  13432. json_object *GetInstalledCertificateIds;
  13433. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13434. GetInstalledCertificateIds = json_tokener_parse(payload);
  13435. if(!is_error(GetInstalledCertificateIds))
  13436. {
  13437. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13438. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13439. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13440. // Optional data
  13441. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13442. {
  13443. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13444. {
  13445. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13446. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13447. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "Accepted");
  13448. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  13449. // Check CSMSRootCertificate
  13450. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "CSMSRootCertificate")!= NULL)
  13451. {
  13452. if(access(ROOTCA_CS,F_OK) != -1)
  13453. {
  13454. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "CSMSRootCertificate");
  13455. char parseData[512] = {0};
  13456. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13457. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13458. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  13459. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13460. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13461. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13462. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13463. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13464. certCnt++;
  13465. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13466. }
  13467. else
  13468. {
  13469. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  13470. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13471. }
  13472. }
  13473. // Check ManufacturerRootCertificate
  13474. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "ManufacturerRootCertificate") != NULL)
  13475. {
  13476. if(access(ROOTCA_MF,F_OK) != -1)
  13477. {
  13478. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "ManufacturerRootCertificate");
  13479. char parseData[512] = {0};
  13480. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13481. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13482. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  13483. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13484. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13485. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13486. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13487. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13488. certCnt++;
  13489. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13490. }
  13491. else
  13492. {
  13493. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  13494. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13495. }
  13496. }
  13497. // Check MORootCertificate
  13498. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "MORootCertificate") != NULL)
  13499. {
  13500. if(access(ROOTCA_MO,F_OK) != -1)
  13501. {
  13502. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "MORootCertificate");
  13503. char parseData[512] = {0};
  13504. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13505. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13506. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, parseData) == PASS)
  13507. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13508. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13509. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13510. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13511. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13512. certCnt++;
  13513. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13514. }
  13515. else
  13516. {
  13517. DEBUG_INFO(">>> No MORootCertificate was found.\n");
  13518. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13519. }
  13520. }
  13521. // Check V2GRootCertificate
  13522. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GRootCertificate") != NULL)
  13523. {
  13524. if(access(ROOTCA_V2G,F_OK) != -1)
  13525. {
  13526. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GRootCertificate");
  13527. char parseData[512] = {0};
  13528. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13529. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13530. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13531. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13532. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13533. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13534. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13535. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13536. certCnt++;
  13537. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13538. }
  13539. else
  13540. {
  13541. DEBUG_INFO(">>> No V2GRootCertificate was found.\n");
  13542. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13543. }
  13544. }
  13545. // Check V2GCertificateChain
  13546. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GCertificateChain") != NULL)
  13547. {
  13548. if(access(CERTIFICATE_V2G,F_OK) != -1)
  13549. {
  13550. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GCertificateChain");
  13551. char parseData[512] = {0};
  13552. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13553. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13554. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13555. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13556. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13557. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13558. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13559. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13560. certCnt++;
  13561. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13562. }
  13563. else
  13564. {
  13565. DEBUG_INFO(">>> No V2GCertificateChain was found.\n");
  13566. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13567. }
  13568. }
  13569. else
  13570. {
  13571. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13572. }
  13573. }
  13574. }
  13575. else
  13576. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13577. }
  13578. json_object_put(GetInstalledCertificateIds);
  13579. sendGetInstalledCertificateIdsConfirmation(uuid, foundCertCnt);
  13580. return result;
  13581. }
  13582. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13583. {
  13584. mtrace();
  13585. int result = FAIL;
  13586. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13587. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13588. {
  13589. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13590. localversion = 0;
  13591. }
  13592. else
  13593. {
  13594. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13595. localversion = 0;
  13596. DB_getListVerion();
  13597. }
  13598. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13599. sendGetLocalListVersionConfirmation(uuid);
  13600. return result;
  13601. }
  13602. static char fnamePlusPath[100]={0};
  13603. static char fnamePWithNoPath[60]={0};
  13604. void checkUploadLog(void)
  13605. {
  13606. FILE *fp;
  13607. /* Open the command for reading. */
  13608. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13609. if (fp == NULL) {
  13610. printf("Failed to run command\n" );
  13611. exit(1);
  13612. }
  13613. int ftppathlen = 0;
  13614. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13615. int i = 0;
  13616. /* Read the output a line at a time - output it. */
  13617. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13618. if(i==0)
  13619. {
  13620. ftppathlen = strlen(fnamePlusPath);
  13621. printf("%s\n", fnamePlusPath);
  13622. fnamePlusPath[ftppathlen]='\0';
  13623. break;
  13624. }
  13625. i= i+1;
  13626. }
  13627. /* close */
  13628. pclose(fp);
  13629. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13630. {
  13631. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13632. {
  13633. fnamePlusPath[k]='\0';
  13634. }
  13635. }
  13636. i=1;
  13637. //char fname[60]={0};
  13638. while(i < ftppathlen)
  13639. {
  13640. int len=ftppathlen-i;
  13641. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13642. {
  13643. printf("compare '/' all right\n");
  13644. break;
  13645. }
  13646. i=i+1;
  13647. }
  13648. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13649. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13650. fnamePWithNoPath[i+1] = '\0';
  13651. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13652. {
  13653. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13654. {
  13655. fnamePWithNoPath[j]='\0';
  13656. }
  13657. }
  13658. FILE* fp1 = fopen(fnamePlusPath, "r");
  13659. if (fp1)
  13660. {
  13661. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13662. // file exists
  13663. fclose(fp1);
  13664. }
  13665. else
  13666. {
  13667. // file doesn't exist
  13668. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13669. }
  13670. }
  13671. void* GetLogProcess(void* data)
  13672. {
  13673. th_GetLog = pthread_self();
  13674. pthread_detach(pthread_self());
  13675. mtrace();
  13676. int requestId, retriesInt=0, retryIntervalInt=0;
  13677. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13678. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  13679. int port=0;
  13680. int isSuccess = FALSE;
  13681. char ftpbuf[1024]={0};
  13682. char cmdBuf[2048];
  13683. struct tm *tmNow;
  13684. time_t CurrentTime;
  13685. struct tm tmStart;
  13686. struct tm tmStop;
  13687. CurrentTime = time(NULL);
  13688. tmNow=localtime(&CurrentTime);
  13689. uint16_t targetYear, targetMonth;
  13690. json_object *GetLog;
  13691. DEBUG_INFO("GetGetProcess...\n");
  13692. GetLog = json_tokener_parse(data);
  13693. if(!is_error(GetLog))
  13694. {
  13695. // Required data
  13696. if(json_object_object_get(GetLog, "requestId") != NULL)
  13697. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13698. if(json_object_object_get(GetLog, "logType") != NULL)
  13699. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13700. if(json_object_object_get(GetLog, "log") != NULL)
  13701. {
  13702. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13703. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13704. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13705. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13706. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13707. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13708. }
  13709. // Optional data
  13710. if(json_object_object_get(GetLog, "retries") != NULL)
  13711. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13712. else
  13713. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13714. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13715. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13716. else
  13717. retryIntervalInt = 30;
  13718. }
  13719. json_object_put(GetLog);
  13720. ShmOCPP20Data->GetLog.requestId = requestId;
  13721. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13722. {
  13723. /*
  13724. * TODO:
  13725. * 1. Pack security log
  13726. */
  13727. }
  13728. else
  13729. {
  13730. // Pack log to compress file
  13731. if((sscanf((char*)oldestTimestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  13732. (sscanf((char*)latestTimestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  13733. {
  13734. // Pack system log
  13735. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13736. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13737. targetYear = tmStart.tm_year;
  13738. targetMonth = tmStart.tm_mon;
  13739. do
  13740. {
  13741. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13742. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13743. if(targetMonth+1>=13)
  13744. {
  13745. targetYear += 1;
  13746. targetMonth = 1;
  13747. }
  13748. else
  13749. {
  13750. targetMonth += 1;
  13751. }
  13752. }while((targetYear < (tmNow->tm_year+1900)) ||
  13753. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13754. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13755. system(cmdBuf);
  13756. // Pack charging & event log
  13757. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13758. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13759. targetYear = tmStart.tm_year;
  13760. targetMonth = tmStart.tm_mon;
  13761. do
  13762. {
  13763. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13764. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  13765. if(targetMonth+1>=13)
  13766. {
  13767. targetYear += 1;
  13768. targetMonth = 1;
  13769. }
  13770. else
  13771. {
  13772. targetMonth += 1;
  13773. }
  13774. }while((targetYear < (tmNow->tm_year+1900)) ||
  13775. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13776. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13777. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13778. system(cmdBuf);
  13779. // Combine log file
  13780. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13781. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13782. }
  13783. else
  13784. {
  13785. system("exec /root/logPackTools 'log' 6");
  13786. }
  13787. }
  13788. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13789. system(cmdBuf);
  13790. checkUploadLog();
  13791. //****************location*******************/
  13792. if(strcmp(remoteLocation,"")==0)
  13793. {
  13794. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13795. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13796. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13797. goto end;
  13798. }
  13799. memset(protocol, 0, ARRAY_SIZE(protocol));
  13800. memset(user, 0, ARRAY_SIZE(user) );
  13801. memset(password, 0, ARRAY_SIZE(password));
  13802. memset(host, 0, ARRAY_SIZE(host));
  13803. memset(path, 0, ARRAY_SIZE(path));
  13804. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13805. memset(host1, 0, ARRAY_SIZE(host1));
  13806. memset(path1, 0, ARRAY_SIZE(path1));
  13807. /*location: ftp://user:password@host:port/path*/
  13808. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13809. if((access(fnamePlusPath,F_OK))!=-1)
  13810. {
  13811. DEBUG_INFO("fnamePlusPath exist.\n");
  13812. }
  13813. else
  13814. {
  13815. DEBUG_INFO("fnamePlusPath not exist!\n");
  13816. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13817. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13818. goto end;
  13819. }
  13820. if(strchr(remoteLocation,'@')==NULL)
  13821. {
  13822. sscanf(remoteLocation,
  13823. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13824. protocol, host, &port, path);
  13825. strcpy(user,"anonymous");
  13826. strcpy(password,"");
  13827. }
  13828. else
  13829. {
  13830. //DEBUG_INFO("pch=%s\n", pch);
  13831. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13832. protocol, user, password, host, &port, path);
  13833. }
  13834. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13835. {
  13836. DEBUG_INFO("protocol is not ftp/http ! \n");
  13837. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13838. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13839. goto end;
  13840. }
  13841. if(strncmp(remoteLocation,"http", 4) == 0)
  13842. {
  13843. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13844. sprintf(ftppath,"/%s", path);
  13845. do
  13846. {
  13847. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13848. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13849. sleep(3);
  13850. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13851. if(!isSuccess)
  13852. {
  13853. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13854. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13855. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13856. sleep(retryIntervalInt);
  13857. }
  13858. else
  13859. {
  13860. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13861. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13862. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13863. }
  13864. retriesInt--;
  13865. }while((isSuccess == 0)&&(retriesInt >= 0));
  13866. }
  13867. else
  13868. {
  13869. sscanf(host,"%[^/]%s",host1, path1);
  13870. if(strlen(path) > 0)
  13871. sprintf(ftppath,"/%s", path);
  13872. else
  13873. sprintf(ftppath,"/%s", path1);
  13874. int ftppathlen=strlen(ftppath);
  13875. int i=1;
  13876. char filenametemp[50];
  13877. while(i < ftppathlen)
  13878. {
  13879. int len=ftppathlen-i;
  13880. if(ftppath[len]== 47) // '/' ascll code: 47
  13881. {
  13882. DEBUG_INFO("find '/' all right\n");
  13883. break;
  13884. }
  13885. i=i+1;
  13886. }
  13887. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13888. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13889. filenametemp[i+1] = 0;
  13890. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13891. if(port == 0)
  13892. port = 21;
  13893. do
  13894. {
  13895. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13896. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13897. sleep(3);
  13898. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13899. if(!isSuccess)
  13900. {
  13901. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13902. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13903. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13904. sleep(retryIntervalInt);
  13905. }
  13906. else
  13907. {
  13908. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13909. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13910. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13911. }
  13912. retriesInt--;
  13913. }while((!isSuccess)&&(retriesInt >= 0));
  13914. }
  13915. end:
  13916. system("rm -f /mnt/*");
  13917. sleep(5);
  13918. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13919. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13920. interLock.isGetLogGoing = OFF;
  13921. pthread_exit(NULL);
  13922. }
  13923. int handleGetLogRequest(char *uuid, char *payload)
  13924. {
  13925. mtrace();
  13926. int result = FAIL;
  13927. char fName[258];
  13928. time_t CurrentTime;
  13929. struct tm *tm;
  13930. pthread_t th_Status;
  13931. DEBUG_INFO("handleGetLogRequest...\n");
  13932. CurrentTime = time(NULL);
  13933. tm = localtime(&CurrentTime);
  13934. sprintf(fName ,"%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  13935. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  13936. if(interLock.isGetLogGoing)
  13937. {
  13938. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  13939. isCancelUploadLog = TRUE;
  13940. pthread_cancel(th_GetLog);
  13941. interLock.isGetLogGoing = OFF;
  13942. sleep(1);
  13943. isCancelUploadLog = OFF;
  13944. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  13945. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13946. sleep(1);
  13947. }
  13948. else
  13949. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  13950. sendGetLogConfirmation(uuid);
  13951. if(!interLock.isGetLogGoing)
  13952. {
  13953. interLock.isGetLogGoing = ON;
  13954. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  13955. sleep(1);
  13956. }
  13957. else
  13958. {
  13959. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  13960. }
  13961. return result;
  13962. }
  13963. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  13964. {
  13965. mtrace();
  13966. int result = FAIL;
  13967. json_object *GetMonitoringReport;
  13968. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  13969. GetMonitoringReport = json_tokener_parse(payload);
  13970. if(!is_error(GetMonitoringReport))
  13971. {
  13972. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  13973. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  13974. // Required data
  13975. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  13976. {
  13977. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  13978. }
  13979. // Optional data
  13980. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  13981. {
  13982. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  13983. }
  13984. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  13985. {
  13986. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  13987. {
  13988. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  13989. {
  13990. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  13991. {
  13992. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  13993. {
  13994. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name")));
  13995. }
  13996. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13997. {
  13998. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance")));
  13999. }
  14000. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14001. {
  14002. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse"), "id") != NULL)
  14003. {
  14004. ShmOCPP20Data->GetMonitoringReport.componentVariable[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance"), "id"));
  14005. }
  14006. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse"), "connectorId") != NULL)
  14007. {
  14008. ShmOCPP20Data->GetMonitoringReport.componentVariable[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance"), "connectorId"));
  14009. }
  14010. }
  14011. }
  14012. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  14013. {
  14014. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14015. {
  14016. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name")));
  14017. }
  14018. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14019. {
  14020. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance")));
  14021. }
  14022. }
  14023. }
  14024. }
  14025. }
  14026. }
  14027. json_object_put(GetMonitoringReport);
  14028. /*
  14029. * TODO:
  14030. * 1. Response result
  14031. */
  14032. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14033. sendGetMonitoringReportConfirmation(uuid);
  14034. return result;
  14035. }
  14036. int handleGetReportRequest(char *uuid, char *payload)
  14037. {
  14038. mtrace();
  14039. int result = FAIL;
  14040. json_object *GetReport;
  14041. DEBUG_INFO("handleGetReportRequest...\n");
  14042. GetReport = json_tokener_parse(payload);
  14043. if(!is_error(GetReport))
  14044. {
  14045. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  14046. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  14047. // Required data
  14048. if(json_object_object_get(GetReport, "requestId") != NULL)
  14049. {
  14050. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  14051. }
  14052. // Optional data
  14053. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  14054. {
  14055. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  14056. }
  14057. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  14058. {
  14059. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  14060. {
  14061. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  14062. {
  14063. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  14064. {
  14065. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  14066. {
  14067. sprintf((char*)ShmOCPP20Data->GetReport.componentVariable[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name")));
  14068. }
  14069. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14070. {
  14071. sprintf((char*)ShmOCPP20Data->GetReport.componentVariable[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance")));
  14072. }
  14073. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14074. {
  14075. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "id") != NULL)
  14076. {
  14077. ShmOCPP20Data->GetReport.componentVariable[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "id"));
  14078. }
  14079. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "connectorId") != NULL)
  14080. {
  14081. ShmOCPP20Data->GetReport.componentVariable[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "connectorId"));
  14082. }
  14083. }
  14084. }
  14085. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  14086. {
  14087. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14088. {
  14089. sprintf((char*)ShmOCPP20Data->GetReport.componentVariable[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name")));
  14090. }
  14091. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14092. {
  14093. sprintf((char*)ShmOCPP20Data->GetReport.componentVariable[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance")));
  14094. }
  14095. }
  14096. }
  14097. }
  14098. }
  14099. }
  14100. json_object_put(GetReport);
  14101. /*
  14102. * TODO:
  14103. * 1. Response result
  14104. */
  14105. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14106. sendGetReportConfirmation(uuid);
  14107. return result;
  14108. }
  14109. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  14110. {
  14111. mtrace();
  14112. int result = FAIL;
  14113. uint8_t tempIndex;
  14114. json_object *GetTransactionStatus;
  14115. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  14116. GetTransactionStatus = json_tokener_parse(payload);
  14117. if(!is_error(GetTransactionStatus))
  14118. {
  14119. memset(&ShmOCPP20Data->GetTransactionStatus, 0, sizeof(struct GetTransactionStatus_20));
  14120. memcpy(&ShmOCPP20Data->GetTransactionStatus.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus.guid));
  14121. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = FALSE;
  14122. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = FALSE;
  14123. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  14124. {
  14125. sprintf((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  14126. }
  14127. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14128. {
  14129. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14130. {
  14131. if(strcmp((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId)==0)
  14132. {
  14133. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14134. {
  14135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14136. tempIndex = ((gun_index==2) ? 1: 0);
  14137. else
  14138. tempIndex = gun_index;
  14139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14140. {
  14141. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) &&
  14142. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14143. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14144. }
  14145. }
  14146. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14147. {
  14148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14149. tempIndex = ((gun_index==2) ? 1: 0);
  14150. else
  14151. tempIndex = gun_index;
  14152. for (int index = 0; index < CCS_QUANTITY; index++)
  14153. {
  14154. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) &&
  14155. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14156. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14157. }
  14158. }
  14159. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14160. {
  14161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14162. tempIndex = ((gun_index==2) ? 1: 0);
  14163. else
  14164. tempIndex = gun_index;
  14165. for (int index = 0; index < GB_QUANTITY; index++)
  14166. {
  14167. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) &&
  14168. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14169. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14170. }
  14171. }
  14172. else if(gunType[gun_index] == GUN_TYPE_DO)
  14173. {
  14174. tempIndex = gun_index;
  14175. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14176. {
  14177. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) &&
  14178. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)))
  14179. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14180. }
  14181. }
  14182. else
  14183. {
  14184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14185. tempIndex = 2;
  14186. else
  14187. tempIndex = gun_index;
  14188. for (int index = 0; index < AC_QUANTITY; index++)
  14189. {
  14190. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) &&
  14191. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14192. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14193. }
  14194. }
  14195. }
  14196. }
  14197. }
  14198. char rmFileCmd[100]={0};
  14199. int TransactionQueueNum = 0;
  14200. struct stat stats;
  14201. stat("/Storage/OCPP", &stats);
  14202. // Check for directory existence
  14203. if (S_ISDIR(stats.st_mode) == 1)
  14204. {
  14205. //DEBUG_INFO("\n OCPP directory exist \n");
  14206. }
  14207. else
  14208. {
  14209. //DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  14210. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  14211. system(rmFileCmd);
  14212. }
  14213. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  14214. if((access("/Storage/OCPP/TransactionRelatedQueue20",F_OK))!=-1)
  14215. {
  14216. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14217. }
  14218. else
  14219. {
  14220. FILE *fp = fopen("/Storage/OCPP/TransactionRelatedQueue20", "r");
  14221. char line[QUEUE_MESSAGE_LENGTH]={0};
  14222. if (fp == NULL) {
  14223. DEBUG_INFO("cannot open file TransactionRelatedQueue!");
  14224. }
  14225. TransactionQueueNum = 0; // the number of packets in queue
  14226. while(fgets(line, sizeof line, fp) != NULL) {
  14227. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14228. {
  14229. if(strstr(line, (char*)ShmOCPP20Data->GetTransactionStatus.transactionId) != NULL)
  14230. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14231. }
  14232. TransactionQueueNum += 1; //the number of packets in queue
  14233. }
  14234. fclose(fp);
  14235. }
  14236. if((strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId) == 0) && (TransactionQueueNum>0))
  14237. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14238. }
  14239. json_object_put(GetTransactionStatus);
  14240. sendGetTransactionStatusConfirmation(uuid);
  14241. return result;
  14242. }
  14243. int handleGetVariablesRequest(char *uuid, char *payload)
  14244. {
  14245. mtrace();
  14246. int result = FAIL;
  14247. int isUnknownComponent = TRUE;
  14248. json_object *GetVariables;
  14249. DEBUG_INFO("handleGetVariablesRequest...\n");
  14250. GetVariables = json_tokener_parse(payload);
  14251. if(!is_error(GetVariables))
  14252. {
  14253. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  14254. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  14255. // Required data
  14256. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  14257. {
  14258. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  14259. {
  14260. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  14261. {
  14262. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  14263. {
  14264. sprintf((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType")));
  14265. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  14266. }
  14267. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  14268. {
  14269. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  14270. }*/
  14271. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  14272. {
  14273. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  14274. {
  14275. sprintf((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name")));
  14276. }
  14277. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  14278. {
  14279. sprintf((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance")));
  14280. }
  14281. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  14282. {
  14283. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse"), "id") != NULL)
  14284. {
  14285. ShmOCPP20Data->GetVariables.getVariableData[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance"), "id"));
  14286. }
  14287. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse"), "connectorId") != NULL)
  14288. {
  14289. ShmOCPP20Data->GetVariables.getVariableData[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance"), "connectorId"));
  14290. }
  14291. }
  14292. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  14293. }
  14294. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  14295. {
  14296. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  14297. {
  14298. sprintf((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name")));
  14299. }
  14300. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  14301. {
  14302. sprintf((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance")));
  14303. }
  14304. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  14305. }
  14306. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14307. {
  14308. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  14309. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  14310. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  14311. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  14312. {
  14313. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  14314. isUnknownComponent = FALSE;
  14315. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  14316. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  14317. {
  14318. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  14319. break;
  14320. }
  14321. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14322. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  14323. {
  14324. struct sysinfo s_info;
  14325. int error = sysinfo(&s_info);
  14326. if(error != 0)
  14327. {
  14328. DEBUG_WARN("System uptime get error: %d\n", error);
  14329. }
  14330. else
  14331. {
  14332. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  14333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  14334. }
  14335. }
  14336. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14337. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  14338. {
  14339. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  14340. }
  14341. else
  14342. {
  14343. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14344. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  14345. }
  14346. break;
  14347. }
  14348. else
  14349. {
  14350. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  14351. {
  14352. isUnknownComponent = FALSE;
  14353. }
  14354. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  14355. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  14356. }
  14357. }
  14358. if(isUnknownComponent == TRUE)
  14359. {
  14360. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  14361. }
  14362. }
  14363. }
  14364. }
  14365. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  14366. }
  14367. json_object_put(GetVariables);
  14368. return result;
  14369. }
  14370. int handleInstallCertificateRequest(char *uuid, char *payload)
  14371. {
  14372. mtrace();
  14373. int result = PASS;
  14374. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14375. json_object *InstallCertificate;
  14376. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14377. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14378. InstallCertificate = json_tokener_parse(payload);
  14379. if(!is_error(InstallCertificate))
  14380. {
  14381. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  14382. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  14383. // Required data
  14384. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  14385. {
  14386. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14387. }
  14388. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  14389. {
  14390. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14391. }
  14392. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificateType);
  14393. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificate);
  14394. char temp[1024];
  14395. FILE *fp = fopen(tempCert, "w");
  14396. fprintf(fp, "%s", ShmOCPP20Data->InstallCertificate.certificate);
  14397. fclose(fp);
  14398. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14399. char strExpDate[30];
  14400. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14401. fp = popen(temp, "r");
  14402. if(fp)
  14403. {
  14404. while(fgets(temp, sizeof(temp), fp) != NULL)
  14405. {
  14406. if(strstr(temp, "notAfter=") != NULL)
  14407. {
  14408. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14409. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14410. break;
  14411. }
  14412. }
  14413. }
  14414. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14415. struct tm tmExpDate;
  14416. struct timeb tbExpDate;
  14417. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14418. tbExpDate.time = mktime(&tmExpDate);
  14419. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14420. {
  14421. DEBUG_INFO("The enddate is already expired...\n");
  14422. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14423. goto End;
  14424. }
  14425. // Verify certificate with rootCA
  14426. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14427. fp = popen(temp, "r");
  14428. if(fp)
  14429. {
  14430. while(fgets(temp, sizeof(temp), fp) != NULL)
  14431. {
  14432. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14433. {
  14434. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14435. break;
  14436. }
  14437. else
  14438. {
  14439. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14440. }
  14441. }
  14442. }
  14443. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14444. {
  14445. //=====================================================
  14446. // Verify if the certificate is valid or not. (OCSP?)
  14447. //=====================================================
  14448. /*
  14449. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14450. // Get ocsp url
  14451. char ocspUrl[512];
  14452. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14453. fp = popen(temp, "r");
  14454. if(fp)
  14455. {
  14456. while(fgets(temp, sizeof(temp), fp) != NULL)
  14457. {
  14458. if(strstr(temp, "://") != NULL)
  14459. {
  14460. strcpy(ocspUrl, temp);
  14461. break;
  14462. }
  14463. }
  14464. }
  14465. // Get certificate chain for issuer
  14466. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14467. *
  14468. // Execute OCSP
  14469. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14470. fp = popen(temp, "r");
  14471. if(fp)
  14472. {
  14473. while(fgets(temp, sizeof(temp), fp) != NULL)
  14474. {
  14475. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14476. {
  14477. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14478. break;
  14479. }
  14480. }
  14481. }
  14482. system("rm -f /Storage/OCPP/tempChain.pem");
  14483. pclose(fp);
  14484. */
  14485. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14486. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14487. {
  14488. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14489. goto End;
  14490. }
  14491. else
  14492. DEBUG_INFO("OCSP verifying...PASS.\n");
  14493. }
  14494. else
  14495. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14496. }
  14497. json_object_put(InstallCertificate);
  14498. End:
  14499. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") == 0)
  14500. {
  14501. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]) == 0)
  14502. {
  14503. if(access(ROOTCA_CS,F_OK) != -1)
  14504. {
  14505. DEBUG_INFO("Existed CSMSRootCertificate is found. Replacing...\n");
  14506. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14507. rename(tempCert, ROOTCA_CS);
  14508. }
  14509. else
  14510. {
  14511. DEBUG_INFO("No existed CSMSRootCertificate Creating...\n");
  14512. rename(tempCert, ROOTCA_CS);
  14513. }
  14514. }
  14515. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]) == 0)
  14516. {
  14517. if(access(ROOTCA_MF,F_OK) != -1)
  14518. {
  14519. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14520. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14521. rename(tempCert, ROOTCA_MF);
  14522. }
  14523. else
  14524. {
  14525. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14526. rename(tempCert, ROOTCA_MF);
  14527. }
  14528. }
  14529. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]) == 0)
  14530. {
  14531. if(access(ROOTCA_V2G,F_OK) != -1)
  14532. {
  14533. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14534. rename(ROOTCA_V2G, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14535. rename(tempCert, ROOTCA_V2G);
  14536. }
  14537. else
  14538. {
  14539. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14540. rename(tempCert, ROOTCA_V2G);
  14541. }
  14542. }
  14543. ShmOCPP20Data->MsMsg.bits.InstallCertificateReq = 1;
  14544. }
  14545. sendInstallCertificateConfirmation(uuid);
  14546. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14547. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14548. {
  14549. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14550. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  14551. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14552. }
  14553. return result;
  14554. }
  14555. int handlePublishFirmwareRequest(char *uuid, char *payload)
  14556. {
  14557. mtrace();
  14558. int result = FAIL;
  14559. json_object *PublishFirmware;
  14560. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  14561. PublishFirmware = json_tokener_parse(payload);
  14562. if(!is_error(PublishFirmware))
  14563. {
  14564. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  14565. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  14566. // Required data
  14567. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  14568. {
  14569. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  14570. }
  14571. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  14572. {
  14573. sprintf((char*)ShmOCPP20Data->PublishFirmware.checksum, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  14574. }
  14575. // Optional data
  14576. if(json_object_object_get(PublishFirmware, "location") != NULL)
  14577. {
  14578. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  14579. }
  14580. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  14581. {
  14582. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  14583. }
  14584. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  14585. {
  14586. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  14587. }
  14588. }
  14589. json_object_put(PublishFirmware);
  14590. /*
  14591. * TODO:
  14592. * 1. Publish firmware preocess and response
  14593. */
  14594. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  14595. sendPublishFirmwareConfirmation(uuid);
  14596. return result;
  14597. }
  14598. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  14599. {
  14600. mtrace();
  14601. int result = FAIL;
  14602. int8_t evseId = -1;
  14603. uint8_t tempIndex;
  14604. uint8_t isOverConnectorMax = FALSE;
  14605. uint8_t isPeriodOverMax = FALSE;
  14606. uint8_t isTxProfile = TRUE;
  14607. uint8_t isAllowStart = TRUE;
  14608. uint8_t filename[128]={0};
  14609. char cmdBuf[128];
  14610. FILE *filePtr;
  14611. json_object *RemoteStartTransaction;
  14612. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  14613. RemoteStartTransaction = json_tokener_parse(payload);
  14614. if(!is_error(RemoteStartTransaction))
  14615. {
  14616. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  14617. {
  14618. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  14619. {
  14620. evseId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  14621. }
  14622. else
  14623. {
  14624. isOverConnectorMax = TRUE;
  14625. DEBUG_WARN("Evse id shall not equal 0 and should be less than gunTotalNumber.\n");
  14626. }
  14627. }
  14628. else
  14629. {
  14630. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  14631. {
  14632. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  14633. {
  14634. evseId = (idx+1);
  14635. DEBUG_INFO("Remote start without evseId but detect connector of evse-%02d connected ready to start.\n", evseId);
  14636. break;
  14637. }
  14638. }
  14639. }
  14640. if(isOverConnectorMax == FALSE)
  14641. {
  14642. if(evseId > 0)
  14643. {
  14644. DEBUG_INFO("Requested evseId id: %d\n", evseId);
  14645. memset(&ShmOCPP20Data->RequestStartTransaction[evseId-1], 0, sizeof(struct RequestStartTransaction_20));
  14646. memcpy(&ShmOCPP20Data->RequestStartTransaction[evseId-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[evseId-1].guid));
  14647. // Required data
  14648. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14649. {
  14650. ShmOCPP20Data->RequestStartTransaction[evseId-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14651. }
  14652. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14653. {
  14654. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14655. {
  14656. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14657. }
  14658. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14659. {
  14660. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14661. }
  14662. }
  14663. // Optional data
  14664. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14665. {
  14666. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14667. {
  14668. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14669. }
  14670. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14671. {
  14672. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14673. }
  14674. }
  14675. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14676. {
  14677. // Check periods is over max configuration
  14678. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  14679. {
  14680. isPeriodOverMax = TRUE;
  14681. }
  14682. // Check profile purpose is TxProfile
  14683. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14684. {
  14685. ShmOCPP20Data->RequestStartTransaction[evseId-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14686. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  14687. }
  14688. else
  14689. {
  14690. isTxProfile = FALSE;
  14691. }
  14692. }
  14693. //check Transaction active
  14694. if(gunType[evseId-1] == GUN_TYPE_CHAdeMO)
  14695. {
  14696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14697. {
  14698. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14699. }
  14700. else
  14701. {
  14702. tempIndex = (evseId-1);
  14703. }
  14704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14705. {
  14706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  14707. {
  14708. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14709. {
  14710. //Reserved
  14711. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  14712. }
  14713. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14714. {
  14715. //Reserved
  14716. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  14717. isAllowStart = FALSE;
  14718. }
  14719. else
  14720. {
  14721. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14722. {
  14723. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  14724. isAllowStart = FALSE;
  14725. }
  14726. }//END FOR ELSE
  14727. }
  14728. }// END FOR CHAdeMO_QUANTITY
  14729. }
  14730. else if(gunType[evseId-1] == GUN_TYPE_CCS)
  14731. {
  14732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14733. {
  14734. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14735. }
  14736. else
  14737. {
  14738. tempIndex = (evseId-1);
  14739. }
  14740. for (int index = 0; index < CCS_QUANTITY; index++)
  14741. {
  14742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14743. {
  14744. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14745. {
  14746. //Reserved
  14747. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  14748. }
  14749. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14750. {
  14751. //Reserved
  14752. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  14753. isAllowStart = FALSE;
  14754. }
  14755. else
  14756. {
  14757. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14758. {
  14759. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  14760. isAllowStart = FALSE;
  14761. }
  14762. }// END FOR ELSE
  14763. }
  14764. }// END FOR CCS_QUANTITY
  14765. }
  14766. else if(gunType[evseId-1] == GUN_TYPE_GBT)
  14767. {
  14768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14769. {
  14770. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14771. }
  14772. else
  14773. {
  14774. tempIndex = (evseId-1);
  14775. }
  14776. for (int index = 0; index < GB_QUANTITY; index++)
  14777. {
  14778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  14779. {
  14780. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14781. {
  14782. //Reserved
  14783. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  14784. }
  14785. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14786. {
  14787. //Reserved
  14788. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  14789. isAllowStart = FALSE;
  14790. }
  14791. else
  14792. {
  14793. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14794. {
  14795. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  14796. isAllowStart = FALSE;
  14797. }
  14798. }// END FOR ELSE
  14799. }
  14800. } // END FOR GB_QUANTITY
  14801. }
  14802. else if(gunType[evseId-1] == GUN_TYPE_DO)
  14803. {
  14804. tempIndex = (evseId-1);
  14805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14806. {
  14807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  14808. {
  14809. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14810. {
  14811. //Reserved
  14812. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  14813. }
  14814. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14815. {
  14816. //Reserved
  14817. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  14818. isAllowStart = FALSE;
  14819. }
  14820. else
  14821. {
  14822. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14823. {
  14824. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  14825. isAllowStart = FALSE;
  14826. }
  14827. }// END FOR ELSE
  14828. }
  14829. } // END FOR GB_QUANTITY
  14830. }
  14831. else
  14832. {
  14833. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14834. {
  14835. tempIndex = 2;
  14836. }
  14837. else
  14838. {
  14839. tempIndex = (evseId-1);
  14840. }
  14841. for (int index = 0; index < AC_QUANTITY; index++)
  14842. {
  14843. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  14844. {
  14845. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14846. {
  14847. //Reserved
  14848. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  14849. }
  14850. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14851. {
  14852. //Reserved
  14853. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  14854. isAllowStart = FALSE;
  14855. }
  14856. else
  14857. {
  14858. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14859. {
  14860. DEBUG_WARN("AC connector not allow start cause busy.\n");
  14861. isAllowStart = FALSE;
  14862. }
  14863. }//END FOR ELSE
  14864. }
  14865. }// END FOR AC_QUANTITY
  14866. }
  14867. }
  14868. else
  14869. {
  14870. DEBUG_INFO("Connector id does not specific.\n");
  14871. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14872. {
  14873. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  14874. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  14875. // Required data
  14876. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14877. {
  14878. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14879. }
  14880. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14881. {
  14882. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14883. {
  14884. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14885. }
  14886. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14887. {
  14888. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14889. }
  14890. }
  14891. // Optional data
  14892. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14893. {
  14894. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14895. {
  14896. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14897. }
  14898. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14899. {
  14900. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14901. }
  14902. }
  14903. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14904. {
  14905. // Check periods is over max configuration
  14906. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  14907. {
  14908. isPeriodOverMax = TRUE;
  14909. }
  14910. // Check profile purpose is TxProfile
  14911. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14912. {
  14913. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14914. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14915. }
  14916. else
  14917. {
  14918. isTxProfile = FALSE;
  14919. }
  14920. }
  14921. }
  14922. }
  14923. }
  14924. // Profile replace or add info
  14925. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  14926. {
  14927. if(evseId != -1)
  14928. {
  14929. if(strlen((char*)filename) > 0)
  14930. {
  14931. // Save profile to file
  14932. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  14933. system(cmdBuf);
  14934. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", evseId);
  14935. filePtr = fopen((char*)filename, "w");
  14936. fprintf(filePtr, "{\"evseId\":%d,\"chargingProfile\":%s}\n", evseId, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14937. fclose(filePtr);
  14938. }
  14939. ShmOCPP20Data->CsMsg.bits[evseId-1].RequestStartTransactionReq = ON;
  14940. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14941. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_transactionId);
  14942. result = PASS;
  14943. }
  14944. else
  14945. {
  14946. uint8_t isHasIdleConnector = FALSE;
  14947. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14948. {
  14949. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  14950. {
  14951. isHasIdleConnector = TRUE;
  14952. break;
  14953. }
  14954. }
  14955. if((isHasIdleConnector == TRUE) && !ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14956. {
  14957. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  14958. if(strlen((char*)filename) > 0)
  14959. {
  14960. // Save profile to file
  14961. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14962. system(cmdBuf);
  14963. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  14964. filePtr = fopen((char*)filename, "w");
  14965. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14966. fclose(filePtr);
  14967. }
  14968. refreshStartTimer(&clientTime.RemoteStartWait);
  14969. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  14970. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14971. {
  14972. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14973. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  14974. }
  14975. result = PASS;
  14976. }
  14977. else
  14978. {
  14979. DEBUG_INFO("There is not any connector is idle.\n");
  14980. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14981. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14982. }
  14983. }
  14984. }
  14985. else
  14986. {
  14987. if(isOverConnectorMax != FALSE)
  14988. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  14989. if(isPeriodOverMax)
  14990. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14991. if(!isTxProfile)
  14992. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  14993. if(!isAllowStart)
  14994. DEBUG_WARN("Target connector does not allow start.\n");
  14995. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((evseId-1)<0?0:(evseId-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  14996. }
  14997. }
  14998. json_object_put(RemoteStartTransaction);
  14999. sendRemoteStartTransactionConfirmation(uuid, ((evseId-1)<0?0:(evseId-1)));
  15000. return result;
  15001. }
  15002. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  15003. {
  15004. mtrace();
  15005. int result = FAIL;
  15006. int match = FALSE;
  15007. int GunNO = 0;
  15008. int tempIndex = 0;
  15009. char transactionIdStr[37];
  15010. int transactionIdIsNULL= TRUE;
  15011. json_object *RemoteStopTransaction;
  15012. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  15013. if(server_pending == TRUE)
  15014. {
  15015. return 0;
  15016. }
  15017. RemoteStopTransaction = json_tokener_parse(payload);
  15018. if(!is_error(RemoteStopTransaction))
  15019. {
  15020. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  15021. {
  15022. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  15023. transactionIdIsNULL = FALSE;
  15024. }
  15025. }
  15026. json_object_put(RemoteStopTransaction);
  15027. if(transactionIdIsNULL == FALSE)
  15028. {
  15029. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  15030. {
  15031. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  15032. {
  15033. //check Transaction active
  15034. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15035. {
  15036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15037. {
  15038. tempIndex = ((gun_index==2) ? 1: 0);
  15039. }
  15040. else
  15041. {
  15042. tempIndex = gun_index;
  15043. }
  15044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15045. {
  15046. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15047. {
  15048. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15049. {
  15050. match = TRUE;
  15051. GunNO = gun_index;
  15052. }
  15053. }
  15054. }// END FOR CHAdeMO_QUANTITY
  15055. }
  15056. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15057. {
  15058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15059. {
  15060. tempIndex = ((gun_index==2) ? 1: 0);
  15061. }
  15062. else
  15063. {
  15064. tempIndex = gun_index;
  15065. }
  15066. for (int index = 0; index < CCS_QUANTITY; index++)
  15067. {
  15068. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15069. {
  15070. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15071. {
  15072. match = TRUE;
  15073. GunNO = gun_index;
  15074. }
  15075. }
  15076. }// END FOR CCS_QUANTITY
  15077. }
  15078. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15079. {
  15080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15081. {
  15082. tempIndex = ((gun_index==2) ? 1: 0);
  15083. }
  15084. else
  15085. {
  15086. tempIndex = gun_index;
  15087. }
  15088. for (int index = 0; index < GB_QUANTITY; index++)
  15089. {
  15090. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15091. {
  15092. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15093. {
  15094. match = TRUE;
  15095. GunNO = gun_index;
  15096. }
  15097. }
  15098. }// END FOR GB_QUANTITY
  15099. }
  15100. else if(gunType[gun_index] == GUN_TYPE_DO)
  15101. {
  15102. tempIndex = gun_index;
  15103. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15104. {
  15105. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15106. {
  15107. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15108. {
  15109. match = TRUE;
  15110. GunNO = gun_index;
  15111. }
  15112. }
  15113. }// END FOR GB_QUANTITY
  15114. }
  15115. else
  15116. {
  15117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15118. {
  15119. tempIndex = 2;
  15120. }
  15121. else
  15122. {
  15123. tempIndex = gun_index;
  15124. }
  15125. for (int index = 0; index < AC_QUANTITY; index++)
  15126. {
  15127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15128. {
  15129. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15130. {
  15131. match = TRUE;
  15132. GunNO = gun_index;
  15133. }
  15134. }
  15135. }// END FOR CHAdeMO_QUANTITY
  15136. } // END FOR AC ELSE
  15137. }// CHECK IF ResponseTransactionId == transactionIdInt
  15138. }//END FOR
  15139. if( match == TRUE)
  15140. {
  15141. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  15142. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15143. }
  15144. else
  15145. {
  15146. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15147. }
  15148. }
  15149. else
  15150. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15151. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  15152. return result;
  15153. }
  15154. int handleReserveNowRequest(char *uuid, char *payload)
  15155. {
  15156. mtrace();
  15157. int result = FAIL;
  15158. int evseIdInt=0, reservationIdInt=0;
  15159. int tempIndex = 0;
  15160. json_object *ReserveNow;
  15161. DEBUG_INFO("handleReserveNowRequest ...\n");
  15162. ReserveNow = json_tokener_parse(payload);
  15163. if(!is_error(ReserveNow))
  15164. {
  15165. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  15166. {
  15167. evseIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15168. evseIdInt = (evseIdInt==0)?1:evseIdInt;
  15169. memset(&ShmOCPP20Data->ReserveNow[evseIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  15170. ShmOCPP20Data->ReserveNow[evseIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15171. }
  15172. // Required data
  15173. if(json_object_object_get(ReserveNow, "id") != NULL)
  15174. ShmOCPP20Data->ReserveNow[evseIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  15175. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  15176. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  15177. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  15178. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  15179. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  15180. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  15181. // Optional data
  15182. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  15183. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  15184. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  15185. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  15186. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  15187. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  15188. result = PASS;
  15189. }
  15190. json_object_put(ReserveNow);
  15191. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15192. if((evseIdInt > 0) && ((evseIdInt -1) <= gunTotalNumber))
  15193. {
  15194. //check Transaction active
  15195. if(gunType[evseIdInt -1] == GUN_TYPE_CHAdeMO)
  15196. {
  15197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15198. {
  15199. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15200. }
  15201. else
  15202. {
  15203. tempIndex = evseIdInt -1;
  15204. }
  15205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15206. {
  15207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15208. {
  15209. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15210. {
  15211. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15212. {
  15213. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15214. {
  15215. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  15216. {
  15217. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15218. }
  15219. else
  15220. {
  15221. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15222. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15223. }
  15224. }
  15225. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  15226. {
  15227. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15228. }
  15229. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15230. {
  15231. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15232. }
  15233. else
  15234. {
  15235. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15236. }
  15237. }
  15238. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  15239. {
  15240. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15241. }
  15242. }
  15243. else
  15244. {
  15245. //replace reservation
  15246. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15247. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15248. }
  15249. }
  15250. } // END FOR CHAdeMO_QUANTITY
  15251. }
  15252. else if(gunType[evseIdInt -1] == GUN_TYPE_CCS)
  15253. {
  15254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15255. {
  15256. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15257. }
  15258. else
  15259. {
  15260. tempIndex = evseIdInt -1;
  15261. }
  15262. for (int index = 0; index < CCS_QUANTITY; index++)
  15263. {
  15264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15265. {
  15266. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15267. {
  15268. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15269. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15270. {
  15271. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15272. {
  15273. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  15274. {
  15275. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15276. }
  15277. else
  15278. {
  15279. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15280. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15281. }
  15282. }
  15283. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  15284. {
  15285. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15286. }
  15287. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  15288. {
  15289. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15290. }
  15291. else
  15292. {
  15293. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15294. }
  15295. }
  15296. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  15297. {
  15298. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15299. }
  15300. }
  15301. else
  15302. {
  15303. //replace reservation
  15304. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15305. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15306. }
  15307. }
  15308. } // END FOR CCS_QUANTITY
  15309. }
  15310. else if(gunType[evseIdInt -1] == GUN_TYPE_GBT)
  15311. {
  15312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15313. {
  15314. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15315. }
  15316. else
  15317. {
  15318. tempIndex = evseIdInt -1;
  15319. }
  15320. for (int index = 0; index < GB_QUANTITY; index++)
  15321. {
  15322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15323. {
  15324. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15325. {
  15326. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15327. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15328. {
  15329. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15330. {
  15331. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  15332. {
  15333. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15334. }
  15335. else
  15336. {
  15337. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15338. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15339. }
  15340. }
  15341. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  15342. {
  15343. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15344. }
  15345. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15346. {
  15347. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15348. }
  15349. else
  15350. {
  15351. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15352. }
  15353. }
  15354. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  15355. {
  15356. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15357. }
  15358. }
  15359. else
  15360. {
  15361. //replace reservation
  15362. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15363. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15364. }
  15365. }
  15366. }// END FOR GB_QUANTITY
  15367. }
  15368. else if(gunType[evseIdInt -1] == GUN_TYPE_DO)
  15369. {
  15370. tempIndex = evseIdInt -1;
  15371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15372. {
  15373. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15374. {
  15375. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  15376. {
  15377. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15378. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15379. {
  15380. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15381. {
  15382. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  15383. {
  15384. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15385. }
  15386. else
  15387. {
  15388. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15389. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15390. }
  15391. }
  15392. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  15393. {
  15394. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15395. }
  15396. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15397. {
  15398. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15399. }
  15400. else
  15401. {
  15402. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15403. }
  15404. }
  15405. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  15406. {
  15407. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15408. }
  15409. }
  15410. else
  15411. {
  15412. //replace reservation
  15413. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15414. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15415. }
  15416. }
  15417. }// END FOR DO_QUANTITY
  15418. }
  15419. else
  15420. {
  15421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15422. {
  15423. tempIndex = 2;
  15424. }
  15425. else
  15426. {
  15427. tempIndex = (evseIdInt -1);
  15428. }
  15429. for (int index = 0; index < AC_QUANTITY; index++)
  15430. {
  15431. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15432. {
  15433. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15434. {
  15435. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15436. {
  15437. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15438. {
  15439. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  15440. {
  15441. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15442. }
  15443. else
  15444. {
  15445. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15446. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15447. }
  15448. }
  15449. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  15450. {
  15451. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15452. }
  15453. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15454. {
  15455. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15456. }
  15457. else
  15458. {
  15459. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15460. }
  15461. }
  15462. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  15463. {
  15464. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15465. }
  15466. }
  15467. else
  15468. {
  15469. //replace reservation
  15470. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15471. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15472. }
  15473. }
  15474. } // END FOR AC_QUANTITY
  15475. }
  15476. }
  15477. else if(evseIdInt == 0)
  15478. {
  15479. //check Transaction active
  15480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15481. {
  15482. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15483. {
  15484. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  15485. {
  15486. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15487. goto end;
  15488. }
  15489. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15490. {
  15491. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15492. goto end;
  15493. }
  15494. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  15495. {
  15496. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15497. goto end;
  15498. }
  15499. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15500. {
  15501. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15502. goto end;
  15503. }
  15504. }
  15505. }// END FOR CHAdeMO_QUANTITY
  15506. for (int index = 0; index < CCS_QUANTITY; index++)
  15507. {
  15508. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15509. {
  15510. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  15511. {
  15512. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15513. goto end;
  15514. }
  15515. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  15516. {
  15517. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15518. goto end;
  15519. }
  15520. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  15521. {
  15522. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15523. goto end;
  15524. }
  15525. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15526. {
  15527. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15528. goto end;
  15529. }
  15530. }
  15531. } // END FOR CCS_QUANTITY
  15532. for (int index = 0; index < GB_QUANTITY; index++)
  15533. {
  15534. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15535. {
  15536. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  15537. {
  15538. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15539. goto end;
  15540. }
  15541. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15542. {
  15543. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15544. goto end;
  15545. }
  15546. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  15547. {
  15548. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15549. goto end;
  15550. }
  15551. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15552. {
  15553. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15554. goto end;
  15555. }
  15556. }
  15557. } // END FOR GB_QUANTITY
  15558. for (int index = 0; index < AC_QUANTITY; index++)
  15559. {
  15560. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15561. {
  15562. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  15563. {
  15564. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15565. goto end;
  15566. }
  15567. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15568. {
  15569. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15570. goto end;
  15571. }
  15572. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  15573. {
  15574. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15575. goto end;
  15576. }
  15577. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15578. {
  15579. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  15580. {
  15581. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15582. goto end;
  15583. }
  15584. }
  15585. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15586. {
  15587. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15588. goto end;
  15589. }
  15590. }
  15591. }// END FOR AC_QUANTITY
  15592. //The connectorId is 0
  15593. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  15594. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15595. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  15596. result = TRUE;
  15597. return result;
  15598. }
  15599. else
  15600. {
  15601. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15602. }
  15603. if(strcmp((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  15604. {
  15605. strcpy((char *)ShmOCPP20Data->ReserveNow[evseIdInt-1].guid, uuid);
  15606. result = TRUE;
  15607. return result;
  15608. }
  15609. end:
  15610. sendReserveNowConfirmation(uuid, (evseIdInt==0?evseIdInt:evseIdInt-1));
  15611. return result;
  15612. }
  15613. int handleResetRequest(char *uuid, char *payload)
  15614. {
  15615. mtrace();
  15616. int result = FAIL;
  15617. json_object *Reset = json_object_new_object();
  15618. DEBUG_INFO("handleResetRequest...\n");
  15619. Reset = json_tokener_parse(payload);
  15620. ShmOCPP20Data->Reset.evseId = 0;
  15621. if(!is_error(Reset))
  15622. {
  15623. // Required data
  15624. if(json_object_object_get(Reset, "type") != NULL)
  15625. {
  15626. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  15627. }
  15628. if(json_object_object_get(Reset, "evseId") != NULL)
  15629. {
  15630. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  15631. }
  15632. }
  15633. json_object_put(Reset);
  15634. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  15635. {
  15636. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  15637. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  15638. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  15639. result = PASS;
  15640. }
  15641. else
  15642. {
  15643. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  15644. }
  15645. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  15646. sendResetConfirmation(uuid);
  15647. return result;
  15648. }
  15649. int handleSendLocalListRequest(char *uuid, char *payload)
  15650. {
  15651. mtrace();
  15652. int result = FAIL;
  15653. int checkState_Faulted = FALSE;
  15654. json_object *SendLocalList;
  15655. DEBUG_INFO("handleSendLocalListRequest...\n");
  15656. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  15657. {
  15658. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15659. goto end;
  15660. }
  15661. SendLocalList = json_tokener_parse(payload);
  15662. if(!is_error(SendLocalList))
  15663. {
  15664. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  15665. // Required data
  15666. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  15667. {
  15668. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  15669. }
  15670. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  15671. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  15672. // Optional data
  15673. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  15674. {
  15675. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  15676. {
  15677. // Required data
  15678. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  15679. {
  15680. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken"), "idToken")));
  15681. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.type, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken"), "type"))));
  15682. }
  15683. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  15684. {
  15685. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.status, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status"))));
  15686. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  15687. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime")));
  15688. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  15689. ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority"));
  15690. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  15691. {
  15692. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken"), "idToken")));
  15693. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken"), "type")));
  15694. }
  15695. }
  15696. }
  15697. }
  15698. }
  15699. json_object_put(SendLocalList);
  15700. //check Charge Point state
  15701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15702. {
  15703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15704. {
  15705. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15706. }
  15707. }
  15708. for (int index = 0; index < CCS_QUANTITY; index++)
  15709. {
  15710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15711. {
  15712. checkState_Faulted = TRUE; //OCPP Status
  15713. }
  15714. }
  15715. for (int index = 0; index < GB_QUANTITY; index++)
  15716. {
  15717. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15718. {
  15719. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15720. }
  15721. }
  15722. for (int index = 0; index < AC_QUANTITY; index++)
  15723. {
  15724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15725. {
  15726. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15727. }
  15728. }
  15729. if(checkState_Faulted == TRUE)
  15730. {
  15731. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15732. goto end;
  15733. }
  15734. // Check update type
  15735. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  15736. {
  15737. //Local list full update
  15738. DEBUG_INFO("Local list full update.\n");
  15739. DB_getListVerion();
  15740. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15741. {
  15742. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15743. goto end;
  15744. }*/
  15745. DB_cleanLocalList();
  15746. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15747. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15748. }
  15749. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  15750. {
  15751. //Local list different update
  15752. DEBUG_INFO("Local list different update.\n");
  15753. DB_getListVerion();
  15754. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15755. {
  15756. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  15757. goto end;
  15758. }
  15759. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15760. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15761. }
  15762. else
  15763. {
  15764. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15765. goto end;
  15766. }
  15767. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  15768. end:
  15769. sendSendLocalListConfirmation(uuid);
  15770. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15771. return result;
  15772. }
  15773. int handleSetChargingProfileRequest(char *uuid, char *payload)
  15774. {
  15775. mtrace();
  15776. int result = FAIL;
  15777. struct SetChargingProfile_20 SetProfileReq = {0};
  15778. uint8_t isLostEvseId = FALSE;
  15779. uint8_t isPeriodOverMax = FALSE;
  15780. uint8_t isStackOverMax = FALSE;
  15781. uint8_t isProfileOverMax = FALSE;
  15782. uint8_t isEvseMismatch = FALSE;
  15783. uint8_t isTransactiodIdMismatch = FALSE;
  15784. uint8_t isInvalidLimit = FALSE;
  15785. uint8_t isWrongFormat = FALSE;
  15786. uint8_t replaceableProfileCnt = 0;
  15787. uint8_t existProfileQuantity = 0;
  15788. uint8_t filename[128]={0};
  15789. uint8_t dataLine[4096]={0};
  15790. FILE *filePtr;
  15791. json_object *SetChargingProfile;
  15792. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  15793. SetChargingProfile = json_tokener_parse(payload);
  15794. if(!is_error(SetChargingProfile))
  15795. {
  15796. // Required data
  15797. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  15798. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  15799. else
  15800. isLostEvseId = TRUE;
  15801. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  15802. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  15803. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  15804. {
  15805. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15806. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15807. {
  15808. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  15809. }
  15810. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  15811. {
  15812. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15813. }
  15814. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  15815. {
  15816. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  15817. }
  15818. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  15819. {
  15820. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  15821. }
  15822. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  15823. {
  15824. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  15825. }
  15826. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  15827. {
  15828. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  15829. }
  15830. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  15831. {
  15832. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  15833. }
  15834. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  15835. {
  15836. int chargingScheduleCount = 0;
  15837. int chargingSchedulePeriodCount = 0;
  15838. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  15839. {
  15840. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  15841. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  15842. {
  15843. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  15844. {
  15845. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit")));
  15846. }
  15847. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  15848. {
  15849. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration"));
  15850. }
  15851. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  15852. {
  15853. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate"));
  15854. }
  15855. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  15856. {
  15857. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].startSchedule, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule")));
  15858. }
  15859. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  15860. {
  15861. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"));
  15862. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  15863. {
  15864. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  15865. {
  15866. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  15867. {
  15868. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  15869. }
  15870. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  15871. {
  15872. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "limit"));
  15873. }
  15874. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  15875. {
  15876. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  15877. }
  15878. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "phaseToUse") != NULL)
  15879. {
  15880. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "phaseToUse"));
  15881. }
  15882. // Check invalid limit
  15883. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  15884. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  15885. {
  15886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  15887. {
  15888. if(((0 < SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit) && (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit < (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases)))) ||
  15889. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  15890. {
  15891. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  15892. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15893. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15894. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15895. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  15896. isInvalidLimit = TRUE;
  15897. }
  15898. }
  15899. else
  15900. {
  15901. if((SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?1:220*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases)) > modelnameInfo.ratedPower) ||
  15902. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?1:220*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases)) < (modelnameInfo.ratedPower*0.01)))
  15903. {
  15904. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  15905. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15906. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15907. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15908. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  15909. isInvalidLimit = TRUE;
  15910. }
  15911. }
  15912. }
  15913. }
  15914. }
  15915. else
  15916. {
  15917. isPeriodOverMax = TRUE;
  15918. }
  15919. }
  15920. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  15921. {
  15922. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "id") != NULL)
  15923. {
  15924. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "id"));
  15925. }
  15926. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffDescription") != NULL)
  15927. {
  15928. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffDescription, json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffDescription")));
  15929. }
  15930. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "numEPriceLevels") != NULL)
  15931. {
  15932. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.numEPriceLevels = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "numEPriceLevels"));
  15933. }
  15934. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry") != NULL)
  15935. {
  15936. int cntEntry = json_object_array_length(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"));
  15937. if(cntEntry<=1024)
  15938. {
  15939. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  15940. {
  15941. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel") != NULL)
  15942. {
  15943. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].ePriceLevel = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel"));
  15944. }
  15945. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval") != NULL)
  15946. {
  15947. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "start") != NULL)
  15948. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].relativeTimeInterval.start = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "start"));
  15949. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "duration") != NULL)
  15950. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].relativeTimeInterval.duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "duration"));
  15951. }
  15952. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost") != NULL)
  15953. {
  15954. uint8_t cntConCost = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"));
  15955. if(cntConCost<=3)
  15956. {
  15957. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  15958. {
  15959. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "startValue") != NULL)
  15960. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].startValue = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"));
  15961. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost") != NULL)
  15962. {
  15963. uint8_t cntCost = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"));
  15964. if(cntConCost<=3)
  15965. {
  15966. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  15967. {
  15968. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "costKind") != NULL)
  15969. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].costKind, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "costKind")));
  15970. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amount") != NULL)
  15971. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].amount = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amount"));
  15972. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amountMultiplier") != NULL)
  15973. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].amountMultiplier = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amountMultiplier"));
  15974. }
  15975. }
  15976. }
  15977. }
  15978. }
  15979. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].ePriceLevel = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel"));
  15980. }
  15981. }
  15982. }
  15983. }
  15984. }
  15985. }
  15986. }
  15987. else
  15988. {
  15989. isWrongFormat = TRUE;
  15990. }
  15991. }
  15992. // Check periods is over max configuration
  15993. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  15994. {
  15995. if(SetProfileReq.evseId == 0)
  15996. {
  15997. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  15998. filePtr = fopen((char*)filename, "r");
  15999. if (!filePtr)
  16000. {
  16001. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  16002. filePtr = fopen((char*)filename, "w+");
  16003. }
  16004. else
  16005. {
  16006. //Check Charging Profile Count
  16007. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16008. char *line = NULL;
  16009. size_t len = 0;
  16010. while(getline(&line, &len, filePtr) != -1)
  16011. {
  16012. json_object *obj = NULL;
  16013. obj = json_tokener_parse(line);
  16014. if(is_error(obj))
  16015. {
  16016. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16017. }
  16018. else
  16019. {
  16020. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16021. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16022. {
  16023. existProfileQuantity += 1;
  16024. }
  16025. else
  16026. replaceableProfileCnt += 1;
  16027. }
  16028. //DEBUG_INFO("word=%s\n",word);
  16029. /*if(strstr((char*)dataLine, "id")!= NULL)
  16030. {
  16031. existProfileQuantity += 1;
  16032. }*/
  16033. }
  16034. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16035. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16036. {
  16037. isStackOverMax = TRUE;
  16038. }
  16039. }
  16040. fclose(filePtr);
  16041. }
  16042. else
  16043. isEvseMismatch = TRUE;
  16044. }
  16045. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  16046. {
  16047. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  16048. isEvseMismatch = TRUE;
  16049. if(!isEvseMismatch)
  16050. {
  16051. if(SetProfileReq.evseId == 0)
  16052. {
  16053. int tmpExistProfileQuantity;
  16054. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  16055. {
  16056. tmpExistProfileQuantity = 0;
  16057. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16058. filePtr = fopen((char*)filename, "r");
  16059. if (!filePtr)
  16060. {
  16061. DEBUG_INFO("%s not exist, create it.\n", filename);
  16062. filePtr = fopen((char*)filename, "w+");
  16063. }
  16064. else
  16065. {
  16066. //Check Charging Profile Count
  16067. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16068. char *line = NULL;
  16069. size_t len = 0;
  16070. while(getline(&line, &len, filePtr) != -1)
  16071. {
  16072. json_object *obj = NULL;
  16073. obj = json_tokener_parse(line);
  16074. if(is_error(obj))
  16075. {
  16076. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16077. }
  16078. else
  16079. {
  16080. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16081. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16082. {
  16083. tmpExistProfileQuantity += 1;
  16084. }
  16085. else
  16086. replaceableProfileCnt += 1;
  16087. }
  16088. //DEBUG_INFO("word=%s\n",word);
  16089. /*if(strstr((char*)dataLine, "id")!= NULL)
  16090. {
  16091. tmpExistProfileQuantity += 1;
  16092. }*/
  16093. }
  16094. }
  16095. fclose(filePtr);
  16096. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16097. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16098. {
  16099. isStackOverMax = TRUE;
  16100. }
  16101. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  16102. }
  16103. }
  16104. else
  16105. {
  16106. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16107. filePtr = fopen((char*)filename, "r");
  16108. if (!filePtr)
  16109. {
  16110. DEBUG_INFO("%s not exist, create it.\n", filename);
  16111. filePtr = fopen((char*)filename, "w+");
  16112. }
  16113. else
  16114. {
  16115. //Check Charging Profile Count
  16116. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16117. char *line = NULL;
  16118. size_t len = 0;
  16119. while(getline(&line, &len, filePtr) != -1)
  16120. {
  16121. json_object *obj = NULL;
  16122. obj = json_tokener_parse(line);
  16123. if(is_error(obj))
  16124. {
  16125. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  16126. }
  16127. else
  16128. {
  16129. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16130. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16131. {
  16132. existProfileQuantity += 1;
  16133. }
  16134. else
  16135. replaceableProfileCnt += 1;
  16136. }
  16137. //DEBUG_INFO("word=%s\n",word);
  16138. /*if(strstr((char*)dataLine, "id")!= NULL)
  16139. {
  16140. existProfileQuantity += 1;
  16141. }*/
  16142. }
  16143. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16144. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16145. {
  16146. isStackOverMax = TRUE;
  16147. }
  16148. }
  16149. fclose(filePtr);
  16150. }
  16151. }
  16152. }
  16153. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  16154. {
  16155. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  16156. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16157. else
  16158. isEvseMismatch = TRUE;
  16159. if(!isEvseMismatch)
  16160. {
  16161. filePtr = fopen((char*)filename, "r");
  16162. if (!filePtr)
  16163. {
  16164. DEBUG_INFO("%s not exist, create it.\n", filename);
  16165. filePtr = fopen((char*)filename, "w+");
  16166. }
  16167. else
  16168. {
  16169. //Check Charging Profile Count
  16170. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16171. char *line = NULL;
  16172. size_t len = 0;
  16173. while(getline(&line, &len, filePtr) != -1)
  16174. {
  16175. json_object *obj = NULL;
  16176. obj = json_tokener_parse(line);
  16177. if(is_error(obj))
  16178. {
  16179. DEBUG_ERROR("Parse TxProfile from file error.\n");
  16180. }
  16181. else
  16182. {
  16183. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16184. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16185. {
  16186. existProfileQuantity += 1;
  16187. }
  16188. else
  16189. replaceableProfileCnt += 1;
  16190. }
  16191. //DEBUG_INFO("word=%s\n",word);
  16192. /*if(strstr((char*)dataLine, "id")!= NULL)
  16193. {
  16194. existProfileQuantity += 1;
  16195. }*/
  16196. }
  16197. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16198. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16199. {
  16200. isStackOverMax = TRUE;
  16201. }
  16202. }
  16203. fclose(filePtr);
  16204. if(strcmp((char*)SetProfileReq.chargingProfile.transactionId, (char*)ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId) != 0)
  16205. isTransactiodIdMismatch = TRUE;
  16206. }
  16207. }
  16208. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  16209. {
  16210. /*
  16211. * TODO:
  16212. *
  16213. */
  16214. }
  16215. else
  16216. {}
  16217. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  16218. {
  16219. FILE *fp;
  16220. char dataLine[4096]={0};
  16221. char fnametemp[128]={0};
  16222. int tmpProfileQuantity;
  16223. //Check ChargePointMaxProfile.json exit
  16224. existProfileQuantity = 0;
  16225. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  16226. {
  16227. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  16228. //Check Charging Profile Count
  16229. tmpProfileQuantity = 0;
  16230. while(fscanf(fp, "%s", dataLine) != EOF)
  16231. {
  16232. if(strstr(dataLine, "id")!= NULL)
  16233. {
  16234. existProfileQuantity += 1;
  16235. tmpProfileQuantity += 1;
  16236. }
  16237. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16238. }
  16239. fclose(fp);
  16240. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  16241. }
  16242. //Check TxDefaultProfile_%d.json
  16243. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16244. {
  16245. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16246. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16247. if((access(fnametemp,F_OK))!=-1)
  16248. {
  16249. fp = fopen(fnametemp, "r");
  16250. //Check Charging Profile Count
  16251. tmpProfileQuantity = 0;
  16252. while(fscanf(fp, "%s", dataLine) != EOF)
  16253. {
  16254. //DEBUG_INFO("word=%s\n",word);
  16255. if(strstr(dataLine, "id")!= NULL)
  16256. {
  16257. existProfileQuantity += 1;
  16258. tmpProfileQuantity += 1;
  16259. }
  16260. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16261. }
  16262. fclose(fp);
  16263. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16264. }
  16265. }
  16266. //Check TxProfile_%d.json
  16267. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16268. {
  16269. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16270. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  16271. if((access(fnametemp,F_OK))!=-1)
  16272. {
  16273. fp = fopen(fnametemp, "r");
  16274. //Check Charging Profile Count
  16275. tmpProfileQuantity = 0;
  16276. while(fscanf(fp, "%s", dataLine) != EOF)
  16277. {
  16278. if(strstr(dataLine, "id")!= NULL)
  16279. {
  16280. existProfileQuantity += 1;
  16281. tmpProfileQuantity += 1;
  16282. }
  16283. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16284. }
  16285. fclose(fp);
  16286. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16287. }
  16288. }
  16289. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  16290. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  16291. // To check total Profile quantity
  16292. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  16293. {
  16294. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16295. isProfileOverMax = TRUE;
  16296. }
  16297. else
  16298. {
  16299. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16300. isProfileOverMax = TRUE;
  16301. }
  16302. }
  16303. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  16304. }
  16305. // Profile replace or add info
  16306. if(!isLostEvseId && !isPeriodOverMax && !isProfileOverMax && !isEvseMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  16307. {
  16308. FILE *infile;
  16309. FILE *outfile;
  16310. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  16311. char rmFileCmd[128];
  16312. int tempchargingProfileIdInt;
  16313. int tempchargingProfileStackLevelInt;
  16314. int chkChar;
  16315. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  16316. {
  16317. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  16318. {
  16319. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  16320. }
  16321. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  16322. {
  16323. if(SetProfileReq.evseId==0)
  16324. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16325. else
  16326. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16327. }
  16328. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  16329. {
  16330. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16331. }
  16332. else
  16333. {
  16334. /*
  16335. * TODO:
  16336. *
  16337. */
  16338. }
  16339. infile = fopen ((char*)filename, "r");
  16340. outfile = fopen ((char*)tmpProfileName, "w");
  16341. chkChar = fgetc(infile);
  16342. rewind(infile);
  16343. if(chkChar == EOF)
  16344. {
  16345. // Profile is empty
  16346. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16347. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16348. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16349. fclose(infile);
  16350. fclose(outfile);
  16351. sprintf(rmFileCmd,"rm -f %s",filename);
  16352. system(rmFileCmd);
  16353. rename((char*)tmpProfileName, (char*)filename);
  16354. }
  16355. else
  16356. {
  16357. // Profile is not empty
  16358. int ChargingProfileAdded = FALSE;
  16359. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  16360. {
  16361. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  16362. json_object *tmpChargingProfile;
  16363. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  16364. if(!is_error(tmpChargingProfile))
  16365. {
  16366. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  16367. {
  16368. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  16369. {
  16370. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  16371. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  16372. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  16373. }
  16374. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16375. {
  16376. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  16377. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  16378. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  16379. }
  16380. }
  16381. }
  16382. json_object_put(tmpChargingProfile);
  16383. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  16384. {
  16385. if(ChargingProfileAdded == FALSE)
  16386. {
  16387. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16388. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16389. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16390. ChargingProfileAdded = TRUE;
  16391. }
  16392. }
  16393. else
  16394. {
  16395. fprintf(outfile,"%s\n",dataLine);
  16396. if(ChargingProfileAdded == FALSE)
  16397. {
  16398. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16399. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16400. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16401. ChargingProfileAdded = TRUE;
  16402. }
  16403. }
  16404. } // end of while loop
  16405. fclose(infile);
  16406. fclose(outfile);
  16407. sprintf(rmFileCmd,"rm -f %s",filename);
  16408. system(rmFileCmd);
  16409. rename((char*)tmpProfileName, (char*)filename);
  16410. }
  16411. }
  16412. sleep(1);
  16413. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  16414. result = PASS;
  16415. }
  16416. else
  16417. {
  16418. if(isLostEvseId)
  16419. DEBUG_WARN("Connector id is wrong.\n");
  16420. if(isEvseMismatch)
  16421. DEBUG_WARN("Connector id is mismatch.\n");
  16422. if(isPeriodOverMax)
  16423. DEBUG_WARN("Profile periods quantity is over spec.\n");
  16424. if(isProfileOverMax)
  16425. DEBUG_WARN("Profile quantity is over spec.\n");
  16426. if(isTransactiodIdMismatch)
  16427. DEBUG_WARN("Transaction id is mismatch.\n");
  16428. if(isInvalidLimit)
  16429. DEBUG_WARN("Limit value is invalid.\n");
  16430. if(isStackOverMax)
  16431. DEBUG_WARN("Profile stack is over spec.\n");
  16432. if(isWrongFormat)
  16433. DEBUG_WARN("Profile format is wrong.\n");
  16434. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  16435. }
  16436. }
  16437. json_object_put(SetChargingProfile);
  16438. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  16439. {
  16440. if(SetProfileReq.evseId == 0)
  16441. {
  16442. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  16443. {
  16444. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  16445. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16446. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  16447. }
  16448. }
  16449. else
  16450. {
  16451. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  16452. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16453. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  16454. }
  16455. }
  16456. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  16457. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16458. return result;
  16459. }
  16460. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  16461. {
  16462. mtrace();
  16463. int result = FAIL;
  16464. json_object *SetDisplayMessage;
  16465. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  16466. SetDisplayMessage = json_tokener_parse(payload);
  16467. if(!is_error(SetDisplayMessage))
  16468. {
  16469. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  16470. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  16471. // Required data
  16472. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  16473. {
  16474. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  16475. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  16476. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  16477. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  16478. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  16479. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  16480. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  16481. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  16482. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  16483. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  16484. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  16485. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  16486. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  16487. {
  16488. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  16489. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.message.format, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format")));
  16490. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  16491. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.message.language, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language")));
  16492. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  16493. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.message.content, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content")));
  16494. }
  16495. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  16496. {
  16497. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  16498. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.display.name, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name")));
  16499. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  16500. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.display.instance, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance")));
  16501. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  16502. {
  16503. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  16504. ShmOCPP20Data->SetDisplayMessage.message.display.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id"));
  16505. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  16506. ShmOCPP20Data->SetDisplayMessage.message.display.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId"));
  16507. }
  16508. }
  16509. }
  16510. }
  16511. json_object_put(SetDisplayMessage);
  16512. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  16513. sendSetDisplayMessagesConfirmation(uuid);
  16514. // Announce CSU there is display request come from server
  16515. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  16516. return result;
  16517. }
  16518. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  16519. {
  16520. mtrace();
  16521. int result = FAIL;
  16522. json_object *SetMonitoringBase;
  16523. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  16524. SetMonitoringBase = json_tokener_parse(payload);
  16525. if(!is_error(SetMonitoringBase))
  16526. {
  16527. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  16528. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  16529. // Required data
  16530. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  16531. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  16532. }
  16533. json_object_put(SetMonitoringBase);
  16534. /*
  16535. * TODO:
  16536. * 1. Configure monitor base and response
  16537. */
  16538. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  16539. sendSetMonitoringBaseConfirmation(uuid);
  16540. return result;
  16541. }
  16542. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  16543. {
  16544. mtrace();
  16545. int result = FAIL;
  16546. json_object *SetMonitoringLevel;
  16547. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  16548. SetMonitoringLevel = json_tokener_parse(payload);
  16549. if(!is_error(SetMonitoringLevel))
  16550. {
  16551. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  16552. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  16553. // Required data
  16554. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  16555. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  16556. }
  16557. json_object_put(SetMonitoringLevel);
  16558. /*
  16559. * TODO:
  16560. * Configure monitor status and response
  16561. */
  16562. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  16563. sendSetMonitoringLevelConfirmation(uuid);
  16564. return result;
  16565. }
  16566. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  16567. {
  16568. mtrace();
  16569. int result = FAIL;
  16570. json_object *SetNetworkProfile;
  16571. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  16572. SetNetworkProfile = json_tokener_parse(payload);
  16573. if(!is_error(SetNetworkProfile))
  16574. {
  16575. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  16576. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  16577. // Required data
  16578. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  16579. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  16580. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  16581. {
  16582. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  16583. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  16584. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  16585. {
  16586. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  16587. {
  16588. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  16589. }
  16590. else
  16591. {
  16592. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16593. goto end;
  16594. }
  16595. }
  16596. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  16597. {
  16598. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  16599. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  16600. {
  16601. char protocol[10], host[128], path[512], port[10];
  16602. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  16603. if(check >= 3)
  16604. {
  16605. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  16606. DEBUG_INFO("protocol: %s\n",protocol);
  16607. DEBUG_INFO("host: %s\n",host);
  16608. DEBUG_INFO("port: %s\n",port);
  16609. DEBUG_INFO("path: %s\n",path);
  16610. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  16611. }
  16612. else
  16613. {
  16614. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16615. goto end;
  16616. }
  16617. }
  16618. else
  16619. {
  16620. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16621. goto end;
  16622. }
  16623. }
  16624. else
  16625. {
  16626. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16627. goto end;
  16628. }
  16629. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  16630. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  16631. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  16632. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  16633. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  16634. {
  16635. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  16636. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server")));
  16637. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  16638. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user")));
  16639. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  16640. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group")));
  16641. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  16642. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password")));
  16643. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  16644. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key")));
  16645. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  16646. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type")));
  16647. }
  16648. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  16649. {
  16650. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  16651. {
  16652. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  16653. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn")));
  16654. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  16655. }
  16656. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  16657. {
  16658. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  16659. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName")));
  16660. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  16661. }
  16662. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  16663. {
  16664. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  16665. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword")));
  16666. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  16667. }
  16668. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  16669. ShmOCPP20Data->SetNetworkProfile.connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin"));
  16670. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  16671. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork")));
  16672. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  16673. ShmOCPP20Data->SetNetworkProfile.connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork"));
  16674. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  16675. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication")));
  16676. }
  16677. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  16678. }
  16679. }
  16680. json_object_put(SetNetworkProfile);
  16681. /*
  16682. * TODO:
  16683. * 1. Process network configuration and response
  16684. */
  16685. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  16686. {
  16687. }
  16688. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  16689. {
  16690. }
  16691. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  16692. {
  16693. }
  16694. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  16695. {
  16696. }
  16697. else
  16698. {
  16699. }
  16700. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  16701. {
  16702. }
  16703. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  16704. {
  16705. }
  16706. else
  16707. {
  16708. }
  16709. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  16710. {
  16711. }
  16712. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  16713. {
  16714. }
  16715. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  16716. {
  16717. }
  16718. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  16719. {
  16720. }
  16721. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  16722. {
  16723. }
  16724. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  16725. {
  16726. }
  16727. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  16728. {
  16729. }
  16730. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  16731. {
  16732. }
  16733. else
  16734. {
  16735. }
  16736. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  16737. {
  16738. }
  16739. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  16740. {
  16741. }
  16742. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  16743. {
  16744. }
  16745. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  16746. {
  16747. }
  16748. else
  16749. {
  16750. }
  16751. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  16752. {
  16753. }
  16754. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  16755. {
  16756. }
  16757. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  16758. {
  16759. }
  16760. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  16761. {
  16762. }
  16763. else
  16764. {
  16765. }
  16766. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  16767. end:
  16768. sendSetNetworkProfileConfirmation(uuid);
  16769. return result;
  16770. }
  16771. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  16772. {
  16773. mtrace();
  16774. int result = FAIL;
  16775. json_object *SetVariableMonitoring;
  16776. uint8_t variableQuantity = 0;
  16777. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  16778. SetVariableMonitoring = json_tokener_parse(payload);
  16779. if(!is_error(SetVariableMonitoring))
  16780. {
  16781. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  16782. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  16783. // Required data
  16784. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  16785. {
  16786. variableQuantity++;
  16787. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  16788. {
  16789. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id"));
  16790. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  16791. }
  16792. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  16793. {
  16794. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].value = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value"));
  16795. }
  16796. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  16797. {
  16798. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type")));
  16799. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16800. }
  16801. else
  16802. {
  16803. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  16804. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16805. }
  16806. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  16807. {
  16808. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity"));
  16809. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  16810. }
  16811. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  16812. {
  16813. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].transaction = json_object_get_boolean(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction"));
  16814. }
  16815. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  16816. {
  16817. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  16818. {
  16819. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name")));
  16820. }
  16821. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  16822. {
  16823. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance")));
  16824. }
  16825. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  16826. {
  16827. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse"), "id") != NULL)
  16828. {
  16829. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance"), "id"));
  16830. }
  16831. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse"), "connectorId") != NULL)
  16832. {
  16833. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance"), "connectorId"));
  16834. }
  16835. }
  16836. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  16837. }
  16838. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  16839. {
  16840. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  16841. {
  16842. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name")));
  16843. }
  16844. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  16845. {
  16846. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance")));
  16847. }
  16848. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  16849. }
  16850. /*
  16851. * TODO
  16852. * Set Variables and save to DB
  16853. */
  16854. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  16855. }
  16856. }
  16857. json_object_put(SetVariableMonitoring);
  16858. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  16859. return result;
  16860. }
  16861. int handleSetVariablesRequest(char *uuid, char *payload)
  16862. {
  16863. mtrace();
  16864. uint8_t result = FAIL;
  16865. uint8_t isUnknownComponent = TRUE;
  16866. uint8_t isNeedReconnect = FALSE;
  16867. json_object *SetVariables;
  16868. DEBUG_INFO("handleSetVariablesRequest...\n");
  16869. SetVariables = json_tokener_parse(payload);
  16870. if(!is_error(SetVariables))
  16871. {
  16872. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  16873. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  16874. // Required data
  16875. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  16876. {
  16877. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  16878. {
  16879. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  16880. {
  16881. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  16882. {
  16883. sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name")));
  16884. }
  16885. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  16886. {
  16887. sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance")));
  16888. }
  16889. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  16890. {
  16891. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse"), "id") != NULL)
  16892. {
  16893. ShmOCPP20Data->SetVariables.setVariableData[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse"), "id"));
  16894. }
  16895. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse"), "connectorId") != NULL)
  16896. {
  16897. ShmOCPP20Data->SetVariables.setVariableData[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse"), "connectorId"));
  16898. }
  16899. }
  16900. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  16901. }
  16902. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  16903. {
  16904. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  16905. {
  16906. sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name")));
  16907. }
  16908. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  16909. {
  16910. sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance")));
  16911. }
  16912. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  16913. }
  16914. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  16915. {
  16916. sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType")));
  16917. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  16918. }
  16919. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  16920. {
  16921. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  16922. }
  16923. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  16924. {
  16925. sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue")));
  16926. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  16927. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  16928. {
  16929. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  16930. (strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.instance)>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.instance) != NULL):TRUE) &&
  16931. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  16932. (strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.instance)>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.instance) != NULL):TRUE))
  16933. {
  16934. isUnknownComponent = FALSE;
  16935. //DEBUG_INFO("Checking variable...[%s][%s], dataType: %s\n",ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType);
  16936. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  16937. {
  16938. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  16939. {
  16940. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16941. break;
  16942. }
  16943. }
  16944. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  16945. {
  16946. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  16947. {
  16948. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16949. break;
  16950. }
  16951. }
  16952. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  16953. {
  16954. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  16955. {
  16956. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16957. break;
  16958. }
  16959. }
  16960. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  16961. {
  16962. // To make sure all boolean value is in uppercase
  16963. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  16964. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  16965. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  16966. {
  16967. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  16968. }
  16969. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  16970. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  16971. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  16972. {
  16973. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  16974. }
  16975. else
  16976. {
  16977. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16978. break;
  16979. }
  16980. }
  16981. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  16982. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  16983. {
  16984. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  16985. break;
  16986. }
  16987. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  16988. {
  16989. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16990. break;
  16991. }
  16992. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  16993. {
  16994. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16995. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16996. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16997. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16998. {
  16999. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17000. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17001. if(strstr((char*)tmp, "true") != NULL)
  17002. {
  17003. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  17004. }
  17005. else
  17006. {
  17007. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  17008. }
  17009. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17010. }
  17011. else
  17012. {
  17013. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17014. break;
  17015. }
  17016. }
  17017. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  17018. {
  17019. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  17020. }
  17021. else
  17022. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17023. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  17024. {
  17025. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  17026. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17027. else
  17028. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17029. }
  17030. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  17031. {
  17032. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17033. {
  17034. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17035. }
  17036. else
  17037. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17038. }
  17039. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  17040. {
  17041. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17042. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17043. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17044. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17045. {
  17046. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17047. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17048. }
  17049. else
  17050. {
  17051. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17052. break;
  17053. }
  17054. }
  17055. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  17056. {
  17057. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17058. {
  17059. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17060. }
  17061. else
  17062. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17063. }
  17064. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "CharingProfileRefreshInterval") != NULL))
  17065. {
  17066. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17067. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17068. else
  17069. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17070. }
  17071. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttempts") != NULL))
  17072. {
  17073. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17074. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17075. else
  17076. {
  17077. TransactionMessageAttemptsValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17078. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17079. }
  17080. }
  17081. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttemptInterval") != NULL))
  17082. {
  17083. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17084. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17085. else
  17086. {
  17087. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17088. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17089. }
  17090. }
  17091. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "RfidEndianType") != NULL))
  17092. {
  17093. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17094. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17095. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17096. if((strstr((char*)tmp, "big") != NULL) || (strstr((char*)tmp, "little") != NULL))
  17097. {
  17098. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "big") != NULL)? "big" : "little");
  17099. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strstr((char*)tmp, "big") != NULL)?1:0;
  17100. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17101. }
  17102. else
  17103. {
  17104. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17105. break;
  17106. }
  17107. }
  17108. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "AuthorizeTimeout") != NULL))
  17109. {
  17110. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) <=0) ||
  17111. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) ||
  17112. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.maxLimit))
  17113. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17114. else
  17115. {
  17116. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17117. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17118. }
  17119. }
  17120. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  17121. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  17122. {
  17123. isNeedReconnect = TRUE;
  17124. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17125. //SetOcppConnStatus(FALSE);
  17126. }
  17127. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  17128. {
  17129. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17130. {
  17131. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17132. }
  17133. else
  17134. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17135. }
  17136. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  17137. {
  17138. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17139. {
  17140. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17141. }
  17142. else
  17143. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17144. }
  17145. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  17146. {
  17147. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17148. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17149. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17150. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17151. {
  17152. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17153. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  17154. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17155. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17156. }
  17157. }
  17158. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  17159. {
  17160. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  17161. {
  17162. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17163. }
  17164. else
  17165. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17166. }
  17167. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  17168. {
  17169. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  17170. {
  17171. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17172. }
  17173. else
  17174. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17175. }
  17176. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  17177. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  17178. {
  17179. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17180. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  17181. }
  17182. break;
  17183. }
  17184. else
  17185. {
  17186. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  17187. {
  17188. isUnknownComponent = FALSE;
  17189. }
  17190. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  17191. }
  17192. }
  17193. if(isUnknownComponent == TRUE)
  17194. {
  17195. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17196. }
  17197. }
  17198. }
  17199. }
  17200. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17201. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  17202. if(isNeedReconnect)
  17203. {
  17204. SetOcppConnStatus(FALSE);
  17205. }
  17206. }
  17207. json_object_put(SetVariables);
  17208. return result;
  17209. }
  17210. int handleTriggerMessageRequest(char *uuid, char *payload)
  17211. {
  17212. mtrace();
  17213. int result = FAIL;
  17214. int evseIdIsNULL = FALSE;
  17215. //int connectorIdIsNULL = FALSE;
  17216. int evseIdInt =0;
  17217. //int connectorIdInt =0;
  17218. json_object *TriggerMessage;
  17219. DEBUG_INFO("handleTriggerMessageRequest\n");
  17220. TriggerMessage = json_tokener_parse(payload);
  17221. if(!is_error(TriggerMessage))
  17222. {
  17223. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  17224. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  17225. // Required data
  17226. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  17227. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  17228. // Optional data
  17229. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  17230. {
  17231. // Required data
  17232. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  17233. {
  17234. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  17235. evseIdInt = ShmOCPP20Data->TriggerMessage.evse.id;
  17236. }
  17237. else
  17238. evseIdIsNULL = TRUE;
  17239. // Optional data
  17240. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  17241. {
  17242. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  17243. //connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  17244. }
  17245. //else
  17246. //connectorIdIsNULL = TRUE;
  17247. }
  17248. else
  17249. evseIdIsNULL = TRUE;
  17250. }
  17251. json_object_put(TriggerMessage);
  17252. if((evseIdIsNULL == TRUE) || ((evseIdIsNULL == FALSE) && ((evseIdInt > 0) && (evseIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  17253. {
  17254. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  17255. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  17256. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  17257. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  17258. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  17259. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  17260. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  17261. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  17262. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  17263. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  17264. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  17265. {
  17266. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  17267. sendTriggerMessageConfirmation(uuid);
  17268. return TRUE;
  17269. }
  17270. else
  17271. {
  17272. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  17273. sendTriggerMessageConfirmation(uuid);
  17274. }
  17275. }
  17276. else if(evseIdIsNULL == FALSE && ((evseIdInt <= 0) || (evseIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  17277. {
  17278. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17279. sendTriggerMessageConfirmation(uuid);
  17280. return TRUE;
  17281. }
  17282. //==========================
  17283. // Trigger message
  17284. //==========================
  17285. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  17286. {
  17287. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  17288. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  17289. {
  17290. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  17291. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17292. }
  17293. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17294. }
  17295. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  17296. {
  17297. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  17298. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  17299. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  17300. }
  17301. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  17302. {
  17303. if(server_sign)
  17304. {
  17305. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17306. sendTriggerMessageConfirmation(uuid);
  17307. return TRUE;
  17308. }
  17309. else
  17310. {
  17311. if(DB_updateBootType(BootReasonEnumType_Triggered))
  17312. server_sign = FALSE;
  17313. }
  17314. }
  17315. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  17316. {
  17317. refreshStartTimer(&clientTime.Heartbeat);
  17318. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  17319. }
  17320. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  17321. {
  17322. if(evseIdIsNULL == FALSE)
  17323. {
  17324. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17325. {
  17326. cpinitateMsg.bits[evseIdInt-1].TriggerMeterValueReq = ON;
  17327. }
  17328. }
  17329. else
  17330. {
  17331. for(int idx=0;idx< gunTotalNumber;idx++)
  17332. {
  17333. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  17334. }
  17335. }
  17336. }
  17337. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  17338. {
  17339. if(evseIdIsNULL == FALSE)
  17340. {
  17341. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17342. {
  17343. cpinitateMsg.bits[evseIdInt-1].TriggerStatusNotificationReq = ON;
  17344. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  17345. }
  17346. }
  17347. else
  17348. {
  17349. for(int idx=0;idx< gunTotalNumber;idx++)
  17350. {
  17351. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  17352. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  17353. }
  17354. }
  17355. }
  17356. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  17357. {
  17358. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17359. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17360. {
  17361. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  17362. }
  17363. }
  17364. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  17365. {
  17366. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17367. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17368. {
  17369. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certV2G.csr -nodes -keyout /Storage/OCPP/certV2G.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  17370. }
  17371. }
  17372. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  17373. {
  17374. if(evseIdIsNULL == FALSE)
  17375. {
  17376. if((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber))
  17377. {
  17378. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  17379. cpinitateMsg.bits[evseIdInt -1].TriggerTransactionEventReq = ON;
  17380. }
  17381. }
  17382. else
  17383. {
  17384. for(int idx=0;idx< gunTotalNumber;idx++)
  17385. {
  17386. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  17387. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  17388. }
  17389. }
  17390. }
  17391. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  17392. {
  17393. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17394. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17395. {
  17396. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  17397. }
  17398. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17399. {
  17400. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certV2G.csr -nodes -keyout /Storage/OCPP/certV2G.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  17401. }
  17402. }
  17403. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  17404. {
  17405. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  17406. }
  17407. return result;
  17408. }
  17409. int handleUnlockConnectorRequest(char *uuid, char *payload)
  17410. {
  17411. mtrace();
  17412. int result = FAIL;
  17413. int evseIdInt =0;
  17414. int tempIndex = 0;
  17415. json_object *UnlockConnector;
  17416. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  17417. UnlockConnector = json_tokener_parse(payload);
  17418. if(!is_error(UnlockConnector))
  17419. {
  17420. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  17421. {
  17422. evseIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  17423. ShmOCPP20Data->UnlockConnector[(evseIdInt>0?evseIdInt-1:0)].evseId = evseIdInt;
  17424. //it should not be array!!
  17425. }
  17426. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  17427. {
  17428. if(json_object_get_int(json_object_object_get(UnlockConnector, "connectorId")) != 1)
  17429. {
  17430. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17431. goto end;
  17432. }
  17433. }
  17434. }
  17435. json_object_put(UnlockConnector);
  17436. DEBUG_INFO("Unlock evseIdInt = %d\n",evseIdInt);
  17437. if(gunTotalNumber == 0)
  17438. {
  17439. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17440. goto end;
  17441. }
  17442. else if((evseIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (evseIdInt <= 0))
  17443. {
  17444. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17445. goto end;
  17446. }
  17447. else
  17448. {
  17449. memset(&ShmOCPP20Data->UnlockConnector[evseIdInt-1], 0, sizeof(struct UnlockConnector_20));
  17450. memcpy(&ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid));
  17451. //check Transaction active
  17452. if(gunType[evseIdInt-1] == GUN_TYPE_CHAdeMO)
  17453. {
  17454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17455. {
  17456. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17457. }
  17458. else
  17459. {
  17460. tempIndex = evseIdInt -1;
  17461. }
  17462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17463. {
  17464. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  17465. {
  17466. //stop Transaction
  17467. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17468. }
  17469. }
  17470. }
  17471. else if(gunType[evseIdInt-1] == GUN_TYPE_CCS)
  17472. {
  17473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17474. {
  17475. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17476. }
  17477. else
  17478. {
  17479. tempIndex = evseIdInt -1;
  17480. }
  17481. for (int index = 0; index < CCS_QUANTITY; index++)
  17482. {
  17483. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  17484. {
  17485. //stop Transaction
  17486. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17487. }
  17488. }
  17489. }
  17490. else if(gunType[evseIdInt-1] == GUN_TYPE_GBT)
  17491. {
  17492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17493. {
  17494. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17495. }
  17496. else
  17497. {
  17498. tempIndex = evseIdInt -1;
  17499. }
  17500. for (int index = 0; index < GB_QUANTITY; index++)
  17501. {
  17502. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  17503. {
  17504. //stop Transaction
  17505. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17506. }
  17507. }
  17508. }
  17509. else if(gunType[evseIdInt-1] == GUN_TYPE_DO)
  17510. {
  17511. tempIndex = evseIdInt -1;
  17512. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17513. {
  17514. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  17515. {
  17516. //stop Transaction
  17517. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17518. }
  17519. }
  17520. }
  17521. else
  17522. {
  17523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17524. {
  17525. tempIndex = 2;
  17526. }
  17527. else
  17528. {
  17529. tempIndex = evseIdInt-1;
  17530. }
  17531. for (int index = 0; index < AC_QUANTITY; index++)
  17532. {
  17533. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  17534. {
  17535. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17536. }
  17537. }
  17538. }
  17539. ShmOCPP20Data->UnlockConnector[evseIdInt-1].connectorId = evseIdInt;
  17540. strcpy((char *)ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid);
  17541. result = TRUE;
  17542. return result;
  17543. }
  17544. end:
  17545. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorConf = ON;
  17546. return result;
  17547. }
  17548. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  17549. {
  17550. mtrace();
  17551. int result = FAIL;
  17552. json_object *UnpublishFirmware;
  17553. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  17554. UnpublishFirmware = json_tokener_parse(payload);
  17555. if(!is_error(UnpublishFirmware))
  17556. {
  17557. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  17558. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  17559. // Required data
  17560. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  17561. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  17562. }
  17563. json_object_put(UnpublishFirmware);
  17564. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  17565. /*
  17566. * TODO:
  17567. * 1. Check unpublished status
  17568. */
  17569. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  17570. sendUnpublishFirmwareConfirmation(uuid);
  17571. return result;
  17572. }
  17573. static char UpdateFirmwarepayloadData[512]={0};
  17574. void *UpdateFirmwareProcess(void *data)
  17575. {
  17576. pthread_detach(pthread_self());
  17577. mtrace();
  17578. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  17579. int port=0;
  17580. int isSuccess = 0;
  17581. char ftpbuf[1024];
  17582. char temp[1024];
  17583. char * pch;
  17584. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  17585. json_object *UpdateFirmware;
  17586. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  17587. if(!is_error(UpdateFirmware))
  17588. {
  17589. // Required data
  17590. if(json_object_object_get(UpdateFirmware, "requestId"))
  17591. {
  17592. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  17593. }
  17594. if(json_object_object_get(UpdateFirmware, "firmware"))
  17595. {
  17596. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  17597. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  17598. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  17599. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  17600. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  17601. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  17602. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  17603. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  17604. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  17605. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  17606. }
  17607. // Optional data
  17608. if(json_object_object_get(UpdateFirmware, "retries"))
  17609. {
  17610. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  17611. }
  17612. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  17613. {
  17614. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  17615. }
  17616. }
  17617. json_object_put(UpdateFirmware);
  17618. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  17619. memset(path, 0, ARRAY_SIZE(path));
  17620. // Wait retrieveData
  17621. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  17622. {
  17623. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17624. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  17625. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17626. do
  17627. {
  17628. sleep(1);
  17629. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  17630. }
  17631. system("rm -f /mnt/*");
  17632. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  17633. {
  17634. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  17635. sprintf(ftppath,"/%s", path);
  17636. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  17637. DEBUG_INFO("protocol: %s\n",protocol);
  17638. DEBUG_INFO("host: %s\n",host);
  17639. DEBUG_INFO("path: %s\n",path);
  17640. DEBUG_INFO("ftppath: %s\n",ftppath);
  17641. int ftppathlen=strlen(ftppath);
  17642. int i=1;
  17643. char filenametemp[50];
  17644. while(i < ftppathlen)
  17645. {
  17646. int len=ftppathlen-i;
  17647. if(ftppath[len]== 47) // '/' ascll code: 47
  17648. {
  17649. DEBUG_INFO("compare '/' all right\n");
  17650. break;
  17651. }
  17652. i=i+1;
  17653. }
  17654. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  17655. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  17656. filenametemp[i+1] = 0;
  17657. do
  17658. {
  17659. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17660. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17661. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17662. sleep(3);
  17663. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17664. if(!isSuccess)
  17665. {
  17666. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17667. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17668. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17669. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17670. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17671. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17672. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17673. }
  17674. else
  17675. {
  17676. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17677. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17678. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17679. }
  17680. ShmOCPP20Data->UpdateFirmware.retries--;
  17681. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17682. }
  17683. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  17684. {
  17685. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17686. memset(temp, 0, ARRAY_SIZE(temp));
  17687. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17688. int ftppathlen=strlen(ftpbuf);
  17689. int i=1;
  17690. char filenametemp[50];
  17691. while(i < ftppathlen)
  17692. {
  17693. int len=ftppathlen-i;
  17694. if(ftpbuf[len]== 47) // '/' ascll code: 47
  17695. {
  17696. DEBUG_INFO(" compare '/' all right\n");
  17697. break;
  17698. }
  17699. i=i+1;
  17700. }
  17701. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  17702. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  17703. filenametemp[i+1] = 0;
  17704. strncpy(temp, ftpbuf, ftppathlen-i+1);
  17705. pch=strchr(temp,'@');
  17706. if(pch==NULL)
  17707. {
  17708. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17709. protocol, host, &port, path);
  17710. strcpy(user,"anonymous");
  17711. strcpy(password,"");
  17712. }
  17713. else
  17714. {
  17715. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  17716. protocol, user, password, host, &port, path);
  17717. }
  17718. sscanf(host,"%[^/]%s",host1, path1);
  17719. sprintf(ftppath,"%s", path1);
  17720. if(port == 0)
  17721. {
  17722. port = 21;
  17723. }
  17724. do
  17725. {
  17726. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17727. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17728. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17729. sleep(3);
  17730. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17731. if(!isSuccess)
  17732. {
  17733. //BulldogUtil.sleepMs(interval*1000);
  17734. DEBUG_INFO("Update firmware request and download file fail.\n");
  17735. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17736. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17737. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17738. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17739. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17740. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17741. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17742. }
  17743. else
  17744. {
  17745. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17746. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17747. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17748. }
  17749. ShmOCPP20Data->UpdateFirmware.retries--;
  17750. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17751. }
  17752. else
  17753. {
  17754. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17755. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17756. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17757. sleep(1);
  17758. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17759. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17760. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17761. }
  17762. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  17763. interLock.isUpdateFirmwareGoing = OFF;
  17764. pthread_exit(NULL);
  17765. }
  17766. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  17767. {
  17768. mtrace();
  17769. int result = FAIL;
  17770. pthread_t t;
  17771. sendUpdateFirmwareConfirmation(uuid);
  17772. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  17773. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  17774. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  17775. if(!interLock.isUpdateFirmwareGoing)
  17776. {
  17777. interLock.isUpdateFirmwareGoing = ON;
  17778. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  17779. sleep(1);
  17780. }
  17781. else
  17782. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  17783. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  17784. return result;
  17785. }
  17786. int handleUnknownRequest(char *uuid, char *payload)
  17787. {
  17788. mtrace();
  17789. int result = FAIL;
  17790. DEBUG_INFO("handleUnknownRequest...\n");
  17791. sendUnknownConfirmation(uuid);
  17792. result = PASS;
  17793. return result;
  17794. }
  17795. //==========================================
  17796. // Handle server response routine
  17797. //==========================================
  17798. void handleAuthorizeResponse(char *payload, int gun_index)
  17799. {
  17800. mtrace();
  17801. DEBUG_INFO("handleAuthorizeResponse...\n");
  17802. json_object *Authorize;
  17803. Authorize = json_tokener_parse(payload);
  17804. if(!is_error(Authorize))
  17805. {
  17806. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  17807. {
  17808. // Required data
  17809. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  17810. // Optional data
  17811. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  17812. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  17813. else
  17814. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  17815. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  17816. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  17817. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  17818. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  17819. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  17820. {
  17821. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  17822. {
  17823. ShmOCPP20Data->Authorize.Response_idTokenInfo.evseId[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId"), idx));
  17824. }
  17825. }
  17826. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  17827. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  17828. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  17829. {
  17830. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  17831. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken")));
  17832. else
  17833. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  17834. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  17835. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type")));
  17836. }
  17837. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  17838. {
  17839. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  17840. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.personalMessage.format, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format")));
  17841. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  17842. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.personalMessage.language, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language")));
  17843. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  17844. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.personalMessage.content, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content")));
  17845. }
  17846. }
  17847. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  17848. {
  17849. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  17850. }
  17851. }
  17852. json_object_put(Authorize);
  17853. //Update idTag information to authorization cache if supported
  17854. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  17855. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  17856. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  17857. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  17858. {
  17859. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  17860. }
  17861. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  17862. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  17863. authorizeRetryTimes = 0;
  17864. }
  17865. void handleBootNotificationResponse(char *payload, int gun_index)
  17866. {
  17867. mtrace();
  17868. char statusStr[12]={0};
  17869. char currentTimeStr[30]={0};
  17870. int intervalInt = 0;
  17871. DEBUG_INFO("handleBootNotificationResponse...\n");
  17872. json_object *BootNotification;
  17873. BootNotification = json_tokener_parse(payload);
  17874. if(!is_error(BootNotification))
  17875. {
  17876. // Required data
  17877. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  17878. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  17879. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  17880. }
  17881. json_object_put(BootNotification);
  17882. DEBUG_INFO("statusStr: %s\n", statusStr);
  17883. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  17884. BootNotificationInterval = intervalInt;
  17885. //write back to ShmOCPP20Data->BootNotification
  17886. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  17887. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  17888. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  17889. {
  17890. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  17891. {
  17892. //Do nothing because the value is out of range.
  17893. }
  17894. else
  17895. {
  17896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  17897. HeartBeatWaitTime = intervalInt;
  17898. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  17899. }
  17900. server_sign = TRUE;
  17901. server_pending =FALSE;
  17902. DB_updateBootType(BootReasonEnumType_PowerUp);
  17903. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  17904. }
  17905. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  17906. {
  17907. server_pending = TRUE;
  17908. }
  17909. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  17910. srand(time(NULL));
  17911. refreshStartTimer(&clientTime.Heartbeat);
  17912. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  17913. SetOcppConnStatus(TRUE);
  17914. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  17915. }
  17916. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  17917. {
  17918. mtrace();
  17919. json_object *ClearedChargingLimit;
  17920. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  17921. ClearedChargingLimit = json_tokener_parse(payload);
  17922. if(!is_error(ClearedChargingLimit))
  17923. {
  17924. // Required data
  17925. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  17926. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  17927. }
  17928. json_object_put(ClearedChargingLimit);
  17929. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  17930. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  17931. }
  17932. void handleDataTransferResponse(char *payload, int gun_index)
  17933. {
  17934. mtrace();
  17935. json_object *DataTrans;
  17936. DEBUG_INFO("handleDataTransferResponse...\n");
  17937. DataTrans = json_tokener_parse(payload);
  17938. if(!is_error(DataTrans))
  17939. {
  17940. // Required data
  17941. if(json_object_object_get(DataTrans,"status") != NULL)
  17942. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  17943. // Optional data
  17944. if(json_object_object_get(DataTrans,"data") != NULL)
  17945. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  17946. }
  17947. json_object_put(DataTrans);
  17948. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  17949. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  17950. }
  17951. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17952. {
  17953. mtrace();
  17954. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  17955. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  17956. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  17957. }
  17958. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  17959. {
  17960. mtrace();
  17961. json_object *Get15118EVCertificate;
  17962. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  17963. Get15118EVCertificate = json_tokener_parse(payload);
  17964. if(!is_error(Get15118EVCertificate))
  17965. {
  17966. // Required data
  17967. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  17968. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  17969. // Optional data
  17970. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  17971. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  17972. }
  17973. json_object_put(Get15118EVCertificate);
  17974. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  17975. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  17976. }
  17977. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  17978. {
  17979. mtrace();
  17980. json_object *GetCertificateStatus;
  17981. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  17982. GetCertificateStatus = json_tokener_parse(payload);
  17983. if(!is_error(GetCertificateStatus))
  17984. {
  17985. // Required data
  17986. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  17987. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  17988. // Optional data
  17989. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  17990. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  17991. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  17992. {
  17993. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  17994. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  17995. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  17996. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  17997. }
  17998. }
  17999. json_object_put(GetCertificateStatus);
  18000. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  18001. {
  18002. /*
  18003. * TODO:
  18004. * 1. If get certificate response accepted process something here
  18005. */
  18006. }
  18007. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  18008. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  18009. }
  18010. void handleHeartbeatResponse(char *payload, int gun_index)
  18011. {
  18012. mtrace();
  18013. DEBUG_INFO("handleHeartbeatResponse...\n");
  18014. json_object *Heartbeat;
  18015. Heartbeat = json_tokener_parse(payload);
  18016. if(!is_error(Heartbeat))
  18017. {
  18018. // Required data
  18019. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  18020. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  18021. }
  18022. json_object_put(Heartbeat);
  18023. if(FirstHeartBeat == OFF)
  18024. {
  18025. FirstHeartBeat = ON;
  18026. DEBUG_INFO("FirstHeartBeat \n");
  18027. }
  18028. HeartBeatWithNOResponse = 0;
  18029. refreshStartTimer(&clientTime.Heartbeat);
  18030. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  18031. }
  18032. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  18033. {
  18034. mtrace();
  18035. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  18036. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  18037. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  18038. }
  18039. void handleMeterValuesResponse(char *payload, int gun_index)
  18040. {
  18041. mtrace();
  18042. DEBUG_INFO("handleMeterValuesResponse...\n");
  18043. isQueueSendable = ON;
  18044. }
  18045. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  18046. {
  18047. mtrace();
  18048. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  18049. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18050. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18051. }
  18052. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  18053. {
  18054. mtrace();
  18055. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  18056. }
  18057. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  18058. {
  18059. mtrace();
  18060. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  18061. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  18062. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  18063. }
  18064. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  18065. {
  18066. mtrace();
  18067. json_object *NotifyEVChargingNeeds;
  18068. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  18069. NotifyEVChargingNeeds = json_tokener_parse(payload);
  18070. if(!is_error(NotifyEVChargingNeeds))
  18071. {
  18072. // Required data
  18073. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  18074. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  18075. }
  18076. json_object_put(NotifyEVChargingNeeds);
  18077. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18078. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18079. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  18080. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  18081. }
  18082. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  18083. {
  18084. mtrace();
  18085. json_object *NotifyEVChargingSchedule;
  18086. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  18087. NotifyEVChargingSchedule = json_tokener_parse(payload);
  18088. if(!is_error(NotifyEVChargingSchedule))
  18089. {
  18090. // Required data
  18091. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  18092. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  18093. }
  18094. json_object_put(NotifyEVChargingSchedule);
  18095. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  18096. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  18097. }
  18098. void handleNotifyEventResponse(char *payload, int gun_index)
  18099. {
  18100. mtrace();
  18101. DEBUG_INFO("handleNotifyEventResponse...\n");
  18102. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  18103. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  18104. }
  18105. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  18106. {
  18107. mtrace();
  18108. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  18109. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  18110. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  18111. }
  18112. void handleNotifyReportResponse(char *payload, int gun_index)
  18113. {
  18114. mtrace();
  18115. DEBUG_INFO("handleNotifyReportResponse...\n");
  18116. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  18117. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  18118. }
  18119. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18120. {
  18121. mtrace();
  18122. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  18123. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  18124. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  18125. }
  18126. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  18127. {
  18128. mtrace();
  18129. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  18130. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  18131. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  18132. }
  18133. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  18134. {
  18135. mtrace();
  18136. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  18137. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  18138. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  18139. }
  18140. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  18141. {
  18142. mtrace();
  18143. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  18144. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  18145. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  18146. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  18147. }
  18148. void handleSignCertificateResponse(char *payload, int gun_index)
  18149. {
  18150. mtrace();
  18151. json_object *SignCertificate;
  18152. DEBUG_INFO("handleSignCertificateResponse...\n");
  18153. SignCertificate = json_tokener_parse(payload);
  18154. if(!is_error(SignCertificate))
  18155. {
  18156. // Required data
  18157. if(json_object_object_get(SignCertificate,"status") != NULL)
  18158. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  18159. // Optional data
  18160. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  18161. {
  18162. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  18163. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  18164. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  18165. }
  18166. }
  18167. json_object_put(SignCertificate);
  18168. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  18169. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  18170. }
  18171. void handleStatusNotificationResponse(char *payload, int gun_index)
  18172. {
  18173. mtrace();
  18174. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  18175. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18176. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18177. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  18178. }
  18179. void handleTransactionEventResponse(char *payload, int gun_index)
  18180. {
  18181. mtrace();
  18182. json_object *TransactionEven;
  18183. DEBUG_INFO("handleTransactionEventResponse...\n");
  18184. TransactionEven = json_tokener_parse(payload);
  18185. if(!is_error(TransactionEven))
  18186. {
  18187. // Required data
  18188. // Optional data
  18189. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  18190. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  18191. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  18192. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  18193. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  18194. {
  18195. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  18196. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  18197. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18198. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  18199. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  18200. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  18201. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  18202. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  18203. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  18204. {
  18205. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18206. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.groupIdToken.idToken, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken")));
  18207. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18208. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.groupIdToken.type, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type")));
  18209. }
  18210. }
  18211. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  18212. {
  18213. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  18214. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  18215. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  18216. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  18217. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  18218. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  18219. }
  18220. }
  18221. json_object_put(TransactionEven);
  18222. isQueueSendable = ON;
  18223. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  18224. }
  18225. //==========================================
  18226. // Handle Error routine
  18227. //==========================================
  18228. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  18229. {
  18230. mtrace();
  18231. #ifdef SystemLogMessage
  18232. DEBUG_INFO("errorCode: %s\n", errorCode);
  18233. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  18234. DEBUG_INFO("errorDetails: %s\n", payload);
  18235. #endif
  18236. }
  18237. //===============================================
  18238. // Common routine
  18239. //===============================================
  18240. int initialConfigurationTable(void)
  18241. {
  18242. DEBUG_INFO("initialConfigurationTable...\n");
  18243. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  18244. DB_variableIsCreate();
  18245. DB_variableLoadFromDb();
  18246. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  18247. {
  18248. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  18249. DB_variableClear();
  18250. DB_variableIsCreate();
  18251. DB_variableLoadFromDb();
  18252. }
  18253. DB_getNetworkProfileFromDb();
  18254. return 0;
  18255. }
  18256. int TransactionMessageAttemptsGet(void)
  18257. {
  18258. return TransactionMessageAttemptsValue;
  18259. }
  18260. int FirstHeartBeatResponse(void)
  18261. {
  18262. return FirstHeartBeat;
  18263. }
  18264. int TransactionMessageRetryIntervalGet(void)
  18265. {
  18266. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18267. }
  18268. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18269. {
  18270. int result = TRUE;
  18271. char rmFileCmd[100]={0};
  18272. char FilePath[100]={0};
  18273. char ftpbuf[200];
  18274. int systemresult;
  18275. sprintf(FilePath,"/mnt/%s",filename);
  18276. system("ping 8.8.8.8 &");
  18277. if((access(FilePath,F_OK))!=-1)
  18278. {
  18279. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18280. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18281. system(rmFileCmd);
  18282. }
  18283. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18284. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18285. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18286. systemresult = system(ftpbuf);
  18287. if(systemresult != 0)
  18288. {
  18289. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  18290. result = FALSE;
  18291. }
  18292. system("pkill ping");
  18293. return result;
  18294. }
  18295. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18296. {
  18297. int result = TRUE;
  18298. char rmFileCmd[100]={0};
  18299. char FilePath[100]={0};
  18300. char ftpbuf[200];
  18301. int systemresult;
  18302. sprintf(FilePath,"/mnt/%s",filename);
  18303. system("ping 8.8.8.8 &");
  18304. if((access(FilePath,F_OK))!=-1)
  18305. {
  18306. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18307. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18308. system(rmFileCmd);
  18309. }
  18310. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18311. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18312. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18313. systemresult = system(ftpbuf);
  18314. if(systemresult != 0)
  18315. {
  18316. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18317. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18318. systemresult = system(ftpbuf);
  18319. if(systemresult != 0)
  18320. {
  18321. DEBUG_WARN("FTP download fail!\n");
  18322. result = FALSE;
  18323. }
  18324. }
  18325. system("pkill ping");
  18326. return result;
  18327. }
  18328. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18329. {
  18330. char rmFileCmd[100]={0};
  18331. char FilePath[100]={0};
  18332. char buf[512];
  18333. int systemresult = 0;
  18334. //DEBUG_INFO("filename=%s\n",filename);
  18335. //DEBUG_INFO("url=%s\n",url);
  18336. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18337. if((access(FilePath,F_OK))!=-1)
  18338. {
  18339. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18340. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18341. system(rmFileCmd);
  18342. }
  18343. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18344. if(fp == NULL)
  18345. {
  18346. DEBUG_INFO("log is NULL\n");
  18347. return FALSE;
  18348. }
  18349. else
  18350. {
  18351. fprintf(fp, "%s\n", url);
  18352. fprintf(fp, "%s\n", filename);
  18353. fclose(fp);
  18354. }
  18355. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18356. if(phpFP == NULL)
  18357. {
  18358. DEBUG_INFO("PHP upload fail.\n");
  18359. return FALSE;
  18360. }
  18361. else
  18362. {
  18363. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18364. {
  18365. if(strstr(buf, "result") != NULL)
  18366. {
  18367. sscanf(buf, "result: %d", &systemresult);
  18368. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18369. }
  18370. }
  18371. pclose(phpFP);
  18372. }
  18373. if(systemresult != 1)
  18374. {
  18375. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18376. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18377. if(phpFP == NULL)
  18378. {
  18379. DEBUG_WARN("PHP PUT upload fail.\n");
  18380. return FALSE;
  18381. }
  18382. else
  18383. {
  18384. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18385. {
  18386. if(strstr(buf, "result") != NULL)
  18387. {
  18388. sscanf(buf, "result: %d", &systemresult);
  18389. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18390. }
  18391. }
  18392. pclose(phpFP);
  18393. }
  18394. }
  18395. if(systemresult != 1)
  18396. {
  18397. DEBUG_WARN("PHP PUT upload fail.\n");
  18398. return FALSE;
  18399. }
  18400. return TRUE;
  18401. }
  18402. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18403. {
  18404. int result = FALSE;
  18405. char ftpbuf[200];
  18406. int systemresult;
  18407. /*
  18408. // Domaind name transfer to IP address
  18409. struct hostent* server;
  18410. char *IPbuffer;
  18411. server = gethostbyname(location);
  18412. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18413. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18414. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18415. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18416. systemresult = system(ftpbuf);
  18417. if(systemresult != 0)
  18418. {
  18419. DEBUG_INFO("ftpput error!\n");
  18420. }
  18421. else
  18422. {
  18423. result = TRUE;
  18424. DEBUG_INFO("ftpput OK!\n");
  18425. }
  18426. return result;
  18427. }
  18428. //=========================================
  18429. // Routine
  18430. //=========================================
  18431. int GetOcppServerURL()
  18432. {
  18433. int result = FALSE;
  18434. struct yuarel url;
  18435. char urlStr[512];
  18436. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18437. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18438. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18439. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  18440. {
  18441. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  18442. if(yuarel_parse(&url, urlStr) != -1)
  18443. {
  18444. sprintf(OcppProtocol, "%s", url.scheme);
  18445. sprintf(OcppHost, "%s", url.host);
  18446. if(url.path == NULL)
  18447. OcppTempPath[0] = '\0';
  18448. else
  18449. sprintf(OcppTempPath, "%s", url.path);
  18450. if(url.port == 0)
  18451. {
  18452. if(strcmp(OcppProtocol, "wss") == 0)
  18453. OcppPort = 443;
  18454. else
  18455. OcppPort = 80;
  18456. }
  18457. else
  18458. OcppPort = url.port;
  18459. result = TRUE;
  18460. }
  18461. }
  18462. else
  18463. {
  18464. strcpy(OcppHost,"");
  18465. }
  18466. return result;
  18467. }
  18468. int GetOcppPath()
  18469. {
  18470. int result = FALSE;
  18471. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18472. {
  18473. if(OcppTempPath == NULL)
  18474. {
  18475. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18476. }
  18477. else
  18478. {
  18479. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18480. }
  18481. result = TRUE;
  18482. }
  18483. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  18484. {
  18485. if(OcppTempPath == NULL)
  18486. {
  18487. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  18488. }
  18489. else
  18490. {
  18491. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  18492. }
  18493. result = TRUE;
  18494. }
  18495. else
  18496. {
  18497. strcpy(OcppPath,"");
  18498. }
  18499. return result;
  18500. }
  18501. int GetOcppPort()
  18502. {
  18503. return OcppPort;
  18504. }
  18505. int GetOcppConnStatus(void)
  18506. {
  18507. return ShmOCPP20Data->OcppConnStatus;
  18508. }
  18509. void SetOcppConnStatus(uint8_t status)
  18510. {
  18511. ShmOCPP20Data->OcppConnStatus = status;
  18512. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18513. }
  18514. int GetHeartBeatWithNOResponse(void)
  18515. {
  18516. return HeartBeatWithNOResponse;
  18517. }
  18518. void SetHeartBeatWithNOResponse(void)
  18519. {
  18520. HeartBeatWithNOResponse = 0;
  18521. }
  18522. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18523. void storeTempStopTransaction(int gun_index)
  18524. {
  18525. char TempStopTransaction[256];
  18526. //char message[1024*20]={0};
  18527. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  18528. char guid[37]={0};
  18529. json_object *TransactionEvent = json_object_new_object();
  18530. json_object *transactionInfo = json_object_new_object();
  18531. json_object *idToken = json_object_new_object();
  18532. json_object *evse = json_object_new_object();
  18533. json_object *meterValues = json_object_new_array();
  18534. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18535. DEBUG_INFO("storeTempStopTransaction...\n");
  18536. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  18537. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  18538. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  18539. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  18540. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  18541. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  18542. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  18543. // Message
  18544. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  18545. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  18546. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  18547. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  18548. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  18549. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  18550. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  18551. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  18552. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  18553. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  18554. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  18555. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  18556. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  18557. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  18558. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  18559. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  18560. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  18561. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  18562. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  18563. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  18564. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  18565. {
  18566. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  18567. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  18568. json_object_object_add(TransactionEvent, "idToken", idToken);
  18569. }
  18570. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  18571. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  18572. json_object_object_add(TransactionEvent, "evse", evse);
  18573. meterValueBufferQuery(gun_index, meterValues);
  18574. if(json_object_array_length(meterValues) > 0)
  18575. {
  18576. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  18577. }
  18578. random_uuid(guid);
  18579. sprintf(queuedata,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  18580. , guid
  18581. , "TransactionEvent"
  18582. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  18583. json_object_put(TransactionEvent);
  18584. // open file for writing
  18585. FILE *outfile;
  18586. outfile = fopen (TempStopTransaction, "w+");
  18587. //DEBUG_INFO("data = %s\n", queuedata);
  18588. fputs(queuedata, outfile);
  18589. fputs("\n", outfile);
  18590. fclose (outfile);
  18591. }
  18592. void checkTempStopTransaction(int gun_index)
  18593. {
  18594. FILE *fptr1;
  18595. char ch;
  18596. char str[QUEUE_MESSAGE_LENGTH]={0};
  18597. char guid[37]={0};
  18598. char tempdata[65]={0};
  18599. char TempStopTransaction[256];
  18600. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18601. fptr1 = fopen(TempStopTransaction, "r");
  18602. if (!fptr1)
  18603. {
  18604. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  18605. return ;
  18606. }
  18607. ch=fgetc(fptr1);
  18608. rewind(fptr1);
  18609. if(ch!=EOF)
  18610. {
  18611. // copy all contents to the temporary file except the specific line
  18612. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18613. {
  18614. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18615. if(str[0]=='\0')
  18616. {
  18617. break;
  18618. }
  18619. strncpy(guid, str+4, 36); //copy guid
  18620. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  18621. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18622. {
  18623. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18624. }
  18625. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18626. memset(str,0,ARRAY_SIZE(str));
  18627. }
  18628. }
  18629. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18630. fclose(fptr1);
  18631. remove(TempStopTransaction); // remove the original file
  18632. }
  18633. int GetWebSocketPingInterval(void)
  18634. {
  18635. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  18636. }
  18637. int GetServerSign(void)
  18638. {
  18639. return server_sign;
  18640. }
  18641. uint8_t GetOcppSecurityProfile()
  18642. {
  18643. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  18644. }
  18645. void MergeCertificates()
  18646. {
  18647. char cmdBuf[2048]={0};
  18648. if(access(ROOTCA_CS,F_OK) != -1)
  18649. {
  18650. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  18651. }
  18652. else
  18653. {
  18654. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  18655. }
  18656. system(cmdBuf);
  18657. }
  18658. void GetOcppChargerBoxId(uint8_t *data)
  18659. {
  18660. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18661. }
  18662. void GetOcppSecurityPassword(uint8_t *data)
  18663. {
  18664. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  18665. }
  18666. void SetServerSign(int value)
  18667. {
  18668. server_sign = value;
  18669. }
  18670. int GetBootNotificationInterval(void)
  18671. {
  18672. return BootNotificationInterval;
  18673. }
  18674. int GetInternetConn(void)
  18675. {
  18676. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18677. }
  18678. int GetBackendConnectionTimeout(void)
  18679. {
  18680. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18681. }
  18682. int isConnectorInitMode(int gun_index)
  18683. {
  18684. int tempIndex = 0;
  18685. int result = TRUE;
  18686. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18687. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18688. {
  18689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18690. {
  18691. tempIndex = ((gun_index==2) ? 1: 0);
  18692. }
  18693. else
  18694. {
  18695. tempIndex = gun_index;
  18696. }
  18697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18698. {
  18699. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18700. {
  18701. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18702. } //end of the same index
  18703. }//end of for CHAdeMO_QUANTITY
  18704. }
  18705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18706. {
  18707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18708. {
  18709. tempIndex = ((gun_index==2) ? 1: 0);
  18710. }
  18711. else
  18712. {
  18713. tempIndex = gun_index;
  18714. }
  18715. for (int index = 0; index < CCS_QUANTITY; index++)
  18716. {
  18717. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18718. {
  18719. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18720. } //end of the same index
  18721. } // end of for CCS_QUANTITY
  18722. }
  18723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18724. {
  18725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18726. {
  18727. tempIndex = ((gun_index==2) ? 1: 0);
  18728. }
  18729. else
  18730. {
  18731. tempIndex = gun_index;
  18732. }
  18733. for (int index = 0; index < GB_QUANTITY; index++)
  18734. {
  18735. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18736. {
  18737. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18738. } //end of the same index
  18739. } // end of for GB_QUANTITY
  18740. }
  18741. else if(gunType[gun_index] == GUN_TYPE_DO)
  18742. {
  18743. tempIndex = gun_index;
  18744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18745. {
  18746. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18747. {
  18748. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18749. } //end of the same index
  18750. }
  18751. }
  18752. else
  18753. {
  18754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18755. {
  18756. tempIndex = 2;
  18757. }
  18758. else
  18759. {
  18760. tempIndex = gun_index;
  18761. }
  18762. for (int index = 0; index < AC_QUANTITY; index++)
  18763. {
  18764. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18765. {
  18766. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18767. }//end of the same index
  18768. }//end of for AC_QUANTITY
  18769. }
  18770. return result;
  18771. }
  18772. void refreshProcDogTimer()
  18773. {
  18774. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  18775. }
  18776. void InitialSystemValue(void)
  18777. {
  18778. localversion=0;
  18779. BootNotificationInterval = 10;
  18780. authorizeRetryTimes = 0;
  18781. GunStatusInterval = 10;
  18782. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  18783. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  18784. //Heart Beat
  18785. HeartBeatWithNOResponse = 0;
  18786. HeartBeatCountPerHour = 0;
  18787. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  18788. if(HeartBeatWaitTime == 0)
  18789. FirstHeartBeat = TRUE;
  18790. else
  18791. FirstHeartBeat = FALSE;
  18792. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  18793. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  18794. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18795. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18796. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18797. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18798. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18799. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18800. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18801. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18802. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18803. //Status && ConnectorPlugIn Setting
  18804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18805. {
  18806. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18807. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18808. }
  18809. for (int index = 0; index < CCS_QUANTITY; index++)
  18810. {
  18811. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18812. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18813. }
  18814. for (int index = 0; index < GB_QUANTITY; index++)
  18815. {
  18816. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18817. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18818. }
  18819. for (int index = 0; index < AC_QUANTITY; index++)
  18820. {
  18821. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18822. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18823. }
  18824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18825. {
  18826. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18827. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18828. }
  18829. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18830. {
  18831. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18832. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18833. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  18834. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18835. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  18836. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  18837. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  18838. }
  18839. refreshStartTimer(&clientTime.Heartbeat);
  18840. sleep(1);
  18841. }
  18842. void LWS_Send(char *str)
  18843. {
  18844. //=====================================================
  18845. // Check InternetConn 0: disconnected, 1: connected
  18846. //====================================================
  18847. if(GetOcppConnStatus() == 0)
  18848. {
  18849. DEBUG_INFO("offline now !!!\n");
  18850. return;
  18851. }
  18852. // Only disable isWebsocketSendable operation initiated by charger
  18853. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18854. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18855. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18856. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18857. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18858. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18859. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18860. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18861. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18862. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18863. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18864. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18865. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18866. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18867. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18868. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18869. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18870. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18871. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18872. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18873. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18874. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18875. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18876. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18877. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18878. {
  18879. isWebsocketSendable = OFF;
  18880. }
  18881. pthread_mutex_lock(&lock_send);
  18882. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18883. sprintf((char *)SendBuffer, "%s", str);
  18884. SendBufLen = strlen(str);
  18885. pthread_mutex_unlock(&lock_send);
  18886. lws_callback_on_writable(wsi_client);
  18887. //lws_service(context, 0);
  18888. //sleep(1);
  18889. }
  18890. void LWS_SendNow(char *str)
  18891. {
  18892. //=====================================================
  18893. // Check InternetConn 0: disconnected, 1: connected
  18894. //====================================================
  18895. if(GetOcppConnStatus() == 0)
  18896. {
  18897. DEBUG_INFO("offline now !!!\n");
  18898. return;
  18899. }
  18900. // Only disable isWebsocketSendable operation initiated by charger
  18901. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18902. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18903. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18904. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18905. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18906. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18907. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18908. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18909. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18910. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18911. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18912. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18913. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18914. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18915. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18916. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18917. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18918. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18919. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18920. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18921. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18922. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18923. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18924. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18925. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18926. {
  18927. isWebsocketSendable = OFF;
  18928. }
  18929. pthread_mutex_lock(&lock_send);
  18930. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18931. sprintf((char *)SendBuffer, "%s", str);
  18932. SendBufLen = strlen(str);
  18933. pthread_mutex_unlock(&lock_send);
  18934. lws_callback_on_writable(wsi_client);
  18935. lws_service(context, 0);
  18936. //sleep(1);
  18937. }