MessageHandler.c 1.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346
  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(KeyCode),
  306. MACROSTR(Local),
  307. MACROSTR(NoAuthorization),
  308. MACROSTR(ISO15693)
  309. };
  310. static char *InstallCertificateUseEnumTypeStr[] = {
  311. MACROSTR(V2GRootCertificate),
  312. MACROSTR(MORootCertificate),
  313. MACROSTR(CSMSRootCertificate),
  314. MACROSTR(ManufacturerRootCertificate)
  315. };
  316. static char *InstallCertificateStatusEnumTypeStr[]={
  317. MACROSTR(Accepted),
  318. MACROSTR(Failed),
  319. MACROSTR(Rejected)
  320. };
  321. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  322. MACROSTR(Accepted),
  323. MACROSTR(Failed)
  324. };
  325. static char *LocationEnumTypeStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char *LogEnumTypeStr[] = {
  333. MACROSTR(DiagnosticsLog),
  334. MACROSTR(SecurityLog)
  335. };
  336. static char *LogStatusEnumTypeStr[] = {
  337. MACROSTR(Accepted),
  338. MACROSTR(Rejected),
  339. MACROSTR(AcceptedCanceled)
  340. };
  341. static char *MeasurandEnumTypeStr[] = {
  342. MACROSTR(Current.Export),
  343. MACROSTR(Current.Import),
  344. MACROSTR(Current.Offered),
  345. MACROSTR(Energy.Active.Export.Register),
  346. MACROSTR(Energy.Active.Import.Register),
  347. MACROSTR(Energy.Reactive.Export.Register),
  348. MACROSTR(Energy.Reactive.Import.Register),
  349. MACROSTR(Energy.Active.Export.Interval),
  350. MACROSTR(Energy.Active.Import.Interval),
  351. MACROSTR(Energy.Active.Net),
  352. MACROSTR(Energy.Reactive.Export.Interval),
  353. MACROSTR(Energy.Reactive.Import.Interval),
  354. MACROSTR(Energy.Reactive.Net),
  355. MACROSTR(Energy.Apparent.Net),
  356. MACROSTR(Energy.Apparent.Import),
  357. MACROSTR(Energy.Apparent.Export),
  358. MACROSTR(Frequency),
  359. MACROSTR(Power.Active.Export),
  360. MACROSTR(Power.Active.Import),
  361. MACROSTR(Power.Factor),
  362. MACROSTR(Power.Offered),
  363. MACROSTR(Power.Reactive.Export),
  364. MACROSTR(Power.Reactive.Import),
  365. MACROSTR(SoC),
  366. MACROSTR(Voltage)
  367. };
  368. static char *MessageFormatEnumTypeStr[] = {
  369. MACROSTR(ASCII),
  370. MACROSTR(HTML),
  371. MACROSTR(URI),
  372. MACROSTR(UTF8)
  373. };
  374. static char *MessagePriorityEnumTypeStr[] = {
  375. MACROSTR(AlwaysFront),
  376. MACROSTR(InFront),
  377. MACROSTR(NormalCycle)
  378. };
  379. static char *MessageStateEnumTypeStr[] = {
  380. MACROSTR(Charging),
  381. MACROSTR(Faulted),
  382. MACROSTR(Idle),
  383. MACROSTR(Unavailable)
  384. };
  385. static char *MessageTriggerEnumTypeStr[] = {
  386. MACROSTR(BootNotification),
  387. MACROSTR(LogStatusNotification),
  388. MACROSTR(FirmwareStatusNotification),
  389. MACROSTR(Heartbeat),
  390. MACROSTR(MeterValues),
  391. MACROSTR(SignChargingStationCertificate),
  392. MACROSTR(SignV2GCertificate),
  393. MACROSTR(StatusNotification),
  394. MACROSTR(TransactionEvent),
  395. MACROSTR(SignCombinedCertificate),
  396. MACROSTR(PublishFirmwareStatusNotification)
  397. };
  398. static char *MonitorEnumTypeStr[] = {
  399. MACROSTR(UpperThreshold),
  400. MACROSTR(LowerThreshold),
  401. MACROSTR(Delta),
  402. MACROSTR(Periodic),
  403. MACROSTR(PeriodicClockAligned)
  404. };
  405. static char *MonitoringBaseEnumTypeStr[] = {
  406. MACROSTR(All),
  407. MACROSTR(FactoryDefault),
  408. MACROSTR(HardWiredOnly)
  409. };
  410. static char *MonitoringCriterionEnumTypeStr[] = {
  411. MACROSTR(ThresholdMonitoring),
  412. MACROSTR(DeltaMonitoring),
  413. MACROSTR(PeriodicMonitoring)
  414. };
  415. static char *MutabilityEnumTypeStr[] = {
  416. MACROSTR(ReadOnly),
  417. MACROSTR(WriteOnly),
  418. MACROSTR(ReadWrite)
  419. };
  420. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  421. MACROSTR(Accepted),
  422. MACROSTR(Rejected),
  423. MACROSTR(Processing)
  424. };
  425. static char *OCPPInterfaceEnumTypeStr[] = {
  426. MACROSTR(Wired0),
  427. MACROSTR(Wired1),
  428. MACROSTR(Wired2),
  429. MACROSTR(Wired3),
  430. MACROSTR(Wireless0),
  431. MACROSTR(Wireless1),
  432. MACROSTR(Wireless2),
  433. MACROSTR(Wireless3)
  434. };
  435. static char *OCPPTransportEnumTypeStr[] = {
  436. MACROSTR(JSON),
  437. MACROSTR(SOAP)
  438. };
  439. static char *OCPPVersionEnumTypeStr[] = {
  440. MACROSTR(OCPP12),
  441. MACROSTR(OCPP15),
  442. MACROSTR(OCPP16),
  443. MACROSTR(OCPP20)
  444. };
  445. static char *OperationalStatusEnumTypeStr[] = {
  446. MACROSTR(Inoperative),
  447. MACROSTR(Operative)
  448. };
  449. static char *PhaseEnumTypeStr[] = {
  450. MACROSTR(L1),
  451. MACROSTR(L2),
  452. MACROSTR(L3),
  453. MACROSTR(N),
  454. MACROSTR(L1-N),
  455. MACROSTR(L2-N),
  456. MACROSTR(L3-N),
  457. MACROSTR(L1-L2),
  458. MACROSTR(L2-L3),
  459. MACROSTR(L3-L1)
  460. };
  461. static char *PublishFirmwareStatusEnumTypeStr[] = {
  462. MACROSTR(Downloaded),
  463. MACROSTR(DownloadFailed),
  464. MACROSTR(Downloading),
  465. MACROSTR(DownloadScheduled),
  466. MACROSTR(DownloadPaused),
  467. MACROSTR(PublishFailed),
  468. MACROSTR(Published),
  469. MACROSTR(InvalidChecksum),
  470. MACROSTR(ChecksumVerified)
  471. };
  472. static char *ReadingContextEnumTypeStr[] = {
  473. MACROSTR(Interruption.Begin),
  474. MACROSTR(Interruption.End),
  475. MACROSTR(Other),
  476. MACROSTR(Sample.Clock),
  477. MACROSTR(Sample.Periodic),
  478. MACROSTR(Transaction.Begin),
  479. MACROSTR(Transaction.End),
  480. MACROSTR(Trigger)
  481. };
  482. #if 0
  483. static char *ReasonEnumTypeStr[] = {
  484. MACROSTR(DeAuthorized),
  485. MACROSTR(EmergencyStop),
  486. MACROSTR(EnergyLimitReached),
  487. MACROSTR(EVDisconnected),
  488. MACROSTR(GroundFault),
  489. MACROSTR(ImmediateReset),
  490. MACROSTR(Local),
  491. MACROSTR(LocalOutOfCredit),
  492. MACROSTR(MasterPass),
  493. MACROSTR(Other),
  494. MACROSTR(OvercurrentFault),
  495. MACROSTR(PowerLoss),
  496. MACROSTR(PowerQuality),
  497. MACROSTR(Reboot),
  498. MACROSTR(Remote),
  499. MACROSTR(SOCLimitReached),
  500. MACROSTR(StoppedByEV),
  501. MACROSTR(TimeLimitReached),
  502. MACROSTR(TimeLimitReached)
  503. };
  504. #endif
  505. static char *RecurrencyKindEnumTypeStr[] = {
  506. MACROSTR(Daily),
  507. MACROSTR(Weekly)
  508. };
  509. static char *RegistrationStatusEnumTypeStr[] = {
  510. MACROSTR(Accepted),
  511. MACROSTR(Pending),
  512. MACROSTR(Rejected)
  513. };
  514. static char *ReportBaseEnumTypeStr[] = {
  515. MACROSTR(ConfigurationInventory),
  516. MACROSTR(FullInventory),
  517. MACROSTR(SummaryInventory)
  518. };
  519. static char *RequestStartStopStatusEnumTypeStr[] = {
  520. MACROSTR(Accepted),
  521. MACROSTR(Rejected)
  522. };
  523. static char *ReservationUpdateStatusEnumTypeStr[] = {
  524. MACROSTR(Expired),
  525. MACROSTR(Removed)
  526. };
  527. static char *ReserveNowStatusEnumTypeStr[] = {
  528. MACROSTR(Accepted),
  529. MACROSTR(Faulted),
  530. MACROSTR(Occupied),
  531. MACROSTR(Rejected),
  532. MACROSTR(Unavailable)
  533. };
  534. static char *ResetEnumTypeStr[] = {
  535. MACROSTR(Immediate),
  536. MACROSTR(OnIdle)
  537. };
  538. static char *ResetStatusEnumTypeStr[] = {
  539. MACROSTR(Accepted),
  540. MACROSTR(Rejected),
  541. MACROSTR(Scheduled)
  542. };
  543. static char *SetMonitoringStatusEnumTypeStr[] = {
  544. MACROSTR(Accepted),
  545. MACROSTR(UnknownComponent),
  546. MACROSTR(UnknownVariable),
  547. MACROSTR(UnsupportedMonitorType),
  548. MACROSTR(Rejected),
  549. MACROSTR(OutOfRange),
  550. MACROSTR(Duplicate)
  551. };
  552. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected),
  555. MACROSTR(Failed)
  556. };
  557. static char *SetVariableStatusEnumTypeStr[] = {
  558. MACROSTR(Accepted),
  559. MACROSTR(Rejected),
  560. MACROSTR(InvalidValue),
  561. MACROSTR(UnknownComponent),
  562. MACROSTR(UnknownVariable),
  563. MACROSTR(NotSupportedAttributeType),
  564. MACROSTR(OutOfRange),
  565. MACROSTR(RebootRequired)
  566. };
  567. static char *TransactionEventEnumTypeStr[] = {
  568. MACROSTR(Ended),
  569. MACROSTR(Started),
  570. MACROSTR(Updated)
  571. };
  572. static char *TriggerMessageStatusEnumTypeStr[] = {
  573. MACROSTR(Accepted),
  574. MACROSTR(Rejected),
  575. MACROSTR(NotImplemented)
  576. };
  577. static char *TriggerReasonEnumTypeStr[] = {
  578. MACROSTR(Authorized),
  579. MACROSTR(CablePluggedIn),
  580. MACROSTR(ChargingRateChanged),
  581. MACROSTR(ChargingStateChanged),
  582. MACROSTR(Deauthorized),
  583. MACROSTR(EnergyLimitReached),
  584. MACROSTR(EVCommunicationLost),
  585. MACROSTR(EVConnectTimeout),
  586. MACROSTR(MeterValueClock),
  587. MACROSTR(MeterValuePeriodic),
  588. MACROSTR(TimeLimitReached),
  589. MACROSTR(Trigger),
  590. MACROSTR(UnlockCommand),
  591. MACROSTR(StopAuthorized),
  592. MACROSTR(EVDeparted),
  593. MACROSTR(EVDetected),
  594. MACROSTR(RemoteStop),
  595. MACROSTR(RemoteStart),
  596. MACROSTR(AbnormalCondition),
  597. MACROSTR(SignedDataReceived),
  598. MACROSTR(ResetCommand)
  599. };
  600. static char *UnlockStatusEnumTypeStr[] = {
  601. MACROSTR(Unlocked),
  602. MACROSTR(UnlockFailed),
  603. MACROSTR(OngoingAuthorizedTransaction),
  604. MACROSTR(UnknownConnector)
  605. };
  606. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  607. MACROSTR(DownloadOngoing),
  608. MACROSTR(NoFirmware),
  609. MACROSTR(Unpublished)
  610. };
  611. static char *UpdateEnumTypeStr[] = {
  612. MACROSTR(Differential),
  613. MACROSTR(Full)
  614. };
  615. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  616. MACROSTR(Accepted),
  617. MACROSTR(Rejected),
  618. MACROSTR(AcceptedCanceled),
  619. MACROSTR(InvalidCertificate),
  620. MACROSTR(RevokedCertificate)
  621. };
  622. static char *UpdateStatusEnumTypeStr[] = {
  623. MACROSTR(Accepted),
  624. MACROSTR(Failed),
  625. MACROSTR(VersionMismatch)
  626. };
  627. static char *UploadLogStatusEnumTypeStr[] = {
  628. MACROSTR(BadMessage),
  629. MACROSTR(Idle),
  630. MACROSTR(NotSupportedOperation),
  631. MACROSTR(PermissionDenied),
  632. MACROSTR(Uploaded),
  633. MACROSTR(UploadFailure),
  634. MACROSTR(Uploading)
  635. };
  636. static char *VPNEnumTypeStr[] = {
  637. MACROSTR(IKEv2),
  638. MACROSTR(IPSec),
  639. MACROSTR(L2TP),
  640. MACROSTR(PPTP)
  641. };
  642. #if 0
  643. static char *ChargePointErrorCodeEnumTypeStr[] = {
  644. MACROSTR(ConnectorLockFailure),
  645. MACROSTR(EVCommunicationError),
  646. MACROSTR(GroundFailure),
  647. MACROSTR(HighTemperature),
  648. MACROSTR(InternalError),
  649. MACROSTR(LocalListConflict),
  650. MACROSTR(NoError),
  651. MACROSTR(OtherError),
  652. MACROSTR(OverCurrentFailure),
  653. MACROSTR(OverVoltage),
  654. MACROSTR(PowerMeterFailure),
  655. MACROSTR(PowerSwitchFailure),
  656. MACROSTR(ReaderFailure),
  657. MACROSTR(ResetFailure),
  658. MACROSTR(UnderVoltage),
  659. MACROSTR(WeakSignal)
  660. };
  661. #endif
  662. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  663. MACROSTR(Accepted),
  664. MACROSTR(Rejected)
  665. };
  666. static char *RemoteStartStopStatusEnumTypeStr[] = {
  667. MACROSTR(Accepted),
  668. MACROSTR(Rejected)
  669. };
  670. #if 0
  671. static char * StopTransactionReasonEnumTypeStr[] = {
  672. MACROSTR(EmergencyStop),
  673. MACROSTR(EVDisconnected),
  674. MACROSTR(HardReset),
  675. MACROSTR(Local),
  676. MACROSTR(Other),
  677. MACROSTR(PowerLoss),
  678. MACROSTR(Reboot),
  679. MACROSTR(Remote),
  680. MACROSTR(SoftReset),
  681. MACROSTR(UnlockCommand),
  682. MACROSTR(DeAuthorized)
  683. };
  684. #endif
  685. //ChargePointMaxProfile
  686. #define ChargingStationMaxProfile_JSON "/Storage/OCPP/ChargingStationMaxProfile_OCPP20.json"
  687. //TxDefaultProfile
  688. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  689. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  690. struct StatusCodeData *ShmStatusCodeData;
  691. struct PsuData *ShmPsuData ;
  692. struct OCPP20Data *ShmOCPP20Data;
  693. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  694. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  695. //===============================
  696. // Gun Total Numbers
  697. //===============================
  698. static ParsingRatedCur modelnameInfo = {0};
  699. static int gunTotalNumber = 0;
  700. static uint8_t gunType[4] = {0};
  701. //===============================
  702. // Local List Version
  703. //===============================
  704. static int localversion=0;
  705. //===============================
  706. // Variable Version
  707. //===============================
  708. static int variableVersion=7;
  709. //===============================
  710. // OCPP sign variable
  711. //===============================
  712. static int server_sign = FALSE;
  713. int server_pending = FALSE;
  714. static int BootNotificationInterval = 10;
  715. //===============================
  716. // OCPP auth variable
  717. //===============================
  718. static int authorizeRetryTimes = 0; //number of Retry times
  719. //===============================
  720. // OCPP other variables
  721. //===============================
  722. static int HeartBeatWaitTime = 10;
  723. static int FirstHeartBeat = 0;
  724. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  725. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  726. static char CurrentChargingProfileScheduleStr[30] = {0};
  727. static int isCancelUploadLog = FALSE;
  728. //========================================
  729. // OCPP status/previous related variables
  730. //========================================
  731. static int GunStatusInterval = 10;
  732. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  733. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  734. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  735. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  736. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  737. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  738. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  739. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  740. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  741. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  742. static int TransactionMessageAttemptsValue = 0;
  743. static int TransactionMessageRetryIntervalValue = 0;
  744. static struct AuthorizationData idTagQuery;
  745. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  746. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  747. //=============================================
  748. // OCPP HeartBeat Response Not Receive Counts
  749. //============================================
  750. static int HeartBeatWithNOResponse = 0;
  751. static int HeartBeatCountPerHour = 0;
  752. sqlite3 *db;
  753. int TransactionMessageAttemptsGet(void);
  754. int TransactionMessageRetryIntervalGet(void);
  755. int GetOcppConnStatus(void);
  756. void SetOcppConnStatus(uint8_t status);
  757. int setKeyValue(char *key, char *value);
  758. void OCPP_get_TableAuthlocalAllData(void);
  759. void processUnkownKey(void);
  760. struct InterLock
  761. {
  762. unsigned char isGetLogGoing:1;
  763. unsigned char isUpdateFirmwareGoing:1;
  764. }interLock;
  765. struct ClientTime
  766. {
  767. struct timespec Heartbeat;
  768. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  769. struct timespec StartTransaction;
  770. struct timespec StopTransaction;
  771. struct timespec MeterValues[CONNECTOR_QUANTITY];
  772. struct timespec RemoteStartWait;
  773. }clientTime;
  774. typedef union
  775. {
  776. //Operations Initiated by Central System
  777. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  778. struct
  779. {
  780. //CsMsgValue[0]
  781. unsigned char StatusNotificationReq:1; //bit 0,
  782. unsigned char StatusNotificationConf:1; //bit 1,
  783. unsigned char TriggerMeterValueReq:1; //bit 2,
  784. unsigned char SampleMeterReq:1; //bit 3,
  785. unsigned char ClockAlignMeterReq:1; //bit 4,
  786. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  787. unsigned char isOnCharging:1; //bit6,
  788. unsigned char :1; //bit7
  789. }bits[CONNECTOR_QUANTITY];
  790. }CpinitiateMsg;
  791. CpinitiateMsg cpinitateMsg;
  792. //=========================================
  793. // Save configuration
  794. //=========================================
  795. int runShellCmd(const char*cmd)
  796. {
  797. int result = FAIL;
  798. char buf[256];
  799. FILE *fp;
  800. fp = popen(cmd, "r");
  801. if(fp != NULL)
  802. {
  803. while(fgets(buf, sizeof(buf), fp) != NULL)
  804. {
  805. DEBUG_INFO("%s\n", buf);
  806. }
  807. result = PASS;
  808. }
  809. pclose(fp);
  810. return result;
  811. }
  812. int StoreUsrConfigData(struct SysConfigData *UsrData)
  813. {
  814. int result = PASS;
  815. int fd,wrd;
  816. unsigned int i,Chk;
  817. unsigned char *ptr, *BufTmp;
  818. int MtdBlockSize = 0x300000;
  819. Chk=0;
  820. ptr=(unsigned char *)UsrData;
  821. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  822. {
  823. memset(BufTmp,0,MtdBlockSize);
  824. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  825. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  826. Chk+=*(BufTmp+i);
  827. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  828. // Output configuration to file.
  829. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  830. if (fd < 0)
  831. {
  832. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  833. free(BufTmp);
  834. return 0;
  835. }
  836. wrd=write(fd, BufTmp, MtdBlockSize);
  837. close(fd);
  838. if(wrd<MtdBlockSize)
  839. {
  840. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  841. free(BufTmp);
  842. return 0;
  843. }
  844. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  845. DEBUG_INFO("Erase /dev/mtd10.\n");
  846. runShellCmd("flash_erase /dev/mtd10 0 0");
  847. DEBUG_INFO("Write /dev/mtd10.\n");
  848. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  849. DEBUG_INFO("Erase /dev/mtd11.\n");
  850. runShellCmd("flash_erase /dev/mtd11 0 0");
  851. DEBUG_INFO("Write /dev/mtd11.\n");
  852. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  853. system("rm -f /mnt/EvseConfig.bin");
  854. DEBUG_INFO("EvseConfig write to flash OK\n");
  855. }
  856. else
  857. {
  858. DEBUG_ERROR("alloc BlockSize NG\r\n");
  859. result = FAIL;
  860. }
  861. if(BufTmp!=NULL)
  862. free(BufTmp);
  863. return result;
  864. }
  865. //=========================================
  866. // Date time related function
  867. //=========================================
  868. void getNowDatetime(uint8_t *data)
  869. {
  870. time_t t = time(NULL);
  871. struct tm tm = *localtime(&t);
  872. 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);
  873. }
  874. //=========================================
  875. // Sqlite3 related function
  876. //=========================================
  877. int DB_Initial()
  878. {
  879. int result = PASS;
  880. char* errMsg = NULL;
  881. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  882. "idToken text UNIQUE,"
  883. "type text,"
  884. "status text,"
  885. "cacheExpiryDateTime text,"
  886. "chargingPriority integer,"
  887. "language1 text,"
  888. "evseId text,"
  889. "language2 text,"
  890. "groupIdToken_idToken text,"
  891. "groupIdToken_type text,"
  892. "personalMessage text);";
  893. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  894. "idToken text UNIQUE,"
  895. "type text,"
  896. "status text,"
  897. "cacheExpiryDateTime text,"
  898. "chargingPriority integer,"
  899. "language1 text,"
  900. "evseId text,"
  901. "language2 text,"
  902. "groupIdToken_idToken text,"
  903. "groupIdToken_type text,"
  904. "personalMessage text,"
  905. "version text);";
  906. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  907. "componentName text NOT NULL ,"
  908. "componentInstance text, "
  909. "variableName text NOT NULL, "
  910. "variableInstance text, "
  911. "variableCharacteristicsDataType integer, "
  912. "variableCharacteristicsUnit text, "
  913. "variableCharacteristicsMaxLimit real,"
  914. "variableAttributesType text, "
  915. "variableAttributesTypeMutability text, "
  916. "variableAttributesTypeValue text, "
  917. "variableCharacteristicsMinLimit real,"
  918. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  919. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  920. "type text);";
  921. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  922. "type text);";
  923. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  924. "slot integer UNIQUE, connectionData text);";
  925. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  926. "occurDatetime text,"
  927. "message_type text,"
  928. "message_content text)";
  929. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  930. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  931. {
  932. result = FAIL;
  933. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  934. sqlite3_close(db);
  935. }
  936. else
  937. {
  938. DEBUG_INFO( "OCPP local database open successfully.\n");
  939. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  940. {
  941. result = FAIL;
  942. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  943. }
  944. else
  945. {
  946. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  947. }
  948. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  949. {
  950. result = FAIL;
  951. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  952. }
  953. else
  954. {
  955. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  956. }
  957. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  958. {
  959. result = FAIL;
  960. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  961. }
  962. else
  963. {
  964. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  965. }
  966. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  967. {
  968. result = FAIL;
  969. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  970. }
  971. else
  972. {
  973. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  974. }
  975. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  976. {
  977. result = FAIL;
  978. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  979. }
  980. else
  981. {
  982. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  983. }
  984. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  985. {
  986. result = FAIL;
  987. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  988. }
  989. else
  990. {
  991. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  992. }
  993. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  994. {
  995. result = FAIL;
  996. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  997. }
  998. else
  999. {
  1000. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1001. }
  1002. //sqlite3_close(db);
  1003. }
  1004. return result;
  1005. }
  1006. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1007. {
  1008. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1009. return 0;
  1010. }
  1011. void DB_getListVerion()
  1012. {
  1013. char sql[256];
  1014. char* errMsg = NULL;
  1015. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1016. /* Execute SQL statement */
  1017. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1018. {
  1019. DEBUG_INFO("SQL error: %s", errMsg);
  1020. }
  1021. }
  1022. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1023. {
  1024. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1025. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1026. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1027. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1028. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1029. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1030. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1031. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1032. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1033. return 0;
  1034. }
  1035. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1036. {
  1037. char sql[256];
  1038. char* errMsg = NULL;
  1039. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1040. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1041. if(isQueryFromCache)
  1042. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1043. else
  1044. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1045. /* Execute SQL statement */
  1046. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1047. {
  1048. DEBUG_INFO("SQL error: %s", errMsg);
  1049. }
  1050. }
  1051. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1052. {
  1053. for (int i = 0; i < columnCount; i++)
  1054. {
  1055. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1056. }
  1057. return 0;
  1058. }
  1059. void DB_get_TableAuthlocalAllData(void)
  1060. {
  1061. char sql[256];
  1062. char* errMsg = NULL;
  1063. sprintf(sql,"select * from ocpp20_auth_local;");
  1064. /* Execute SQL statement */
  1065. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1066. {
  1067. DEBUG_INFO("SQL error: %s", errMsg);
  1068. }
  1069. }
  1070. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1071. {
  1072. for(int i = 0; i<columnCount; i++)
  1073. {
  1074. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1075. }
  1076. return 0;
  1077. }
  1078. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1079. {
  1080. int result = PASS;
  1081. char sql[512];
  1082. char* errMsg = NULL;
  1083. 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;",
  1084. data->idToken.idToken,
  1085. data->idToken.type,
  1086. data->idTokenInfo.status,
  1087. data->idTokenInfo.cacheExpiryDateTime,
  1088. data->idTokenInfo.chargingPriority,
  1089. data->idTokenInfo.language1,
  1090. data->idTokenInfo.language2,
  1091. data->idTokenInfo.groupIdToken.idToken,
  1092. data->idTokenInfo.groupIdToken.type,
  1093. listVersion);
  1094. //* Execute SQL statement */
  1095. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1096. {
  1097. DEBUG_INFO("SQL error: %s\n", errMsg);
  1098. result = FAIL;
  1099. }
  1100. else
  1101. {
  1102. memset(sql, 0, ARRAY_SIZE(sql));
  1103. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1104. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1105. {
  1106. DEBUG_INFO("SQL error: %s\n", errMsg);
  1107. result = FAIL;
  1108. }
  1109. }
  1110. return result;
  1111. }
  1112. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1113. {
  1114. int result = PASS;
  1115. char sql[512];
  1116. char* errMsg = NULL;
  1117. 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;",
  1118. idToken->idToken,
  1119. idToken->type,
  1120. idTokenInfo->status,
  1121. idTokenInfo->cacheExpiryDateTime,
  1122. idTokenInfo->chargingPriority,
  1123. idTokenInfo->language1,
  1124. idTokenInfo->language2,
  1125. idTokenInfo->groupIdToken.idToken,
  1126. idTokenInfo->groupIdToken.type);
  1127. //* Execute SQL statement */
  1128. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1129. {
  1130. DEBUG_INFO("SQL error: %s\n", errMsg);
  1131. result = FAIL;
  1132. }
  1133. return result;
  1134. }
  1135. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1136. {
  1137. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1138. // printf("localversion=%d\n", localversion);
  1139. return 0;
  1140. }
  1141. void DB_deleteIdTag(char idTag[])
  1142. {
  1143. char sql[512];
  1144. char* errMsg = NULL;
  1145. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1146. //* Execute SQL statement */
  1147. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1148. {
  1149. DEBUG_INFO("SQL error: %s", errMsg);
  1150. }
  1151. }
  1152. int DB_cleanLocalList()
  1153. {
  1154. int result = PASS;
  1155. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1156. char *errMsg = 0;
  1157. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1158. {
  1159. DEBUG_INFO("%s\n", errMsg);
  1160. result = FAIL;
  1161. }
  1162. return result;
  1163. }
  1164. int DB_cleanLocalCache()
  1165. {
  1166. int result = PASS;
  1167. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1168. char *errMsg = 0;
  1169. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1170. {
  1171. DEBUG_INFO("%s\n", errMsg);
  1172. result = FAIL;
  1173. }
  1174. return result;
  1175. }
  1176. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1177. {
  1178. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1179. return 0;
  1180. }
  1181. void DB_getBooType()
  1182. {
  1183. char sql[256];
  1184. char* errMsg = NULL;
  1185. sprintf(sql,"select * from ocpp20_boot_type;");
  1186. /* Execute SQL statement */
  1187. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1188. {
  1189. DEBUG_INFO("SQL error: %s\n", errMsg);
  1190. }
  1191. }
  1192. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1193. {
  1194. for(int i = 0; i<columnCount; i++)
  1195. {
  1196. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1197. }
  1198. return 0;
  1199. }
  1200. int DB_updateBootType(BootReasonEnumType reason)
  1201. {
  1202. int result = PASS;
  1203. char sql[512];
  1204. char* errMsg = NULL;
  1205. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1206. //* Execute SQL statement */
  1207. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1208. {
  1209. DEBUG_INFO("SQL error: %s\n", errMsg);
  1210. result = FAIL;
  1211. }
  1212. return result;
  1213. }
  1214. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1215. {
  1216. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1217. return 0;
  1218. }
  1219. void DB_getSecurityEventType()
  1220. {
  1221. char sql[256];
  1222. char* errMsg = NULL;
  1223. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1224. /* Execute SQL statement */
  1225. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1226. {
  1227. DEBUG_INFO("SQL error: %s\n", errMsg);
  1228. }
  1229. }
  1230. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1231. {
  1232. for(int i = 0; i<columnCount; i++)
  1233. {
  1234. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1235. }
  1236. return 0;
  1237. }
  1238. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1239. {
  1240. int result = PASS;
  1241. char sql[512];
  1242. char* errMsg = NULL;
  1243. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1244. //* Execute SQL statement */
  1245. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1246. {
  1247. DEBUG_INFO("SQL error: %s\n", errMsg);
  1248. result = FAIL;
  1249. }
  1250. return result;
  1251. }
  1252. int DB_variableClear()
  1253. {
  1254. int result = PASS;
  1255. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1256. char *errMsg = 0;
  1257. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1258. {
  1259. DEBUG_INFO("%s\n", errMsg);
  1260. result = FAIL;
  1261. }
  1262. return result;
  1263. }
  1264. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1265. {
  1266. for(int i = 0; i<columnCount; i++)
  1267. {
  1268. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1269. }
  1270. return 0;
  1271. }
  1272. int DB_variableSaveToDb(struct ReportDataType *variable)
  1273. {
  1274. int result = FAIL;
  1275. char sql[4096];
  1276. char* errMsg = NULL;
  1277. 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;",
  1278. variable->component.name,
  1279. variable->component.instance,
  1280. variable->variable.name,
  1281. variable->variable.instance,
  1282. variable->variableCharacteristics.dataType,
  1283. variable->variableCharacteristics.unit,
  1284. variable->variableCharacteristics.maxLimit,
  1285. variable->variableAttribute[0].type,
  1286. variable->variableAttribute[0].mutability,
  1287. variable->variableAttribute[0].value,
  1288. variable->variableCharacteristics.minLimit);
  1289. //* Execute SQL statement */
  1290. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1291. {
  1292. DEBUG_INFO("SQL error: %s\n", errMsg);
  1293. result = FAIL;
  1294. }
  1295. return result;
  1296. }
  1297. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1298. {
  1299. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1300. if(atoi(columnValue[0]) == 0)
  1301. {
  1302. DB_updateBootType(BootReasonEnumType_PowerUp);
  1303. // Create variable table content
  1304. /* AlignedDataCtrlr Required item */
  1305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1311. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1318. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1322. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1327. "Energy.Active.Import.Register,"
  1328. "Energy.Active.Import.Interval,"
  1329. "Power.Active.Import,"
  1330. "Voltage,"
  1331. "SoC,"
  1332. "Current.Offered,"
  1333. "Power.Offered");
  1334. else
  1335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1336. "Energy.Active.Import.Register,"
  1337. "Energy.Active.Import.Interval,"
  1338. "Power.Active.Import,"
  1339. "Voltage,"
  1340. "Current.Offered");
  1341. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1346. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1350. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1357. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1364. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1368. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1373. "Energy.Active.Import.Register,"
  1374. "Energy.Active.Import.Interval,"
  1375. "Power.Active.Import,"
  1376. "Voltage,"
  1377. "SoC");
  1378. else
  1379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1380. "Energy.Active.Import.Register,"
  1381. "Energy.Active.Import.Interval,"
  1382. "Power.Active.Import,"
  1383. "Voltage");
  1384. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1392. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1393. /* AuthCtrlrVariable Required item */
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1400. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1407. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1414. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1421. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1428. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1435. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1439. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1443. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1444. /* AuthCacheCtrlr Variable Required item*/
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1451. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1458. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1466. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1470. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1474. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1481. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1482. /* ClockCtrlr Variable Required item */
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1488. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1489. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1496. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1504. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1511. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1518. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1526. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1533. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1540. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1541. /* ChargingStation Required item */
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1548. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1555. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1562. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  1569. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  1576. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  1583. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  1584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  1585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  1590. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  1591. /* Connector Required item */
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1598. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1605. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1612. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1613. /* CustomizationCtrlr Required item */
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1620. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1621. /* DeviceDataCtrlr Required item */
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1629. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1637. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1645. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1653. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1656. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1661. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1664. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1669. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1677. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1685. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1686. /* DisplayMessageCtrlr Required item */
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1693. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1700. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1704. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1708. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1715. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1722. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1723. /* EVSE Required item */
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1730. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1737. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1744. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1751. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1752. /* LocalAuthListCtrlr Required item */
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1759. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1763. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1767. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1774. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  1782. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  1790. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1794. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  1798. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1799. /* MonitoringCtrlr Required item */
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1806. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1813. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1821. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1829. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1837. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1845. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1852. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1853. /* OCPPCommCtrlr Required item */
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1860. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1869. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1876. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1880. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1885. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1892. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1899. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1907. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1914. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1923. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  1932. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1939. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1943. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1948. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1955. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1962. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  1969. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "FALSE");
  1976. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  1980. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  1985. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  1986. /* ReservationCtrlr Required item */
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1993. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  2000. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  2007. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2008. /* SampledDataCtrlr Required item */
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  2015. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  2022. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  2029. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2033. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2038. "Energy.Active.Import.Register,"
  2039. "Energy.Active.Import.Interval,"
  2040. "Power.Active.Import,"
  2041. "Voltage,"
  2042. "SoC");
  2043. else
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2045. "Energy.Active.Import.Register,"
  2046. "Energy.Active.Import.Interval,"
  2047. "Power.Active.Import,"
  2048. "Voltage");
  2049. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2057. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2061. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2065. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2069. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2074. "Energy.Active.Import.Register,"
  2075. "Energy.Active.Import.Interval,"
  2076. "Power.Active.Import,"
  2077. "Voltage,"
  2078. "SoC,"
  2079. "Current.Offered,"
  2080. "Power.Offered");
  2081. else
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2083. "Energy.Active.Import.Register,"
  2084. "Energy.Active.Import.Interval,"
  2085. "Power.Active.Import,"
  2086. "Voltage,"
  2087. "Current.Offered");
  2088. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2093. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2097. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2098. /* SecurityCtrlr Required item */
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2102. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2106. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2110. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2114. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2121. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2125. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2129. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2136. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  2143. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2147. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2151. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2152. /* SmartChargingCtrlr Required item */
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  2159. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  2166. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  2173. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2180. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2187. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2194. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  2201. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  2208. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  2215. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2219. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2223. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2230. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2231. /* TariffCostCtrlr Required item */
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  2239. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  2247. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2251. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2255. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2263. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2271. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2275. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2279. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2283. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2287. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2288. /* TxCtrlr Required item */
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2295. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2303. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2310. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2317. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2324. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2331. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2339. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2346. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2347. }
  2348. else
  2349. {
  2350. // Variable name init
  2351. /* AlignedDataCtrlr Required item */
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2368. /* AuthCtrlrVariable Required item */
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2383. /* AuthCacheCtrlr Variable Required item */
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2394. /* ClockCtrlr Variable Required item */
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2413. /* ChargingStation Required item */
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2428. /* Connector Required item */
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2435. /* CustomizationCtrlr Required item */
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2438. /* DeviceDataCtrlr Required item */
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2461. /* DisplayMessageCtrlr Required item */
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2472. /* EVSE Required item */
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2481. /* LocalAuthListCtrlr Required item */
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2496. /* MonitoringCtrlr Required item */
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2515. /* OCPPCommCtrlr Required item */
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2553. /* ReservationCtrlr Required item */
  2554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2560. /* SampledDataCtrlr Required item */
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2577. /* SecurityCtrlr Required item */
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2592. /* SmartChargingCtrlr Required item */
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2615. /* TariffCostCtrlr Required item */
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2634. /* TxCtrlr Required item */
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2651. }
  2652. return 0;
  2653. }
  2654. void DB_variableIsCreate()
  2655. {
  2656. char sql[512];
  2657. char* errMsg = NULL;
  2658. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2659. /* Execute SQL statement */
  2660. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2661. {
  2662. DEBUG_INFO("SQL error: %s\n", errMsg);
  2663. }
  2664. }
  2665. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2666. {
  2667. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2668. {
  2669. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2670. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2671. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2672. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2673. {
  2674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2676. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2680. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  2681. }
  2682. }
  2683. return 0;
  2684. }
  2685. void DB_variableLoadFromDb()
  2686. {
  2687. char sql[512];
  2688. char* errMsg = NULL;
  2689. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2690. /* Execute SQL statement */
  2691. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2692. {
  2693. DEBUG_INFO("SQL error: %s\n", errMsg);
  2694. }
  2695. }
  2696. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2697. {
  2698. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2699. if(columnCount > 0)
  2700. {
  2701. for(int idx=0;idx<columnCount;idx++)
  2702. {
  2703. json_object *SetNetworkProfile;
  2704. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2705. if(!is_error(SetNetworkProfile))
  2706. {
  2707. // Required data
  2708. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2709. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2710. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2711. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2712. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2713. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2714. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2715. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2716. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2717. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2718. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2719. {
  2720. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2721. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2722. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2723. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2724. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2725. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2726. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2727. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2728. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2729. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2730. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2731. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2732. }
  2733. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2734. {
  2735. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2736. {
  2737. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2738. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2739. }
  2740. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2741. {
  2742. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2743. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2744. }
  2745. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2746. {
  2747. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2748. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2749. }
  2750. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2751. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2752. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2753. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2754. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2755. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2756. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2757. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2758. }
  2759. }
  2760. json_object_put(SetNetworkProfile);
  2761. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2762. }
  2763. }
  2764. return 0;
  2765. }
  2766. void DB_getNetworkProfileFromDb()
  2767. {
  2768. char sql[512];
  2769. char* errMsg = NULL;
  2770. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2771. /* Execute SQL statement */
  2772. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2773. {
  2774. DEBUG_INFO("SQL error: %s\n", errMsg);
  2775. }
  2776. }
  2777. int DB_addNetworkProfile(int slot, char *data)
  2778. {
  2779. int result = PASS;
  2780. char sql[512];
  2781. char* errMsg = NULL;
  2782. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2783. slot,
  2784. data);
  2785. //* Execute SQL statement */
  2786. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2787. {
  2788. DEBUG_INFO("SQL error: %s\n", errMsg);
  2789. result = FAIL;
  2790. }
  2791. return result;
  2792. }
  2793. int DB_deleteNetworkProfile(int slot)
  2794. {
  2795. int result = PASS;
  2796. char sql[512];
  2797. char* errMsg = NULL;
  2798. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2799. //* Execute SQL statement */
  2800. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2801. {
  2802. DEBUG_INFO("SQL error: %s", errMsg);
  2803. result = FAIL;
  2804. }
  2805. return result;
  2806. }
  2807. int getCurrentYear()
  2808. {
  2809. int result = 0;
  2810. time_t CurrentTime;
  2811. struct tm *tm;
  2812. CurrentTime = time(NULL);
  2813. tm=localtime(&CurrentTime);
  2814. result = (tm->tm_year + 1900);
  2815. return result;
  2816. }
  2817. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2818. {
  2819. int result = PASS;
  2820. char* errMsg = NULL;
  2821. char sqlStr[8192];
  2822. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2823. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2824. {
  2825. result = FAIL;
  2826. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  2827. }
  2828. 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));
  2829. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2830. {
  2831. result = FAIL;
  2832. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  2833. }
  2834. return result;
  2835. }
  2836. //==========================================
  2837. // Check time passed since today
  2838. //==========================================
  2839. long long DiffTimebWithNow(struct timeb ST)
  2840. {
  2841. //return milli-second
  2842. struct timeb ET;
  2843. long long StartTime,StopTime;
  2844. ftime(&ET);
  2845. StartTime=(long long)ST.time;
  2846. StopTime=(long long)ET.time;
  2847. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2848. }
  2849. int getTimePassSinceToday(uint8_t gun_index)
  2850. {
  2851. int result = -1;
  2852. static time_t lastTime[4];
  2853. time_t t;
  2854. struct tm *tmStartToday;
  2855. struct timeb tbStartToday;
  2856. t=time(NULL);
  2857. if(difftime(t, lastTime[gun_index])>0)
  2858. {
  2859. tmStartToday=localtime(&t);
  2860. tmStartToday->tm_hour = 0;
  2861. tmStartToday->tm_min = 0;
  2862. tmStartToday->tm_sec = 0;
  2863. tbStartToday.time = mktime(tmStartToday);
  2864. tbStartToday.millitm = 0;
  2865. result = DiffTimebWithNow(tbStartToday)/1000;
  2866. lastTime[gun_index] = t;
  2867. }
  2868. return result;
  2869. }
  2870. int syncDateTimeRTC(uint8_t *data)
  2871. {
  2872. struct ParsingResult
  2873. {
  2874. int result;
  2875. int scanedElement;
  2876. int year;
  2877. int month;
  2878. int mday;
  2879. int hour;
  2880. int min;
  2881. int sec;
  2882. int tz_hour;
  2883. int tz_min;
  2884. float minSec;
  2885. }result;
  2886. struct tm tmOrg;
  2887. struct tm *tmTarget;
  2888. struct timeb tbTarget;
  2889. char buf[128];
  2890. memset(&result, 0x00, sizeof(struct ParsingResult));
  2891. result.result = PASS;
  2892. if(strstr((char*)data, ".") != NULL)
  2893. {
  2894. // Original data with mini second
  2895. if(strstr((char*)data, "Z") != NULL)
  2896. {
  2897. // Original data with Z
  2898. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2899. &result.year,
  2900. &result.month,
  2901. &result.mday,
  2902. &result.hour,
  2903. &result.min,
  2904. &result.sec,
  2905. &result.minSec);
  2906. }
  2907. else
  2908. {
  2909. // Original data without Z
  2910. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2911. &result.year,
  2912. &result.month,
  2913. &result.mday,
  2914. &result.hour,
  2915. &result.min,
  2916. &result.sec,
  2917. &result.minSec,
  2918. &result.tz_hour,
  2919. &result.tz_min);
  2920. }
  2921. }
  2922. else
  2923. {
  2924. // Original data without mini second
  2925. if(strstr((char*)data, "Z") != NULL)
  2926. {
  2927. // Original data with Z
  2928. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2929. &result.year,
  2930. &result.month,
  2931. &result.mday,
  2932. &result.hour,
  2933. &result.min,
  2934. &result.sec);
  2935. }
  2936. else
  2937. {
  2938. // Original data without Z
  2939. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2940. &result.year,
  2941. &result.month,
  2942. &result.mday,
  2943. &result.hour,
  2944. &result.min,
  2945. &result.sec,
  2946. &result.tz_hour,
  2947. &result.tz_min);
  2948. }
  2949. }
  2950. tmOrg.tm_year = result.year - 1900;
  2951. tmOrg.tm_mon = result.month - 1;
  2952. tmOrg.tm_mday = result.mday;
  2953. tmOrg.tm_hour = result.hour;
  2954. tmOrg.tm_min = result.min;
  2955. tmOrg.tm_sec = result.sec;
  2956. tmOrg.tm_gmtoff = 0;
  2957. tbTarget.time = mktime(&tmOrg);
  2958. tbTarget.timezone = 0;
  2959. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2960. tmTarget = gmtime(&tbTarget.time);
  2961. 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);
  2962. //DEBUG_INFO(" org date time: %s\n", data);
  2963. //DEBUG_INFO("parse date time: %s\n", buf);
  2964. system(buf);
  2965. system("/sbin/hwclock -w --systohc");
  2966. if(result.scanedElement < 6)
  2967. result.result = FAIL;
  2968. return result.result;
  2969. }
  2970. //==========================================
  2971. // GetCompositeSchedule logic related function
  2972. //==========================================
  2973. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2974. {
  2975. //return milli-second
  2976. unsigned int StartTime,StopTime;
  2977. StartTime=(unsigned int)ST.time;
  2978. StopTime=(unsigned int)ET.time;
  2979. return (StopTime-StartTime);
  2980. }
  2981. int DiffTimebWithNowSec(struct timeb ST)
  2982. {
  2983. //return milli-second
  2984. struct timeb ET;
  2985. unsigned int StartTime,StopTime;
  2986. ftime(&ET);
  2987. StartTime=(unsigned int)ST.time;
  2988. StopTime=(unsigned int)ET.time;
  2989. return (StopTime-StartTime);
  2990. }
  2991. int getStartStop(uint8_t *start, uint8_t *stop)
  2992. {
  2993. struct ParsingResult
  2994. {
  2995. int result;
  2996. int scanedElement;
  2997. int year;
  2998. int month;
  2999. int mday;
  3000. int hour;
  3001. int min;
  3002. int sec;
  3003. int tz_hour;
  3004. int tz_min;
  3005. float minSec;
  3006. };
  3007. struct ParsingResult parseStart;
  3008. struct ParsingResult parseStop;
  3009. int result = -1;
  3010. struct tm tmStart;
  3011. struct timeb tbStart;
  3012. struct tm tmStop;
  3013. struct timeb tbStop;
  3014. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3015. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3016. // Scan start & stop date time
  3017. if(strstr((char*)start, ".") != NULL)
  3018. {
  3019. // Original data with mini second
  3020. if(strstr((char*)start, "Z") != NULL)
  3021. {
  3022. // Original data with Z
  3023. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3024. &parseStart.year,
  3025. &parseStart.month,
  3026. &parseStart.mday,
  3027. &parseStart.hour,
  3028. &parseStart.min,
  3029. &parseStart.sec,
  3030. &parseStart.minSec);
  3031. }
  3032. else
  3033. {
  3034. // Original data without Z
  3035. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3036. &parseStart.year,
  3037. &parseStart.month,
  3038. &parseStart.mday,
  3039. &parseStart.hour,
  3040. &parseStart.min,
  3041. &parseStart.sec,
  3042. &parseStart.minSec,
  3043. &parseStart.tz_hour,
  3044. &parseStart.tz_min);
  3045. }
  3046. }
  3047. else
  3048. {
  3049. // Original data without mini second
  3050. if(strstr((char*)start, "Z") != NULL)
  3051. {
  3052. // Original data with Z
  3053. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3054. &parseStart.year,
  3055. &parseStart.month,
  3056. &parseStart.mday,
  3057. &parseStart.hour,
  3058. &parseStart.min,
  3059. &parseStart.sec);
  3060. }
  3061. else
  3062. {
  3063. // Original data without Z
  3064. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3065. &parseStart.year,
  3066. &parseStart.month,
  3067. &parseStart.mday,
  3068. &parseStart.hour,
  3069. &parseStart.min,
  3070. &parseStart.sec,
  3071. &parseStart.tz_hour,
  3072. &parseStart.tz_min);
  3073. }
  3074. }
  3075. if(strstr((char*)stop, ".") != NULL)
  3076. {
  3077. // Original data with mini second
  3078. if(strstr((char*)stop, "Z") != NULL)
  3079. {
  3080. // Original data with Z
  3081. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3082. &parseStop.year,
  3083. &parseStop.month,
  3084. &parseStop.mday,
  3085. &parseStop.hour,
  3086. &parseStop.min,
  3087. &parseStop.sec,
  3088. &parseStop.minSec);
  3089. }
  3090. else
  3091. {
  3092. // Original data without Z
  3093. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3094. &parseStop.year,
  3095. &parseStop.month,
  3096. &parseStop.mday,
  3097. &parseStop.hour,
  3098. &parseStop.min,
  3099. &parseStop.sec,
  3100. &parseStop.minSec,
  3101. &parseStop.tz_hour,
  3102. &parseStop.tz_min);
  3103. }
  3104. }
  3105. else
  3106. {
  3107. // Original data without mini second
  3108. if(strstr((char*)stop, "Z") != NULL)
  3109. {
  3110. // Original data with Z
  3111. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3112. &parseStop.year,
  3113. &parseStop.month,
  3114. &parseStop.mday,
  3115. &parseStop.hour,
  3116. &parseStop.min,
  3117. &parseStop.sec);
  3118. }
  3119. else
  3120. {
  3121. // Original data without Z
  3122. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3123. &parseStop.year,
  3124. &parseStop.month,
  3125. &parseStop.mday,
  3126. &parseStop.hour,
  3127. &parseStop.min,
  3128. &parseStop.sec,
  3129. &parseStop.tz_hour,
  3130. &parseStop.tz_min);
  3131. }
  3132. }
  3133. // Calculate date time difference
  3134. if((parseStart.scanedElement >=6) &&
  3135. (parseStop.scanedElement >=6))
  3136. {
  3137. //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);
  3138. //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);
  3139. tmStart.tm_year = parseStart.year - 1900;
  3140. tmStart.tm_mon = parseStart.month - 1;
  3141. tmStart.tm_mday = parseStart.mday;
  3142. tmStart.tm_hour = parseStart.hour;
  3143. tmStart.tm_min = parseStart.min;
  3144. tmStart.tm_sec = parseStart.sec;
  3145. tmStart.tm_gmtoff = 0;
  3146. tbStart.time = mktime(&tmStart);
  3147. tbStart.timezone = 0;
  3148. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3149. tmStop.tm_year = parseStop.year - 1900;
  3150. tmStop.tm_mon = parseStop.month - 1;
  3151. tmStop.tm_mday = parseStop.mday;
  3152. tmStop.tm_hour = parseStop.hour;
  3153. tmStop.tm_min = parseStop.min;
  3154. tmStop.tm_sec = parseStop.sec;
  3155. tmStop.tm_gmtoff = 0;
  3156. tbStop.time = mktime(&tmStop);
  3157. tbStop.timezone = 0;
  3158. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3159. result = DiffTimebSec(tbStart, tbStop);
  3160. //DEBUG_INFO("getStartStop(): %d\n", result);
  3161. }
  3162. else
  3163. {
  3164. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3165. }
  3166. return result;
  3167. }
  3168. int isOvertNow(uint8_t *start)
  3169. {
  3170. int result = NO;
  3171. struct ParsingResult
  3172. {
  3173. int result;
  3174. int scanedElement;
  3175. int year;
  3176. int month;
  3177. int mday;
  3178. int hour;
  3179. int min;
  3180. int sec;
  3181. int tz_hour;
  3182. int tz_min;
  3183. float minSec;
  3184. }parsingResult;
  3185. struct tm tmStart;
  3186. struct timeb tbStart;
  3187. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3188. if(strstr((char*)start, ".") != NULL)
  3189. {
  3190. // Original data with mini second
  3191. if(strstr((char*)start, "Z") != NULL)
  3192. {
  3193. // Original data with Z
  3194. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3195. &parsingResult.year,
  3196. &parsingResult.month,
  3197. &parsingResult.mday,
  3198. &parsingResult.hour,
  3199. &parsingResult.min,
  3200. &parsingResult.sec,
  3201. &parsingResult.minSec);
  3202. }
  3203. else
  3204. {
  3205. // Original data without Z
  3206. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3207. &parsingResult.year,
  3208. &parsingResult.month,
  3209. &parsingResult.mday,
  3210. &parsingResult.hour,
  3211. &parsingResult.min,
  3212. &parsingResult.sec,
  3213. &parsingResult.minSec,
  3214. &parsingResult.tz_hour,
  3215. &parsingResult.tz_min);
  3216. }
  3217. }
  3218. else
  3219. {
  3220. // Original data without mini second
  3221. if(strstr((char*)start, "Z") != NULL)
  3222. {
  3223. // Original data with Z
  3224. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3225. &parsingResult.year,
  3226. &parsingResult.month,
  3227. &parsingResult.mday,
  3228. &parsingResult.hour,
  3229. &parsingResult.min,
  3230. &parsingResult.sec);
  3231. }
  3232. else
  3233. {
  3234. // Original data without Z
  3235. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3236. &parsingResult.year,
  3237. &parsingResult.month,
  3238. &parsingResult.mday,
  3239. &parsingResult.hour,
  3240. &parsingResult.min,
  3241. &parsingResult.sec,
  3242. &parsingResult.tz_hour,
  3243. &parsingResult.tz_min);
  3244. }
  3245. }
  3246. if(parsingResult.scanedElement >= 6)
  3247. {
  3248. tmStart.tm_year = parsingResult.year - 1900;
  3249. tmStart.tm_mon = parsingResult.month - 1;
  3250. tmStart.tm_mday = parsingResult.mday;
  3251. tmStart.tm_hour = parsingResult.hour;
  3252. tmStart.tm_min = parsingResult.min;
  3253. tmStart.tm_sec = parsingResult.sec;
  3254. tmStart.tm_gmtoff = 0;
  3255. tbStart.time = mktime(&tmStart);
  3256. tbStart.timezone = 0;
  3257. tbStart.millitm = 0;
  3258. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3259. if(DiffTimebWithNowSec(tbStart) <= 0)
  3260. result = NO;
  3261. else
  3262. result = YES;
  3263. }
  3264. else
  3265. {
  3266. DEBUG_WARN("Start date parsing error.\n");
  3267. }
  3268. return result;
  3269. }
  3270. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3271. {
  3272. struct ParsingResult
  3273. {
  3274. int result;
  3275. int scanedElement;
  3276. int year;
  3277. int month;
  3278. int mday;
  3279. int hour;
  3280. int min;
  3281. int sec;
  3282. int tz_hour;
  3283. int tz_min;
  3284. float minSec;
  3285. };
  3286. struct ParsingResult parseStart;
  3287. struct ParsingResult parseStop;
  3288. int result = -1;
  3289. struct tm tmStart;
  3290. struct timeb tbStart;
  3291. struct tm tmStop;
  3292. struct timeb tbStop;
  3293. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3294. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3295. // Scan start & stop date time
  3296. if(strstr((char*)start, ".") != NULL)
  3297. {
  3298. // Original data with mini second
  3299. if(strstr((char*)start, "Z") != NULL)
  3300. {
  3301. // Original data with Z
  3302. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3303. &parseStart.year,
  3304. &parseStart.month,
  3305. &parseStart.mday,
  3306. &parseStart.hour,
  3307. &parseStart.min,
  3308. &parseStart.sec,
  3309. &parseStart.minSec);
  3310. }
  3311. else
  3312. {
  3313. // Original data without Z
  3314. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3315. &parseStart.year,
  3316. &parseStart.month,
  3317. &parseStart.mday,
  3318. &parseStart.hour,
  3319. &parseStart.min,
  3320. &parseStart.sec,
  3321. &parseStart.minSec,
  3322. &parseStart.tz_hour,
  3323. &parseStart.tz_min);
  3324. }
  3325. }
  3326. else
  3327. {
  3328. // Original data without mini second
  3329. if(strstr((char*)start, "Z") != NULL)
  3330. {
  3331. // Original data with Z
  3332. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3333. &parseStart.year,
  3334. &parseStart.month,
  3335. &parseStart.mday,
  3336. &parseStart.hour,
  3337. &parseStart.min,
  3338. &parseStart.sec);
  3339. }
  3340. else
  3341. {
  3342. // Original data without Z
  3343. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3344. &parseStart.year,
  3345. &parseStart.month,
  3346. &parseStart.mday,
  3347. &parseStart.hour,
  3348. &parseStart.min,
  3349. &parseStart.sec,
  3350. &parseStart.tz_hour,
  3351. &parseStart.tz_min);
  3352. }
  3353. }
  3354. if(strstr((char*)stop, ".") != NULL)
  3355. {
  3356. // Original data with mini second
  3357. if(strstr((char*)stop, "Z") != NULL)
  3358. {
  3359. // Original data with Z
  3360. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3361. &parseStop.year,
  3362. &parseStop.month,
  3363. &parseStop.mday,
  3364. &parseStop.hour,
  3365. &parseStop.min,
  3366. &parseStop.sec,
  3367. &parseStop.minSec);
  3368. }
  3369. else
  3370. {
  3371. // Original data without Z
  3372. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3373. &parseStop.year,
  3374. &parseStop.month,
  3375. &parseStop.mday,
  3376. &parseStop.hour,
  3377. &parseStop.min,
  3378. &parseStop.sec,
  3379. &parseStop.minSec,
  3380. &parseStop.tz_hour,
  3381. &parseStop.tz_min);
  3382. }
  3383. }
  3384. else
  3385. {
  3386. // Original data without mini second
  3387. if(strstr((char*)stop, "Z") != NULL)
  3388. {
  3389. // Original data with Z
  3390. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3391. &parseStop.year,
  3392. &parseStop.month,
  3393. &parseStop.mday,
  3394. &parseStop.hour,
  3395. &parseStop.min,
  3396. &parseStop.sec);
  3397. }
  3398. else
  3399. {
  3400. // Original data without Z
  3401. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3402. &parseStop.year,
  3403. &parseStop.month,
  3404. &parseStop.mday,
  3405. &parseStop.hour,
  3406. &parseStop.min,
  3407. &parseStop.sec,
  3408. &parseStop.tz_hour,
  3409. &parseStop.tz_min);
  3410. }
  3411. }
  3412. // Calculate date time difference
  3413. if((parseStart.scanedElement >=6) &&
  3414. (parseStop.scanedElement >=6))
  3415. {
  3416. //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);
  3417. //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);
  3418. tmStart.tm_year = parseStart.year - 1900;
  3419. tmStart.tm_mon = parseStart.month - 1;
  3420. tmStart.tm_mday = parseStart.mday;
  3421. tmStart.tm_hour = parseStart.hour;
  3422. tmStart.tm_min = parseStart.min;
  3423. tmStart.tm_sec = parseStart.sec;
  3424. tmStart.tm_gmtoff = 0;
  3425. tbStart.time = mktime(&tmStart);
  3426. tbStart.timezone = 0;
  3427. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3428. tmStop.tm_year = parseStop.year - 1900;
  3429. tmStop.tm_mon = parseStop.month - 1;
  3430. tmStop.tm_mday = parseStop.mday;
  3431. tmStop.tm_hour = parseStop.hour;
  3432. tmStop.tm_min = parseStop.min;
  3433. tmStop.tm_sec = parseStop.sec;
  3434. tmStop.tm_gmtoff = 0;
  3435. tbStop.time = mktime(&tmStop);
  3436. tbStop.timezone = 0;
  3437. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3438. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  3439. //DEBUG_INFO("getStartStop(): %d\n", result);
  3440. }
  3441. else
  3442. {
  3443. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3444. }
  3445. return result;
  3446. }
  3447. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3448. {
  3449. FILE *fp;
  3450. char profileFileName[128];
  3451. char *line = NULL;
  3452. size_t len = 0;
  3453. time_t CurrentTime;
  3454. struct tm *tmComposite;
  3455. struct ChargingProfileType maxProfile;
  3456. struct ChargingProfileType compositeProfile;
  3457. uint8_t limitMax=0;
  3458. int compositePeriodIdx = 0;
  3459. CurrentTime = time(NULL);
  3460. tmComposite=localtime(&CurrentTime);
  3461. 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);
  3462. if(isUnitA)
  3463. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3464. else
  3465. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3466. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3468. {
  3469. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3470. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3471. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3472. }
  3473. compositeProfile.id = 0;
  3474. compositeProfile.stackLevel = 99 ;
  3475. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  3476. maxProfile.id = -1;
  3477. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3478. system("rm -f /tmp/*.json");
  3479. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3480. // Search max profile
  3481. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  3482. if((access(profileFileName, F_OK))!=-1)
  3483. {
  3484. fp = fopen(profileFileName, "r");
  3485. while(getline(&line, &len, fp) != -1)
  3486. {
  3487. json_object *obj = NULL;
  3488. obj = json_tokener_parse(line);
  3489. if(is_error(obj))
  3490. {
  3491. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3492. }
  3493. else
  3494. {
  3495. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  3496. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  3497. )
  3498. {
  3499. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3500. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3501. )
  3502. {
  3503. struct tm tmFrom, tmTo;
  3504. struct timeb tbFrom, tbTo;
  3505. 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) &&
  3506. (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))
  3507. {
  3508. tmFrom.tm_year -= 1900;
  3509. tmFrom.tm_mon -= 1;
  3510. tbFrom.time = mktime(&tmFrom);
  3511. tmTo.tm_year -= 1900;
  3512. tmTo.tm_mon -= 1;
  3513. tbTo.time = mktime(&tmTo);
  3514. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3515. {
  3516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3517. {
  3518. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3519. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3520. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3521. }
  3522. if(maxProfile.id == -1)
  3523. DEBUG_INFO("MaxProfile found.\n");
  3524. else
  3525. DEBUG_INFO("MaxProfile updated.\n");
  3526. // Required item
  3527. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3528. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3529. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3530. if(isUnitA)
  3531. {
  3532. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3533. 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++)
  3534. {
  3535. 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"));
  3536. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  3537. 3:
  3538. 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")));
  3539. 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")));
  3540. }
  3541. }
  3542. else
  3543. {
  3544. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3545. 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++)
  3546. {
  3547. 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"));
  3548. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  3549. 3:
  3550. 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")));
  3551. 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));
  3552. }
  3553. }
  3554. // Optional item
  3555. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3556. {
  3557. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3558. }
  3559. else
  3560. {
  3561. sprintf((char*)maxProfile.validFrom, " ");
  3562. }
  3563. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3564. {
  3565. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3566. }
  3567. else
  3568. {
  3569. sprintf((char*)maxProfile.validTo, " ");
  3570. }
  3571. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3572. {
  3573. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3574. }
  3575. else
  3576. {
  3577. sprintf((char*)maxProfile.recurrencyKind, " ");
  3578. }
  3579. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3580. {
  3581. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3582. }
  3583. else
  3584. {
  3585. sprintf((char*)maxProfile.transactionId, " ");
  3586. }
  3587. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3588. {
  3589. 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"));
  3590. }
  3591. else
  3592. {
  3593. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3594. }
  3595. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3596. {
  3597. 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")));
  3598. }
  3599. else
  3600. {
  3601. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3602. }
  3603. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3604. {
  3605. 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"));
  3606. }
  3607. else
  3608. {
  3609. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3610. }
  3611. }
  3612. }
  3613. }
  3614. else
  3615. {
  3616. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3617. {
  3618. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3619. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3620. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3621. }
  3622. if(maxProfile.id == -1)
  3623. DEBUG_INFO("MaxProfile found.\n");
  3624. else
  3625. DEBUG_INFO("MaxProfile updated.\n");
  3626. // Required item
  3627. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3628. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3629. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3630. if(isUnitA)
  3631. {
  3632. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3633. 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++)
  3634. {
  3635. 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"));
  3636. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  3637. 3:
  3638. 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")));
  3639. 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")));
  3640. }
  3641. }
  3642. else
  3643. {
  3644. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3645. 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++)
  3646. {
  3647. 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"));
  3648. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  3649. 3:
  3650. 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")));
  3651. 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));
  3652. }
  3653. }
  3654. // Optional item
  3655. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3656. {
  3657. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3658. }
  3659. else
  3660. {
  3661. sprintf((char*)maxProfile.validFrom, " ");
  3662. }
  3663. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3664. {
  3665. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3666. }
  3667. else
  3668. {
  3669. sprintf((char*)maxProfile.validTo, " ");
  3670. }
  3671. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3672. {
  3673. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3674. }
  3675. else
  3676. {
  3677. sprintf((char*)maxProfile.recurrencyKind, " ");
  3678. }
  3679. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3680. {
  3681. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3682. }
  3683. else
  3684. {
  3685. sprintf((char*)maxProfile.transactionId, " ");
  3686. }
  3687. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3688. {
  3689. 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"));
  3690. }
  3691. else
  3692. {
  3693. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3694. }
  3695. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3696. {
  3697. 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")));
  3698. }
  3699. else
  3700. {
  3701. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3702. }
  3703. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3704. {
  3705. 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"));
  3706. }
  3707. else
  3708. {
  3709. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3710. }
  3711. }
  3712. }
  3713. }
  3714. json_object_put(obj);
  3715. }
  3716. fclose(fp);
  3717. /*
  3718. if(maxProfile.id !=-1)
  3719. {
  3720. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3721. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3722. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3723. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3724. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3725. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3726. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3727. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3728. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3729. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3730. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3731. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3732. {
  3733. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3734. {
  3735. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3736. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3737. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3738. }
  3739. }
  3740. }
  3741. else
  3742. DEBUG_INFO("MaxProfile not found.\n");
  3743. DEBUG_INFO("------------------------------------\n");*/
  3744. }
  3745. if(maxProfile.id != -1)
  3746. {
  3747. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3748. {
  3749. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3750. {
  3751. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3752. 0:
  3753. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3754. }
  3755. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3756. {
  3757. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3758. {
  3759. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3760. 0:
  3761. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3762. if(idxPeriod > 0)
  3763. {
  3764. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3765. {
  3766. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3767. }
  3768. }
  3769. }
  3770. }
  3771. }
  3772. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3773. {
  3774. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3775. {
  3776. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3777. }
  3778. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3779. {
  3780. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3781. {
  3782. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3783. if(idxPeriod > 0)
  3784. {
  3785. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3786. {
  3787. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3788. }
  3789. }
  3790. }
  3791. }
  3792. }
  3793. else
  3794. {
  3795. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3796. {
  3797. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3798. {
  3799. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3800. 0:
  3801. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3802. }
  3803. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3804. {
  3805. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3806. {
  3807. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3808. 0:
  3809. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3810. if(idxPeriod > 0)
  3811. {
  3812. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3813. {
  3814. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3815. }
  3816. }
  3817. }
  3818. }
  3819. }
  3820. else
  3821. {
  3822. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3823. {
  3824. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3825. 0:
  3826. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3827. }
  3828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3829. {
  3830. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3831. {
  3832. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3833. 0:
  3834. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3835. if(idxPeriod > 0)
  3836. {
  3837. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3838. {
  3839. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3840. }
  3841. }
  3842. }
  3843. }
  3844. }
  3845. }
  3846. /*
  3847. DEBUG_INFO("MaxProfile after align.\n");
  3848. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3849. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3850. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3851. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3852. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3853. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3854. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3855. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3856. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3857. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3858. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3859. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3860. {
  3861. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3862. {
  3863. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3864. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3865. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3866. }
  3867. }
  3868. DEBUG_INFO("------------------------------------\n");*/
  3869. }
  3870. // Find each profile period quantity
  3871. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  3872. {
  3873. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  3874. limitMax = idx+1;
  3875. }
  3876. if(maxProfile.id != -1)
  3877. {
  3878. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3879. {
  3880. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3881. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3882. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  3883. {
  3884. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3885. {
  3886. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3887. compositePeriodIdx++;
  3888. }
  3889. else
  3890. {
  3891. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3892. }
  3893. }
  3894. }
  3895. }
  3896. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  3897. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3898. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  3899. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  3900. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3901. {
  3902. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  3903. {
  3904. compositeProfile.id = 1;
  3905. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3906. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  3907. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  3908. }
  3909. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  3910. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  3911. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  3912. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  3913. }
  3914. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3915. if(line)
  3916. free(line);
  3917. }
  3918. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3919. {
  3920. FILE *fp;
  3921. char profileFileName[128];
  3922. char *line = NULL;
  3923. size_t len = 0;
  3924. time_t CurrentTime;
  3925. struct tm *tmComposite;
  3926. struct ChargingProfileType maxProfile;
  3927. struct ChargingProfileType defaultTxProfile;
  3928. struct ChargingProfileType txProfile;
  3929. struct ChargingProfileType compositeProfile;
  3930. struct ChargingSchedulePeriodType tmpPeriod;
  3931. uint8_t limitMax=0;
  3932. uint8_t limitDef=0;
  3933. uint8_t limitTx=0;
  3934. int compositePeriodIdx = 0;
  3935. CurrentTime = time(NULL);
  3936. tmComposite=localtime(&CurrentTime);
  3937. 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);
  3938. if(isUnitA)
  3939. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3940. else
  3941. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3942. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3943. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3944. {
  3945. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3946. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3947. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3948. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  3949. }
  3950. compositeProfile.id = 0;
  3951. compositeProfile.stackLevel = 99 ;
  3952. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  3953. maxProfile.id = -1;
  3954. defaultTxProfile.id = -1;
  3955. txProfile.id = -1;
  3956. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3957. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  3958. txProfile.chargingSchedule[idxSchedule].duration = -1;
  3959. system("rm -f /tmp/*.json");
  3960. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3961. /*
  3962. * Search valid charging profile
  3963. */
  3964. //DEBUG_INFO("====================================\n");
  3965. // Search tx profile
  3966. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", connectorId);
  3967. if((access(profileFileName, F_OK))!=-1)
  3968. {
  3969. fp = fopen(profileFileName, "r");
  3970. while(getline(&line, &len, fp) != -1)
  3971. {
  3972. json_object *obj = NULL;
  3973. obj = json_tokener_parse(line);
  3974. if(is_error(obj))
  3975. {
  3976. DEBUG_ERROR("Parse txProfile from file error.\n");
  3977. }
  3978. else
  3979. {
  3980. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  3981. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  3982. )
  3983. {
  3984. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3985. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3986. )
  3987. {
  3988. struct tm tmFrom, tmTo;
  3989. struct timeb tbFrom, tbTo;
  3990. 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) &&
  3991. (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))
  3992. {
  3993. tmFrom.tm_year -= 1900;
  3994. tmFrom.tm_mon -= 1;
  3995. tbFrom.time = mktime(&tmFrom);
  3996. tmTo.tm_year -= 1900;
  3997. tmTo.tm_mon -= 1;
  3998. tbTo.time = mktime(&tmTo);
  3999. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4000. {
  4001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4002. {
  4003. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4004. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4005. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4006. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4007. }
  4008. if(txProfile.id == -1)
  4009. DEBUG_INFO("TxProfile found.\n");
  4010. else
  4011. DEBUG_INFO("TxProfile updated.\n");
  4012. // Required item
  4013. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4014. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4015. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4016. if(isUnitA)
  4017. {
  4018. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4019. 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++)
  4020. {
  4021. 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"));
  4022. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4023. 3:
  4024. 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")));
  4025. 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")));
  4026. }
  4027. }
  4028. else
  4029. {
  4030. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4031. 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++)
  4032. {
  4033. 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"));
  4034. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4035. 3:
  4036. 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")));
  4037. 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));
  4038. }
  4039. }
  4040. // Optional item
  4041. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4042. {
  4043. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4044. }
  4045. else
  4046. {
  4047. sprintf((char*)txProfile.validFrom, " ");
  4048. }
  4049. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4050. {
  4051. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4052. }
  4053. else
  4054. {
  4055. sprintf((char*)txProfile.validTo, " ");
  4056. }
  4057. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4058. {
  4059. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4060. }
  4061. else
  4062. {
  4063. sprintf((char*)txProfile.recurrencyKind, " ");
  4064. }
  4065. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4066. {
  4067. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4068. }
  4069. else
  4070. {
  4071. sprintf((char*)txProfile.transactionId, " ");
  4072. }
  4073. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4074. {
  4075. 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"));
  4076. }
  4077. else
  4078. {
  4079. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4080. }
  4081. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4082. {
  4083. 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")));
  4084. }
  4085. else
  4086. {
  4087. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4088. }
  4089. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4090. {
  4091. 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"));
  4092. }
  4093. else
  4094. {
  4095. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4096. }
  4097. }
  4098. }
  4099. }
  4100. else
  4101. {
  4102. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4103. {
  4104. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4105. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4106. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4107. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4108. }
  4109. if(txProfile.id == -1)
  4110. DEBUG_INFO("TxProfile found.\n");
  4111. else
  4112. DEBUG_INFO("TxProfile updated.\n");
  4113. // Required item
  4114. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4115. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4116. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4117. if(isUnitA)
  4118. {
  4119. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4120. 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++)
  4121. {
  4122. 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"));
  4123. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4124. 3:
  4125. 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")));
  4126. 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")));
  4127. }
  4128. }
  4129. else
  4130. {
  4131. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4132. 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++)
  4133. {
  4134. 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"));
  4135. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4136. 3:
  4137. 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")));
  4138. 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));
  4139. }
  4140. }
  4141. // Optional item
  4142. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4143. {
  4144. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4145. }
  4146. else
  4147. {
  4148. sprintf((char*)txProfile.validFrom, " ");
  4149. }
  4150. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4151. {
  4152. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4153. }
  4154. else
  4155. {
  4156. sprintf((char*)txProfile.validTo, " ");
  4157. }
  4158. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4159. {
  4160. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4161. }
  4162. else
  4163. {
  4164. sprintf((char*)txProfile.recurrencyKind, " ");
  4165. }
  4166. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4167. {
  4168. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4169. }
  4170. else
  4171. {
  4172. sprintf((char*)txProfile.transactionId, " ");
  4173. }
  4174. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4175. {
  4176. 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"));
  4177. }
  4178. else
  4179. {
  4180. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4181. }
  4182. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4183. {
  4184. 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")));
  4185. }
  4186. else
  4187. {
  4188. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4189. }
  4190. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4191. {
  4192. 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"));
  4193. }
  4194. else
  4195. {
  4196. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4197. }
  4198. }
  4199. }
  4200. }
  4201. json_object_put(obj);
  4202. }
  4203. fclose(fp);
  4204. /*
  4205. if(txProfile.id != -1)
  4206. {
  4207. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4208. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4209. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4210. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4211. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4212. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4213. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4214. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4215. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4216. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4217. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4219. {
  4220. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4221. {
  4222. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4223. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4224. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4225. }
  4226. }
  4227. }
  4228. else
  4229. DEBUG_INFO("TxProfile not found.\n");*/
  4230. }
  4231. // Search default tx profile
  4232. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", connectorId);
  4233. if((access(profileFileName, F_OK))==-1)
  4234. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4235. if((access(profileFileName, F_OK))!=-1)
  4236. {
  4237. fp = fopen(profileFileName, "r");
  4238. while(getline(&line, &len, fp) != -1)
  4239. {
  4240. json_object *obj = NULL;
  4241. obj = json_tokener_parse(line);
  4242. if(is_error(obj))
  4243. {
  4244. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4245. }
  4246. else
  4247. {
  4248. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  4249. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  4250. )
  4251. {
  4252. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4253. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4254. )
  4255. {
  4256. struct tm tmFrom, tmTo;
  4257. struct timeb tbFrom, tbTo;
  4258. 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) &&
  4259. (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))
  4260. {
  4261. tmFrom.tm_year -= 1900;
  4262. tmFrom.tm_mon -= 1;
  4263. tbFrom.time = mktime(&tmFrom);
  4264. tmTo.tm_year -= 1900;
  4265. tmTo.tm_mon -= 1;
  4266. tbTo.time = mktime(&tmTo);
  4267. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4268. {
  4269. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4270. {
  4271. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4272. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4273. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4274. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4275. }
  4276. if(defaultTxProfile.id == -1)
  4277. DEBUG_INFO("TxDefaultProfile found.\n");
  4278. else
  4279. DEBUG_INFO("TxDefaultProfile updated.\n");
  4280. // Required item
  4281. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4282. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4283. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4284. if(isUnitA)
  4285. {
  4286. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4287. 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++)
  4288. {
  4289. 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"));
  4290. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4291. 3:
  4292. 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")));
  4293. 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")));
  4294. }
  4295. }
  4296. else
  4297. {
  4298. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4299. 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++)
  4300. {
  4301. 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"));
  4302. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4303. 3:
  4304. 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")));
  4305. 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));
  4306. }
  4307. }
  4308. // Optional item
  4309. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4310. {
  4311. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4312. }
  4313. else
  4314. {
  4315. sprintf((char*)defaultTxProfile.validFrom, " ");
  4316. }
  4317. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4318. {
  4319. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4320. }
  4321. else
  4322. {
  4323. sprintf((char*)defaultTxProfile.validTo, " ");
  4324. }
  4325. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4326. {
  4327. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4328. }
  4329. else
  4330. {
  4331. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4332. }
  4333. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4334. {
  4335. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4336. }
  4337. else
  4338. {
  4339. sprintf((char*)defaultTxProfile.transactionId, " ");
  4340. }
  4341. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4342. {
  4343. 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"));
  4344. }
  4345. else
  4346. {
  4347. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4348. }
  4349. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4350. {
  4351. 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")));
  4352. }
  4353. else
  4354. {
  4355. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4356. }
  4357. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4358. {
  4359. 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"));
  4360. }
  4361. else
  4362. {
  4363. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4364. }
  4365. }
  4366. }
  4367. }
  4368. else
  4369. {
  4370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4371. {
  4372. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4373. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4374. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4375. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4376. }
  4377. if(defaultTxProfile.id == -1)
  4378. DEBUG_INFO("TxDefaultProfile found.\n");
  4379. else
  4380. DEBUG_INFO("TxDefaultProfile updated.\n");
  4381. // Required item
  4382. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4383. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4384. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4385. if(isUnitA)
  4386. {
  4387. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4388. 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++)
  4389. {
  4390. 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"));
  4391. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4392. 3:
  4393. 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")));
  4394. 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")));
  4395. }
  4396. }
  4397. else
  4398. {
  4399. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4400. 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++)
  4401. {
  4402. 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"));
  4403. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4404. 3:
  4405. 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")));
  4406. 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));
  4407. }
  4408. }
  4409. // Optional item
  4410. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4411. {
  4412. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4413. }
  4414. else
  4415. {
  4416. sprintf((char*)defaultTxProfile.validFrom, " ");
  4417. }
  4418. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4419. {
  4420. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4421. }
  4422. else
  4423. {
  4424. sprintf((char*)defaultTxProfile.validTo, " ");
  4425. }
  4426. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4427. {
  4428. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4429. }
  4430. else
  4431. {
  4432. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4433. }
  4434. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4435. {
  4436. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4437. }
  4438. else
  4439. {
  4440. sprintf((char*)defaultTxProfile.transactionId, " ");
  4441. }
  4442. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4443. {
  4444. 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"));
  4445. }
  4446. else
  4447. {
  4448. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4449. }
  4450. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4451. {
  4452. 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")));
  4453. }
  4454. else
  4455. {
  4456. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4457. }
  4458. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4459. {
  4460. 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"));
  4461. }
  4462. else
  4463. {
  4464. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4465. }
  4466. }
  4467. }
  4468. }
  4469. json_object_put(obj);
  4470. }
  4471. fclose(fp);
  4472. /*
  4473. if(defaultTxProfile.id != -1)
  4474. {
  4475. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  4476. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4477. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4478. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4479. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4480. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4481. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  4482. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4483. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4484. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4485. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4486. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4487. {
  4488. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4489. {
  4490. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4491. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4492. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4493. }
  4494. }
  4495. }
  4496. else
  4497. DEBUG_INFO("TxDefaultProfile not found.\n");
  4498. DEBUG_INFO("------------------------------------\n");*/
  4499. }
  4500. // Search max profile
  4501. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4502. if((access(profileFileName, F_OK))!=-1)
  4503. {
  4504. fp = fopen(profileFileName, "r");
  4505. while(getline(&line, &len, fp) != -1)
  4506. {
  4507. json_object *obj = NULL;
  4508. obj = json_tokener_parse(line);
  4509. if(is_error(obj))
  4510. {
  4511. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4512. }
  4513. else
  4514. {
  4515. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4516. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4517. )
  4518. {
  4519. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4520. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4521. )
  4522. {
  4523. struct tm tmFrom, tmTo;
  4524. struct timeb tbFrom, tbTo;
  4525. 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) &&
  4526. (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))
  4527. {
  4528. tmFrom.tm_year -= 1900;
  4529. tmFrom.tm_mon -= 1;
  4530. tbFrom.time = mktime(&tmFrom);
  4531. tmTo.tm_year -= 1900;
  4532. tmTo.tm_mon -= 1;
  4533. tbTo.time = mktime(&tmTo);
  4534. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4535. {
  4536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4537. {
  4538. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4539. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4540. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4541. }
  4542. if(maxProfile.id == -1)
  4543. DEBUG_INFO("MaxProfile found.\n");
  4544. else
  4545. DEBUG_INFO("MaxProfile updated.\n");
  4546. // Required item
  4547. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4548. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4549. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4550. if(isUnitA)
  4551. {
  4552. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4553. 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++)
  4554. {
  4555. 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"));
  4556. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4557. 3:
  4558. 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")));
  4559. 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")));
  4560. }
  4561. }
  4562. else
  4563. {
  4564. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4565. 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++)
  4566. {
  4567. 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"));
  4568. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4569. 3:
  4570. 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")));
  4571. 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));
  4572. }
  4573. }
  4574. // Optional item
  4575. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4576. {
  4577. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4578. }
  4579. else
  4580. {
  4581. sprintf((char*)maxProfile.validFrom, " ");
  4582. }
  4583. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4584. {
  4585. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4586. }
  4587. else
  4588. {
  4589. sprintf((char*)maxProfile.validTo, " ");
  4590. }
  4591. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4592. {
  4593. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4594. }
  4595. else
  4596. {
  4597. sprintf((char*)maxProfile.recurrencyKind, " ");
  4598. }
  4599. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4600. {
  4601. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4602. }
  4603. else
  4604. {
  4605. sprintf((char*)maxProfile.transactionId, " ");
  4606. }
  4607. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4608. {
  4609. 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"));
  4610. }
  4611. else
  4612. {
  4613. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4614. }
  4615. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4616. {
  4617. 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")));
  4618. }
  4619. else
  4620. {
  4621. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4622. }
  4623. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4624. {
  4625. 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"));
  4626. }
  4627. else
  4628. {
  4629. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4630. }
  4631. }
  4632. }
  4633. }
  4634. else
  4635. {
  4636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4637. {
  4638. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4639. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4640. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4641. }
  4642. if(maxProfile.id == -1)
  4643. DEBUG_INFO("MaxProfile found.\n");
  4644. else
  4645. DEBUG_INFO("MaxProfile updated.\n");
  4646. // Required item
  4647. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4648. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4649. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4650. if(isUnitA)
  4651. {
  4652. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4653. 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++)
  4654. {
  4655. 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"));
  4656. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4657. 3:
  4658. 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")));
  4659. 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")));
  4660. }
  4661. }
  4662. else
  4663. {
  4664. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4665. 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++)
  4666. {
  4667. 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"));
  4668. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (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?
  4669. 3:
  4670. 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")));
  4671. 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));
  4672. }
  4673. }
  4674. // Optional item
  4675. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4676. {
  4677. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4678. }
  4679. else
  4680. {
  4681. sprintf((char*)maxProfile.validFrom, " ");
  4682. }
  4683. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4684. {
  4685. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4686. }
  4687. else
  4688. {
  4689. sprintf((char*)maxProfile.validTo, " ");
  4690. }
  4691. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4692. {
  4693. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4694. }
  4695. else
  4696. {
  4697. sprintf((char*)maxProfile.recurrencyKind, " ");
  4698. }
  4699. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4700. {
  4701. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4702. }
  4703. else
  4704. {
  4705. sprintf((char*)maxProfile.transactionId, " ");
  4706. }
  4707. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4708. {
  4709. 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"));
  4710. }
  4711. else
  4712. {
  4713. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4714. }
  4715. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4716. {
  4717. 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")));
  4718. }
  4719. else
  4720. {
  4721. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4722. }
  4723. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4724. {
  4725. 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"));
  4726. }
  4727. else
  4728. {
  4729. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4730. }
  4731. }
  4732. }
  4733. }
  4734. json_object_put(obj);
  4735. }
  4736. fclose(fp);
  4737. /*
  4738. if(maxProfile.id !=-1)
  4739. {
  4740. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4741. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4742. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4743. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4744. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4745. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4746. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4747. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4748. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4749. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4750. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4752. {
  4753. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4754. {
  4755. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4756. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4757. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4758. }
  4759. }
  4760. }
  4761. else
  4762. DEBUG_INFO("MaxProfile not found.\n");
  4763. DEBUG_INFO("------------------------------------\n");*/
  4764. }
  4765. /*
  4766. * Align found profile start schedule & periods
  4767. */
  4768. //DEBUG_INFO("====================================\n");
  4769. /*
  4770. // For local test usage, force modify found profile start schedule info
  4771. 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);
  4772. 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);
  4773. 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);
  4774. */
  4775. if(txProfile.id != -1)
  4776. {
  4777. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4778. {
  4779. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4780. {
  4781. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4782. 0:
  4783. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4784. }
  4785. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4786. {
  4787. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4788. {
  4789. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4790. 0:
  4791. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4792. if(idxPeriod > 0)
  4793. {
  4794. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4795. {
  4796. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4797. }
  4798. }
  4799. }
  4800. }
  4801. }
  4802. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4803. {
  4804. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4805. {
  4806. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4807. 0:
  4808. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4809. }
  4810. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4811. {
  4812. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4813. {
  4814. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4815. 0:
  4816. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4817. if(idxPeriod > 0)
  4818. {
  4819. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4820. {
  4821. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4822. }
  4823. }
  4824. }
  4825. }
  4826. }
  4827. else
  4828. {
  4829. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4830. {
  4831. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4832. {
  4833. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4834. 0:
  4835. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4836. }
  4837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4838. {
  4839. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4840. {
  4841. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4842. 0:
  4843. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4844. if(idxPeriod > 0)
  4845. {
  4846. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4847. {
  4848. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4849. }
  4850. }
  4851. }
  4852. }
  4853. }
  4854. else
  4855. {
  4856. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4857. {
  4858. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4859. 0:
  4860. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4861. }
  4862. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4863. {
  4864. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4865. {
  4866. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4867. 0:
  4868. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4869. if(idxPeriod > 0)
  4870. {
  4871. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4872. {
  4873. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4874. }
  4875. }
  4876. }
  4877. }
  4878. }
  4879. }
  4880. /*
  4881. DEBUG_INFO("txProfile after align.\n");
  4882. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4883. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4884. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4885. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4886. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4887. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4888. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4889. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4890. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4891. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4892. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4894. {
  4895. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4896. {
  4897. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4898. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4899. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4900. }
  4901. }*/
  4902. }
  4903. if(defaultTxProfile.id != -1)
  4904. {
  4905. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4906. {
  4907. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4908. {
  4909. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4910. 0:
  4911. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4912. }
  4913. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4914. {
  4915. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4916. {
  4917. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4918. 0:
  4919. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4920. if(idxPeriod > 0)
  4921. {
  4922. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4923. {
  4924. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4925. }
  4926. }
  4927. }
  4928. }
  4929. }
  4930. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4931. {
  4932. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4933. {
  4934. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4935. 0:
  4936. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4937. }
  4938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4939. {
  4940. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4941. {
  4942. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4943. 0:
  4944. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4945. if(idxPeriod > 0)
  4946. {
  4947. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4948. {
  4949. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4950. }
  4951. }
  4952. }
  4953. }
  4954. }
  4955. else
  4956. {
  4957. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4958. {
  4959. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4960. {
  4961. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4962. 0:
  4963. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4964. }
  4965. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4966. {
  4967. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4968. {
  4969. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4970. 0:
  4971. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4972. if(idxPeriod > 0)
  4973. {
  4974. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4975. {
  4976. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4977. }
  4978. }
  4979. }
  4980. }
  4981. }
  4982. else
  4983. {
  4984. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4985. {
  4986. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4987. 0:
  4988. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4989. }
  4990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4991. {
  4992. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4993. {
  4994. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4995. 0:
  4996. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4997. if(idxPeriod > 0)
  4998. {
  4999. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5000. {
  5001. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5002. }
  5003. }
  5004. }
  5005. }
  5006. }
  5007. }
  5008. /*
  5009. DEBUG_INFO("defaultTxProfile after align.\n");
  5010. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5011. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5012. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5013. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5014. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5015. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5016. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5017. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5018. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5019. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5020. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5021. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5022. {
  5023. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5024. {
  5025. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5026. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5027. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5028. }
  5029. }
  5030. DEBUG_INFO("------------------------------------\n");*/
  5031. }
  5032. if(maxProfile.id != -1)
  5033. {
  5034. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5035. {
  5036. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5037. {
  5038. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5039. 0:
  5040. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5041. }
  5042. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5043. {
  5044. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5045. {
  5046. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5047. 0:
  5048. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5049. if(idxPeriod > 0)
  5050. {
  5051. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5052. {
  5053. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5054. }
  5055. }
  5056. }
  5057. }
  5058. }
  5059. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5060. {
  5061. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5062. {
  5063. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5064. 0:
  5065. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5066. }
  5067. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5068. {
  5069. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5070. {
  5071. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5072. 0:
  5073. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5074. if(idxPeriod > 0)
  5075. {
  5076. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5077. {
  5078. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5079. }
  5080. }
  5081. }
  5082. }
  5083. }
  5084. else
  5085. {
  5086. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5087. {
  5088. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5089. {
  5090. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5091. 0:
  5092. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5093. }
  5094. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5095. {
  5096. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5097. {
  5098. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5099. 0:
  5100. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5101. if(idxPeriod > 0)
  5102. {
  5103. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5104. {
  5105. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5106. }
  5107. }
  5108. }
  5109. }
  5110. }
  5111. else
  5112. {
  5113. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5114. {
  5115. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5116. 0:
  5117. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5118. }
  5119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5120. {
  5121. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5122. {
  5123. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5124. 0:
  5125. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5126. if(idxPeriod > 0)
  5127. {
  5128. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5129. {
  5130. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5131. }
  5132. }
  5133. }
  5134. }
  5135. }
  5136. }
  5137. /*
  5138. DEBUG_INFO("MaxProfile after align.\n");
  5139. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5140. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5141. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5142. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5143. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5144. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5145. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5146. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5147. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5148. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5149. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5150. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5151. {
  5152. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5153. {
  5154. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5155. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5156. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5157. }
  5158. }
  5159. DEBUG_INFO("------------------------------------\n");*/
  5160. }
  5161. /*
  5162. * Merge to conposite schedule
  5163. */
  5164. //DEBUG_INFO("====================================\n");
  5165. // Find each profile period quantity
  5166. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5167. {
  5168. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5169. limitMax = idx+1;
  5170. }
  5171. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5172. {
  5173. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5174. limitDef = idx+1;
  5175. }
  5176. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5177. {
  5178. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5179. limitTx = idx+1;
  5180. }
  5181. // TxProfile found, composite schedule based on it
  5182. if(txProfile.id != -1)
  5183. {
  5184. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  5185. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  5186. {
  5187. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  5188. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  5189. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  5190. {
  5191. if(maxProfile.id != -1)
  5192. {
  5193. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5194. {
  5195. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  5196. {
  5197. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5198. {
  5199. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5200. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5201. 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);
  5202. }
  5203. else
  5204. {
  5205. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5206. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5207. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  5208. }
  5209. }
  5210. if(idxMaxPeriod == (limitMax-1))
  5211. {
  5212. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5213. {
  5214. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5215. {
  5216. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5217. compositePeriodIdx++;
  5218. }
  5219. else
  5220. {
  5221. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5222. }
  5223. }
  5224. }
  5225. }
  5226. }
  5227. else
  5228. {
  5229. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5230. {
  5231. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5232. compositePeriodIdx++;
  5233. }
  5234. else
  5235. {
  5236. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5237. }
  5238. }
  5239. }
  5240. if(idxTxPeriod == (limitTx-1))
  5241. {
  5242. if(defaultTxProfile.id != -1)
  5243. {
  5244. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  5245. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5246. {
  5247. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  5248. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5249. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  5250. {
  5251. if(maxProfile.id != -1)
  5252. {
  5253. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5254. {
  5255. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5256. {
  5257. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5258. {
  5259. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5260. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5261. 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);
  5262. }
  5263. else
  5264. {
  5265. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5266. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5267. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5268. }
  5269. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5270. {
  5271. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5272. {
  5273. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5274. compositePeriodIdx++;
  5275. }
  5276. else
  5277. {
  5278. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5279. }
  5280. }
  5281. // Delete duplicate period
  5282. if(compositePeriodIdx > 1)
  5283. {
  5284. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5285. {
  5286. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5287. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5288. compositePeriodIdx -= 1;
  5289. }
  5290. }
  5291. }
  5292. else
  5293. {
  5294. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5295. {
  5296. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5297. compositePeriodIdx++;
  5298. }
  5299. else
  5300. {
  5301. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5302. }
  5303. break;
  5304. }
  5305. }
  5306. }
  5307. else
  5308. {
  5309. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5310. {
  5311. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5312. compositePeriodIdx++;
  5313. }
  5314. else
  5315. {
  5316. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5317. }
  5318. }
  5319. }
  5320. }
  5321. }
  5322. }
  5323. }
  5324. }
  5325. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  5326. else if(defaultTxProfile.id != -1)
  5327. {
  5328. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  5329. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5330. {
  5331. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  5332. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5333. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  5334. {
  5335. if(maxProfile.id != -1)
  5336. {
  5337. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5338. {
  5339. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5340. {
  5341. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5342. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5343. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5344. {
  5345. 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);
  5346. }
  5347. else
  5348. {
  5349. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5350. }
  5351. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5352. {
  5353. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5354. {
  5355. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5356. compositePeriodIdx++;
  5357. }
  5358. else
  5359. {
  5360. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5361. }
  5362. }
  5363. // Delete duplicate period
  5364. if(compositePeriodIdx > 1)
  5365. {
  5366. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5367. {
  5368. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5369. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5370. compositePeriodIdx -= 1;
  5371. }
  5372. }
  5373. }
  5374. else
  5375. {
  5376. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5377. {
  5378. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5379. compositePeriodIdx++;
  5380. }
  5381. else
  5382. {
  5383. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5384. }
  5385. break;
  5386. }
  5387. }
  5388. }
  5389. else
  5390. {
  5391. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5392. {
  5393. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5394. compositePeriodIdx++;
  5395. }
  5396. else
  5397. {
  5398. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5399. }
  5400. }
  5401. }
  5402. }
  5403. }
  5404. // Fill other period by MaxProfile
  5405. if(maxProfile.id != -1)
  5406. {
  5407. if(compositePeriodIdx==0)
  5408. {
  5409. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  5410. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  5411. {
  5412. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5413. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5414. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5415. {
  5416. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5417. {
  5418. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5419. compositePeriodIdx++;
  5420. }
  5421. else
  5422. {
  5423. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5424. }
  5425. }
  5426. }
  5427. }
  5428. else
  5429. {
  5430. int lastCompositePeriodIdx = compositePeriodIdx;
  5431. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5432. {
  5433. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5434. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5435. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5436. {
  5437. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  5438. {
  5439. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  5440. {
  5441. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5442. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5443. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  5444. }
  5445. else
  5446. {
  5447. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5448. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5449. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  5450. }
  5451. }
  5452. if(tmpPeriod.limit != -1)
  5453. {
  5454. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  5455. {
  5456. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  5457. {
  5458. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5459. compositePeriodIdx++;
  5460. }
  5461. else
  5462. {
  5463. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5464. }
  5465. }
  5466. // Delete duplicate period
  5467. if(compositePeriodIdx > 1)
  5468. {
  5469. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5470. {
  5471. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5472. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5473. compositePeriodIdx -= 1;
  5474. }
  5475. }
  5476. }
  5477. }
  5478. }
  5479. }
  5480. }
  5481. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  5482. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  5483. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  5484. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  5485. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  5486. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5487. {
  5488. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  5489. {
  5490. compositeProfile.id = 1;
  5491. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  5492. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  5493. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  5494. }
  5495. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  5496. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  5497. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  5498. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  5499. }
  5500. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  5501. if(line)
  5502. free(line);
  5503. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  5504. }
  5505. //==========================================
  5506. // Init all share memory
  5507. //==========================================
  5508. int InitShareMemory()
  5509. {
  5510. int result = PASS;
  5511. int MeterSMId;
  5512. //creat ShmSysConfigAndInfo
  5513. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  5514. {
  5515. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  5516. result = FAIL;
  5517. }
  5518. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5519. {
  5520. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  5521. result = FAIL;
  5522. }
  5523. else
  5524. {}
  5525. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  5526. {
  5527. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  5528. result = FAIL;
  5529. }
  5530. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5531. {
  5532. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  5533. result = FAIL;
  5534. }
  5535. else
  5536. {}
  5537. //creat ShmPsuData
  5538. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  5539. {
  5540. DEBUG_ERROR("shmget ShmPsuData NG\n");
  5541. result = FAIL;
  5542. }
  5543. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5544. {
  5545. DEBUG_ERROR("shmat ShmPsuData NG\n");
  5546. result = FAIL;
  5547. }
  5548. else
  5549. {}
  5550. //creat ShmOCPP20Data
  5551. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  5552. {
  5553. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  5554. result = FAIL;
  5555. }
  5556. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5557. {
  5558. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  5559. result = FAIL;
  5560. }
  5561. else
  5562. {}
  5563. /****************************** For Initial Settings************************************************/
  5564. /*
  5565. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  5566. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  5567. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  5568. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  5569. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  5570. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  5571. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  5572. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  5573. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  5574. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  5575. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  5576. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  5577. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  5578. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  5579. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  5580. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  5581. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  5582. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  5583. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  5584. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  5585. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  5586. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  5587. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  5588. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  5589. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  5590. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  5591. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  5592. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  5593. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  5594. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  5595. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  5596. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  5597. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  5598. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  5599. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  5600. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  5601. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  5602. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  5603. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  5604. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  5605. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  5606. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  5607. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  5608. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  5609. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  5610. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  5611. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  5612. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  5613. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  5614. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  5615. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  5616. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  5617. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  5618. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  5619. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  5620. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  5621. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  5622. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  5623. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  5624. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  5625. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  5626. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  5627. */
  5628. return result;
  5629. }
  5630. int ProcessShareMemory()
  5631. {
  5632. int result = PASS;
  5633. if(InitShareMemory() == FAIL)
  5634. {
  5635. DEBUG_ERROR("InitShareMemory NG\n");
  5636. if(ShmStatusCodeData!=NULL)
  5637. {
  5638. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5639. }
  5640. result = FAIL;
  5641. }
  5642. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  5643. {
  5644. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  5645. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  5646. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  5647. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  5648. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  5649. ) // 'D' means DC
  5650. {
  5651. // DO series
  5652. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  5653. {
  5654. gunTotalNumber += 1;
  5655. gunType[gun_index] = GUN_TYPE_DO;
  5656. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5657. {
  5658. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  5659. {
  5660. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5661. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5662. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  5663. }
  5664. }
  5665. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5666. {
  5667. case Gun_Type_Chademo:
  5668. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  5669. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5672. {
  5673. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5674. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5675. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  5676. }
  5677. }
  5678. break;
  5679. case Gun_Type_CCS_2:
  5680. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  5681. for (int index = 0; index < CCS_QUANTITY; index++)
  5682. {
  5683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5684. {
  5685. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5686. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5687. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  5688. }
  5689. }
  5690. break;
  5691. case Gun_Type_GB:
  5692. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  5693. for (int index = 0; index < GB_QUANTITY; index++)
  5694. {
  5695. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5696. {
  5697. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5698. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5699. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  5700. }
  5701. }
  5702. break;
  5703. case Gun_Type_AC:
  5704. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  5705. for (int index = 0; index < AC_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  5708. {
  5709. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5710. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5711. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  5712. }
  5713. }
  5714. break;
  5715. default:
  5716. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  5717. break;
  5718. }
  5719. }
  5720. }
  5721. else
  5722. {
  5723. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  5724. {
  5725. gunTotalNumber += 1;
  5726. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5727. {
  5728. case Gun_Type_Chademo:
  5729. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  5730. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  5731. break;
  5732. case Gun_Type_CCS_2:
  5733. gunType[gun_index] = GUN_TYPE_CCS;
  5734. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  5735. break;
  5736. case Gun_Type_GB:
  5737. gunType[gun_index] = GUN_TYPE_GBT;
  5738. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  5739. break;
  5740. case Gun_Type_AC:
  5741. gunType[gun_index] = GUN_TYPE_AC;
  5742. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  5743. break;
  5744. default:
  5745. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  5746. break;
  5747. }
  5748. }
  5749. }
  5750. }
  5751. else
  5752. {
  5753. DEBUG_ERROR("Model name parsing fail.\n");
  5754. result = FAIL;
  5755. }
  5756. if(result != PASS)sleep(5);
  5757. return result;
  5758. }
  5759. //---------------------common routine---------------------------//
  5760. void checkNetworkProfile(void)
  5761. {
  5762. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  5763. json_object *priority;
  5764. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  5765. if(!is_error(priority))
  5766. {
  5767. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  5768. {
  5769. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  5770. {
  5771. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  5772. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  5773. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  5774. {
  5775. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  5776. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  5777. break;
  5778. }
  5779. }
  5780. }
  5781. }
  5782. json_object_put(priority);
  5783. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  5784. }
  5785. void checkRemoteStart(uint8_t connectorIdx)
  5786. {
  5787. uint8_t tempIndex;
  5788. int isAllowStart = TRUE;
  5789. char cmdBuf[512];
  5790. //check Transaction active
  5791. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5794. {
  5795. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5796. }
  5797. else
  5798. {
  5799. tempIndex = (connectorIdx-1);
  5800. }
  5801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  5804. {
  5805. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5806. {
  5807. //Reserved
  5808. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  5809. }
  5810. 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[connectorIdx-1].idToken.idToken) != 0))
  5811. {
  5812. //Reserved
  5813. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  5814. isAllowStart = FALSE;
  5815. }
  5816. else
  5817. {
  5818. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5819. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  5820. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  5821. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  5822. {
  5823. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  5824. isAllowStart = FALSE;
  5825. }
  5826. }//END FOR ELSE
  5827. }
  5828. }// END FOR CHAdeMO_QUANTITY
  5829. }
  5830. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5835. }
  5836. else
  5837. {
  5838. tempIndex = (connectorIdx-1);
  5839. }
  5840. for (int index = 0; index < CCS_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5843. {
  5844. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5845. {
  5846. //Reserved
  5847. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  5848. }
  5849. 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[connectorIdx-1].idToken.idToken) != 0))
  5850. {
  5851. //Reserved
  5852. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  5853. isAllowStart = FALSE;
  5854. }
  5855. else
  5856. {
  5857. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5858. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5859. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5860. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5861. {
  5862. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  5863. isAllowStart = FALSE;
  5864. }
  5865. }// END FOR ELSE
  5866. }
  5867. }// END FOR CCS_QUANTITY
  5868. }
  5869. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  5870. {
  5871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5872. {
  5873. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5874. }
  5875. else
  5876. {
  5877. tempIndex = (connectorIdx-1);
  5878. }
  5879. for (int index = 0; index < GB_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  5882. {
  5883. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5884. {
  5885. //Reserved
  5886. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  5887. }
  5888. 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[connectorIdx-1].idToken.idToken) != 0))
  5889. {
  5890. //Reserved
  5891. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  5892. isAllowStart = FALSE;
  5893. }
  5894. else
  5895. {
  5896. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5897. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5898. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5899. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5900. {
  5901. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  5902. isAllowStart = FALSE;
  5903. }
  5904. }// END FOR ELSE
  5905. }
  5906. } // END FOR GB_QUANTITY
  5907. }
  5908. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  5909. {
  5910. tempIndex = (connectorIdx-1);
  5911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  5914. {
  5915. 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[connectorIdx-1].idToken.idToken) == 0))
  5916. {
  5917. //Reserved
  5918. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  5919. }
  5920. 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[connectorIdx-1].idToken.idToken) != 0))
  5921. {
  5922. //Reserved
  5923. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  5924. isAllowStart = FALSE;
  5925. }
  5926. else
  5927. {
  5928. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5929. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5930. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5931. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5932. {
  5933. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  5934. isAllowStart = FALSE;
  5935. }
  5936. }// END FOR ELSE
  5937. }
  5938. } // END FOR GB_QUANTITY
  5939. }
  5940. else
  5941. {
  5942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5943. {
  5944. tempIndex = 2;
  5945. }
  5946. else
  5947. {
  5948. tempIndex = (connectorIdx-1);
  5949. }
  5950. for (int index = 0; index < AC_QUANTITY; index++)
  5951. {
  5952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  5953. {
  5954. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5955. {
  5956. //Reserved
  5957. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  5958. }
  5959. 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[connectorIdx-1].idToken.idToken) != 0))
  5960. {
  5961. //Reserved
  5962. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  5963. isAllowStart = FALSE;
  5964. }
  5965. else
  5966. {
  5967. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5968. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5969. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5970. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5971. {
  5972. DEBUG_WARN("AC connector not allow start cause busy.\n");
  5973. isAllowStart = FALSE;
  5974. }
  5975. }//END FOR ELSE
  5976. }
  5977. }// END FOR AC_QUANTITY
  5978. }
  5979. if(isAllowStart == TRUE)
  5980. {
  5981. if(ShmOCPP20Data->RequestStartTransaction[connectorIdx -1].chargingProfile.id > 0)
  5982. {
  5983. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  5984. {
  5985. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  5986. system(cmdBuf);
  5987. }
  5988. }
  5989. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  5990. }
  5991. }
  5992. void CheckSystemValue(void)
  5993. {
  5994. char filenmae[100]={0};
  5995. char str[100]={0};
  5996. int tempIndex = 0;
  5997. //===============================
  5998. // EVSE operation check
  5999. //===============================
  6000. //===============================
  6001. // Heartbeat check
  6002. //===============================
  6003. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6004. {
  6005. //parameter for test
  6006. sendHeartbeatRequest(0);
  6007. //==============================================
  6008. // Reset Waiting Time
  6009. //==============================================
  6010. HeartBeatWithNOResponse += 1;
  6011. }
  6012. //===============================
  6013. // CSU Trigger Authorize Request
  6014. //===============================
  6015. if(isWebsocketSendable &&
  6016. (server_sign == TRUE) &&
  6017. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6018. (authorizeRetryTimes < 3))
  6019. {
  6020. sendAuthorizeRequest(0);
  6021. authorizeRetryTimes = authorizeRetryTimes + 1;
  6022. if(authorizeRetryTimes < 3)
  6023. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6024. }
  6025. else if((server_sign == TRUE) &&
  6026. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6027. (authorizeRetryTimes >= 3))
  6028. {
  6029. authorizeRetryTimes = 0;
  6030. SetOcppConnStatus(FALSE);
  6031. server_sign = FALSE;
  6032. }
  6033. else if((server_sign == FALSE) &&
  6034. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  6035. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  6036. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6037. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6038. {
  6039. sendAuthorizeRequest(0);
  6040. }
  6041. if(isWebsocketSendable &&
  6042. (server_sign == TRUE) &&
  6043. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6044. {
  6045. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6046. {
  6047. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6048. {
  6049. /*
  6050. * TODO:
  6051. * 1. Report component that are ThresholdMonitoring
  6052. */
  6053. }
  6054. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6055. {
  6056. /*
  6057. * TODO:
  6058. * 1. Report component that are DeltaMonitoring
  6059. */
  6060. }
  6061. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6062. {
  6063. /*
  6064. * TODO:
  6065. * 1. Report component that are PeriodicMonitoring
  6066. */
  6067. }
  6068. else
  6069. {
  6070. /*
  6071. * TODO:
  6072. * 1. Process unknown criteria condition
  6073. */
  6074. }
  6075. }
  6076. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6077. }
  6078. if(isWebsocketSendable &&
  6079. (server_sign == TRUE) &&
  6080. (ShmOCPP20Data->GetReport.requestId > 0))
  6081. {
  6082. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6083. {
  6084. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6085. {
  6086. /*
  6087. * TODO:
  6088. * 1. Report component that are active
  6089. */
  6090. }
  6091. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6092. {
  6093. /*
  6094. * TODO:
  6095. * 1. Report component that are available
  6096. */
  6097. }
  6098. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6099. {
  6100. /*
  6101. * TODO:
  6102. * 1. Report component that are enable
  6103. */
  6104. }
  6105. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6106. {
  6107. /*
  6108. * TODO:
  6109. * 1. Report component that are problem
  6110. */
  6111. }
  6112. else
  6113. {
  6114. /*
  6115. * TODO:
  6116. * 1. Process unknown criteria condition
  6117. */
  6118. }
  6119. }
  6120. ShmOCPP20Data->GetReport.requestId = 0;
  6121. }
  6122. if(isWebsocketSendable &&
  6123. (server_sign == TRUE) &&
  6124. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6125. {
  6126. uint8_t reportIdx = 0;
  6127. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6128. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6129. {
  6130. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6131. {
  6132. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6133. {
  6134. 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))
  6135. {
  6136. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6137. reportIdx++;
  6138. }
  6139. }
  6140. else
  6141. {
  6142. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6143. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6144. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6145. else
  6146. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6147. sendNotifyReportRequest();
  6148. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6149. reportIdx = 0;
  6150. }
  6151. }
  6152. }
  6153. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6154. {
  6155. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6156. {
  6157. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6158. {
  6159. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6160. reportIdx++;
  6161. }
  6162. else
  6163. {
  6164. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6165. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6166. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6167. else
  6168. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6169. sendNotifyReportRequest();
  6170. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6171. reportIdx = 0;
  6172. }
  6173. }
  6174. }
  6175. else
  6176. {
  6177. /*
  6178. * TODO:
  6179. * 1. Fill out summary inventory to response message, currently not support
  6180. */
  6181. }
  6182. if(reportIdx > 0)
  6183. {
  6184. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6185. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6186. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6187. else
  6188. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6189. sendNotifyReportRequest();
  6190. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6191. reportIdx = 0;
  6192. }
  6193. ShmOCPP20Data->GetBaseReport.requestId = 0;
  6194. }
  6195. if(isWebsocketSendable &&
  6196. (server_sign == TRUE) &&
  6197. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  6198. {
  6199. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  6200. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  6201. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  6202. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  6203. else
  6204. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  6205. sendNotifyEventRequest();
  6206. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  6207. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  6208. }
  6209. if(isWebsocketSendable &&
  6210. (server_sign == TRUE) &&
  6211. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  6212. {
  6213. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  6214. {
  6215. /*
  6216. * TODO:
  6217. * 1.
  6218. */
  6219. }
  6220. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  6221. {
  6222. /*
  6223. * TODO:
  6224. * 1.
  6225. */
  6226. }
  6227. else
  6228. {
  6229. /*
  6230. * TODO:
  6231. * 1.
  6232. */
  6233. }
  6234. sendGet15118EVCertificateRequest();
  6235. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  6236. }
  6237. if(isWebsocketSendable &&
  6238. (server_sign == TRUE) &&
  6239. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  6240. {
  6241. sendSecurityEventNotificationRequest();
  6242. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  6243. }
  6244. if(isWebsocketSendable &&
  6245. (server_sign == TRUE) &&
  6246. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  6247. {
  6248. sendNotifyCustomerInformationRequest();
  6249. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  6250. }
  6251. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6252. {
  6253. // ClockAlign MeterValue
  6254. 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))
  6255. {
  6256. //check Transaction active
  6257. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6258. {
  6259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6260. {
  6261. tempIndex = ((gun_index==2) ? 1: 0);
  6262. }
  6263. else
  6264. {
  6265. tempIndex = gun_index;
  6266. }
  6267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6268. {
  6269. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6270. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6271. {
  6272. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6273. }
  6274. }// End for CHAdeMO
  6275. }
  6276. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6277. {
  6278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6279. {
  6280. tempIndex = ((gun_index==2) ? 1: 0);
  6281. }
  6282. else
  6283. {
  6284. tempIndex = gun_index;
  6285. }
  6286. for (int index = 0; index < CCS_QUANTITY; index++)
  6287. {
  6288. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6289. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6290. {
  6291. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6292. }
  6293. } // End for CCS
  6294. }
  6295. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6296. {
  6297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6298. {
  6299. tempIndex = ((gun_index==2) ? 1: 0);
  6300. }
  6301. else
  6302. {
  6303. tempIndex = gun_index;
  6304. }
  6305. for (int index = 0; index < GB_QUANTITY; index++)
  6306. {
  6307. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6308. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6309. {
  6310. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6311. }
  6312. }// End for GB
  6313. }
  6314. else if(gunType[gun_index] == GUN_TYPE_DO)
  6315. {
  6316. tempIndex = gun_index;
  6317. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6318. {
  6319. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6320. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6321. {
  6322. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6323. }
  6324. }
  6325. }
  6326. else
  6327. {
  6328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6329. {
  6330. tempIndex = 2;
  6331. }
  6332. else
  6333. {
  6334. tempIndex = gun_index;
  6335. }
  6336. for (int index = 0; index < AC_QUANTITY; index++)
  6337. {
  6338. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6339. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6340. {
  6341. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6342. }
  6343. }//End for AC
  6344. }
  6345. }
  6346. }
  6347. //===============================
  6348. // Each connector operation check
  6349. //===============================
  6350. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  6351. {
  6352. //==========================================
  6353. // Check remote start without connector id
  6354. //==========================================
  6355. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  6356. {
  6357. int connectorIdInt = -1;
  6358. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  6359. {
  6360. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  6361. {
  6362. connectorIdInt = (gun_index+1);
  6363. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  6364. checkRemoteStart(connectorIdInt);
  6365. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6366. break;
  6367. }
  6368. }
  6369. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  6370. {
  6371. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  6372. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6373. }
  6374. }
  6375. //==========================================
  6376. // csu trigger DataTransferReq
  6377. //==========================================
  6378. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  6379. {
  6380. sendDataTransferRequest(gun_index);
  6381. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  6382. }
  6383. //==============================================
  6384. // Charger status notification & Transaction event report
  6385. //==============================================
  6386. //--- Check Mode Change ---//
  6387. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6399. {
  6400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6401. {
  6402. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  6403. {
  6404. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  6405. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  6406. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6407. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6409. {
  6410. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6411. }
  6412. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6413. {
  6414. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6415. if((access(filenmae,F_OK))!=-1)
  6416. {
  6417. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6418. sprintf(str,"rm -f %s",filenmae);
  6419. system(str);
  6420. }
  6421. }
  6422. }
  6423. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6424. #if 1 // for TempStopTransaction
  6425. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6426. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6427. {
  6428. checkTempStopTransaction(gun_index);
  6429. }
  6430. #endif
  6431. }
  6432. }
  6433. }
  6434. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6435. {
  6436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6437. {
  6438. tempIndex = ((gun_index==2) ? 1: 0);
  6439. }
  6440. else
  6441. {
  6442. tempIndex = gun_index;
  6443. }
  6444. for (int index = 0; index < CCS_QUANTITY; index++)
  6445. {
  6446. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6447. {
  6448. 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]*/ )
  6449. {
  6450. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  6451. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  6452. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6453. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6454. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6455. {
  6456. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6457. }
  6458. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6459. {
  6460. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6461. if((access(filenmae,F_OK))!=-1)
  6462. {
  6463. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6464. sprintf(str,"rm -f %s",filenmae);
  6465. system(str);
  6466. }
  6467. }
  6468. }
  6469. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6470. #if 1 // for TempStopTransaction
  6471. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6472. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6473. {
  6474. checkTempStopTransaction(gun_index);
  6475. }
  6476. #endif
  6477. }
  6478. }
  6479. }
  6480. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6481. {
  6482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6483. {
  6484. tempIndex = ((gun_index==2) ? 1: 0);
  6485. }
  6486. else
  6487. {
  6488. tempIndex = gun_index;
  6489. }
  6490. for (int index = 0; index < GB_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6493. {
  6494. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  6495. {
  6496. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  6497. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  6498. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6499. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6500. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6501. {
  6502. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6503. }
  6504. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6505. {
  6506. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6507. if((access(filenmae,F_OK))!=-1)
  6508. {
  6509. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6510. sprintf(str,"rm -f %s",filenmae);
  6511. system(str);
  6512. }
  6513. }
  6514. }
  6515. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6516. #if 1 // for TempStopTransaction
  6517. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6518. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6519. {
  6520. checkTempStopTransaction(gun_index);
  6521. }
  6522. #endif
  6523. }
  6524. }
  6525. }
  6526. else if(gunType[gun_index] == GUN_TYPE_DO)
  6527. {
  6528. tempIndex = gun_index;
  6529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6532. {
  6533. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  6534. {
  6535. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  6536. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  6537. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6538. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  6539. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  6540. {
  6541. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6542. }
  6543. 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
  6544. {
  6545. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6546. if((access(filenmae,F_OK))!=-1)
  6547. {
  6548. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6549. sprintf(str,"rm -f %s",filenmae);
  6550. system(str);
  6551. }
  6552. }
  6553. }
  6554. 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);
  6555. #if 1 // for TempStopTransaction
  6556. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  6557. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6558. {
  6559. checkTempStopTransaction(gun_index);
  6560. }
  6561. #endif
  6562. }
  6563. }
  6564. }
  6565. else
  6566. {
  6567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6568. {
  6569. tempIndex = 2;
  6570. }
  6571. else
  6572. {
  6573. tempIndex = gun_index;
  6574. }
  6575. for (int index = 0; index < AC_QUANTITY; index++)
  6576. {
  6577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6578. {
  6579. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  6580. {
  6581. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  6582. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  6583. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  6584. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6585. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6586. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6587. {
  6588. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6589. }
  6590. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6591. {
  6592. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6593. if((access(filenmae,F_OK))!=-1)
  6594. {
  6595. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6596. sprintf(str,"rm -f %s",filenmae);
  6597. system(str);
  6598. }
  6599. }
  6600. }
  6601. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6602. #if 1 // for TempStopTransaction
  6603. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6604. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6605. {
  6606. checkTempStopTransaction(gun_index);
  6607. }
  6608. #endif
  6609. }
  6610. }// END
  6611. }
  6612. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  6613. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  6614. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "TRUE") == 0) &&
  6615. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  6616. {
  6617. sendStatusNotificationRequest(gun_index);
  6618. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  6619. }
  6620. //==============================================
  6621. // CSU Trigger Smart Charging Profile
  6622. //==============================================
  6623. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  6624. {
  6625. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  6626. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  6627. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  6628. }
  6629. //==============================================
  6630. // CSU transaction event
  6631. //==============================================
  6632. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON)
  6633. {
  6634. sendTransactionEventRequest(gun_index);
  6635. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  6636. //storeTempStopTransaction(gun_index);
  6637. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  6638. }
  6639. //==============================================
  6640. // Meter report
  6641. //==============================================
  6642. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  6643. {
  6644. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  6645. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  6646. }
  6647. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  6648. {
  6649. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  6650. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  6651. }
  6652. // Sample period MeterValue
  6653. if(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))
  6654. {
  6655. //check Transaction active
  6656. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6657. {
  6658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6659. {
  6660. tempIndex = ((gun_index==2) ? 1: 0);
  6661. }
  6662. else
  6663. {
  6664. tempIndex = gun_index;
  6665. }
  6666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6667. {
  6668. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6669. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6670. {
  6671. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6672. {
  6673. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6674. }
  6675. }
  6676. }// End for CHAdeMO
  6677. }
  6678. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6679. {
  6680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6681. {
  6682. tempIndex = ((gun_index==2) ? 1: 0);
  6683. }
  6684. else
  6685. {
  6686. tempIndex = gun_index;
  6687. }
  6688. for (int index = 0; index < CCS_QUANTITY; index++)
  6689. {
  6690. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6691. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6692. {
  6693. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6694. {
  6695. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6696. }
  6697. }
  6698. } // End for CCS
  6699. }
  6700. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6701. {
  6702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6703. {
  6704. tempIndex = ((gun_index==2) ? 1: 0);
  6705. }
  6706. else
  6707. {
  6708. tempIndex = gun_index;
  6709. }
  6710. for (int index = 0; index < GB_QUANTITY; index++)
  6711. {
  6712. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6713. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6714. {
  6715. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6716. {
  6717. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6718. }
  6719. }
  6720. }// End for GB
  6721. }
  6722. else if(gunType[gun_index] == GUN_TYPE_DO)
  6723. {
  6724. tempIndex = gun_index;
  6725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6726. {
  6727. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6728. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6729. {
  6730. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  6731. {
  6732. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6733. }
  6734. }
  6735. }
  6736. }
  6737. else
  6738. {
  6739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6740. {
  6741. tempIndex = 2;
  6742. }
  6743. else
  6744. {
  6745. tempIndex = gun_index;
  6746. }
  6747. for (int index = 0; index < AC_QUANTITY; index++)
  6748. {
  6749. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6750. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6751. {
  6752. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6753. {
  6754. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6755. }
  6756. }
  6757. }//End for AC
  6758. }
  6759. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  6760. {
  6761. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  6762. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  6763. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  6764. }
  6765. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6766. }
  6767. //==============================================
  6768. // Check Connector reserved
  6769. //==============================================
  6770. //===============================
  6771. // Check if Reserve is expired
  6772. //===============================
  6773. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  6774. {
  6775. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  6776. {
  6777. DEBUG_INFO("reserve expired.\n");
  6778. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  6779. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  6780. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  6781. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  6782. }
  6783. }//END OF Check if Reserve is expired
  6784. //==========================================
  6785. // csu trigger FirmwareStatusNotificationReq
  6786. //==========================================
  6787. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  6788. {
  6789. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  6790. }
  6791. //==========================================
  6792. // csu cleared charging limit request
  6793. //==========================================
  6794. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  6795. {
  6796. sendClearedChargingLimitRequest(gun_index);
  6797. }
  6798. //==========================================
  6799. // csu trigger CancelReservationConf
  6800. //==========================================
  6801. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  6802. {
  6803. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  6804. }
  6805. //==========================================
  6806. // csu notify EV charging need request
  6807. //==========================================
  6808. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  6809. {
  6810. sendNotifyEVChargingNeedsRequest(gun_index);
  6811. }
  6812. //==========================================
  6813. // csu trigger ChangeAvailabilityConf
  6814. //==========================================
  6815. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  6816. {
  6817. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  6818. }
  6819. //==========================================
  6820. // csu trigger UnlockConnectorConf
  6821. //==========================================
  6822. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  6823. {
  6824. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  6825. }
  6826. //==========================================
  6827. // csu trigger ReserveNowConf
  6828. //==========================================
  6829. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  6830. {
  6831. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  6832. }
  6833. //==========================================
  6834. // csu trigger ReserveNowConf
  6835. //==========================================
  6836. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  6837. {
  6838. sendReservationStatusUpdateRequest(gun_index);
  6839. }
  6840. //==========================================
  6841. // csu trigger LogStatusNotificationReq
  6842. //==========================================
  6843. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  6844. {
  6845. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  6846. }
  6847. //==========================================
  6848. // csu trigger SignCertificateReq
  6849. //==========================================
  6850. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  6851. {
  6852. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  6853. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  6854. {
  6855. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  6856. }
  6857. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  6858. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  6859. {
  6860. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  6861. }
  6862. }
  6863. }
  6864. }
  6865. //==========================================
  6866. // send request routine
  6867. //==========================================
  6868. int sendAuthorizeRequest(int gun_index)
  6869. {
  6870. mtrace();
  6871. int result = FAIL;
  6872. char message[4096]={0};
  6873. char guid[37];
  6874. char tempdata[128]={0};
  6875. json_object *Authorize = json_object_new_object();
  6876. json_object *idToken = json_object_new_object();
  6877. DEBUG_INFO("sendAuthorizeRequest...\n");
  6878. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  6879. //Local Authorize
  6880. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  6881. {
  6882. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  6883. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6884. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  6885. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  6886. result = PASS;
  6887. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6888. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6889. authorizeRetryTimes = 0;
  6890. return result;
  6891. }
  6892. 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)) ||
  6893. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  6894. {
  6895. // Query idtag from cache
  6896. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  6897. // Query idtag from list
  6898. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6899. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  6900. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6901. {
  6902. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  6903. {
  6904. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6905. }
  6906. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  6907. {
  6908. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6909. }
  6910. // Return authorize result if does not connect to server
  6911. if(!ShmOCPP20Data->OcppConnStatus)
  6912. {
  6913. DEBUG_INFO("Local Authorization Fail.\n");
  6914. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6915. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6916. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  6917. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6918. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6919. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6920. authorizeRetryTimes = 0;
  6921. return result;
  6922. }
  6923. }
  6924. else
  6925. {
  6926. DEBUG_INFO("Local Authorization get result.\n");
  6927. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  6928. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6929. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  6930. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  6931. else
  6932. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  6933. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6934. result = PASS;
  6935. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6936. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6937. authorizeRetryTimes = 0;
  6938. return result;
  6939. }
  6940. }
  6941. //get data from shared memory
  6942. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6943. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  6944. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  6945. json_object_object_add(Authorize, "idToken", idToken);
  6946. random_uuid(guid);
  6947. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  6948. json_object_put(Authorize);
  6949. LWS_Send(message);
  6950. sprintf(tempdata, "Authorize,%d", gun_index);
  6951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6952. {
  6953. result = PASS;
  6954. }
  6955. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6956. return result;
  6957. }
  6958. int sendBootNotificationRequest()
  6959. {
  6960. mtrace();
  6961. int result = FAIL;
  6962. char message[4096]={0};
  6963. char guid[37]={0};
  6964. char tempdata[128]={0};
  6965. json_object *BootNotification = json_object_new_object();
  6966. json_object *chargingStation = json_object_new_object();
  6967. json_object *modem = json_object_new_object();
  6968. DEBUG_INFO("sendBootNotificationRequest...\n");
  6969. // Fill BootNotification fields
  6970. DB_getBooType();
  6971. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  6972. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6973. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  6974. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  6975. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  6976. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  6977. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  6978. {
  6979. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  6980. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  6981. json_object_object_add(chargingStation, "modem", modem);
  6982. }
  6983. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  6984. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  6985. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  6986. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  6987. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  6988. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  6989. random_uuid(guid);
  6990. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  6991. json_object_put(BootNotification);
  6992. LWS_Send(message);
  6993. sprintf(tempdata, "BootNotification,0");
  6994. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6995. {
  6996. result = PASS;
  6997. }
  6998. return result;
  6999. }
  7000. int sendClearedChargingLimitRequest(int gun_index)
  7001. {
  7002. mtrace();
  7003. int result = FAIL;
  7004. char message[4096]={0};
  7005. char guid[37]={0};
  7006. char tempdata[128]={0};
  7007. json_object *ClearedChargingLimit = json_object_new_object();
  7008. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  7009. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  7010. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  7011. random_uuid(guid);
  7012. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  7013. json_object_put(ClearedChargingLimit);
  7014. LWS_Send(message);
  7015. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  7016. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7017. {
  7018. result = PASS;
  7019. }
  7020. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  7021. return result;
  7022. }
  7023. int sendDataTransferRequest(int gun_index)
  7024. {
  7025. mtrace();
  7026. char message[1000]={0};
  7027. char guid[37]={0};
  7028. char tempdata[65]={0};
  7029. int result = FAIL;
  7030. DEBUG_INFO("sendDataTransferRequest...\n");
  7031. random_uuid(guid);
  7032. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  7033. MESSAGE_TYPE_CALL,
  7034. guid,
  7035. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  7036. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  7037. ShmOCPP20Data->DataTransfer[gun_index].data);
  7038. LWS_Send(message);
  7039. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  7040. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7041. {
  7042. result = PASS;
  7043. }
  7044. return result;
  7045. }
  7046. int sendFirmwareStatusNotificationRequest(char *status)
  7047. {
  7048. mtrace();
  7049. int result = FAIL;
  7050. char message[110]={0};
  7051. char guid[37]={0};
  7052. char tempdata[65]={0};
  7053. json_object *FirmwareStatusNotification = json_object_new_object();
  7054. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  7055. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  7056. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  7057. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  7058. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  7059. random_uuid(guid);
  7060. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7061. json_object_put(FirmwareStatusNotification);
  7062. LWS_SendNow(message);
  7063. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7064. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7065. {
  7066. result = PASS;
  7067. }
  7068. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  7069. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  7070. //record status
  7071. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  7072. {
  7073. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  7074. }
  7075. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  7076. {
  7077. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  7078. }
  7079. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  7080. {
  7081. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  7082. }
  7083. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  7084. {
  7085. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  7086. }
  7087. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  7088. {
  7089. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  7090. }
  7091. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  7092. {
  7093. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  7094. }
  7095. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  7096. {
  7097. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  7098. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7099. }
  7100. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  7101. {
  7102. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  7103. }
  7104. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  7105. {
  7106. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  7107. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7108. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7109. }
  7110. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  7111. {
  7112. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  7113. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7114. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7115. }
  7116. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  7117. {
  7118. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  7119. }
  7120. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  7121. {
  7122. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  7123. }
  7124. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  7125. {
  7126. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  7127. }
  7128. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  7129. {
  7130. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  7131. }
  7132. return result;
  7133. }
  7134. int sendGet15118EVCertificateRequest()
  7135. {
  7136. mtrace();
  7137. int result = FAIL;
  7138. char message[4096]={0};
  7139. char guid[37]={0};
  7140. char tempdata[128]={0};
  7141. json_object *Get15118EVCertificate = json_object_new_object();
  7142. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  7143. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  7144. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  7145. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  7146. random_uuid(guid);
  7147. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  7148. json_object_put(Get15118EVCertificate);
  7149. LWS_Send(message);
  7150. sprintf(tempdata, "Get15118EVCertificate,0");
  7151. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7152. {
  7153. result = PASS;
  7154. }
  7155. return result;
  7156. }
  7157. int sendGetCertificateStatusRequest()
  7158. {
  7159. mtrace();
  7160. int result = FAIL;
  7161. char message[4096]={0};
  7162. char guid[37]={0};
  7163. char tempdata[128]={0};
  7164. json_object *GetCertificateStatus = json_object_new_object();
  7165. json_object *ocspRequestData = json_object_new_object();
  7166. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  7167. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  7168. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  7169. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  7170. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  7171. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  7172. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  7173. random_uuid(guid);
  7174. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  7175. json_object_put(GetCertificateStatus);
  7176. LWS_Send(message);
  7177. sprintf(tempdata, "GetCertificateStatus,0");
  7178. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7179. {
  7180. result = PASS;
  7181. }
  7182. return result;
  7183. }
  7184. int sendHeartbeatRequest()
  7185. {
  7186. mtrace();
  7187. int result = FAIL;
  7188. char message[40096]={0};
  7189. char guid[37]={0};
  7190. char tempdata[128]={0};
  7191. DEBUG_INFO("sendHeartbeatRequest...\n");
  7192. random_uuid(guid);
  7193. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  7194. , MESSAGE_TYPE_CALL
  7195. , guid );
  7196. LWS_Send(message);
  7197. sprintf(tempdata, "Heartbeat,%d", 0);
  7198. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7199. {
  7200. result = PASS;
  7201. }
  7202. return result;
  7203. }
  7204. int sendLogStatusNotificationRequest(char *status)
  7205. {
  7206. mtrace();
  7207. int result = FAIL;
  7208. char message[4096]={0};
  7209. char guid[37]={0};
  7210. char tempdata[128]={0};
  7211. json_object *LogStatusNotification = json_object_new_object();
  7212. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7213. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  7214. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  7215. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  7216. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  7217. random_uuid(guid);
  7218. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7219. json_object_put(LogStatusNotification);
  7220. LWS_SendNow(message);
  7221. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7222. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7223. {
  7224. result = PASS;
  7225. }
  7226. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7227. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  7228. //record status
  7229. if(strcmp(status,"BadMessage")==0)
  7230. {
  7231. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  7232. }
  7233. else if(strcmp(status,"Idle")==0)
  7234. {
  7235. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  7236. }
  7237. else if(strcmp(status,"NotSupportedOperation")==0)
  7238. {
  7239. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  7240. }
  7241. else if(strcmp(status,"PermissionDenied")==0)
  7242. {
  7243. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  7244. }
  7245. else if(strcmp(status,"Uploaded")==0)
  7246. {
  7247. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  7248. }
  7249. else if(strcmp(status,"UploadFailure")==0)
  7250. {
  7251. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  7252. }
  7253. else if(strcmp(status,"Uploading")==0)
  7254. {
  7255. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  7256. }
  7257. return result;
  7258. }
  7259. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  7260. {
  7261. mtrace();
  7262. int result = FAIL;
  7263. char guid[37]={0};
  7264. char tempdata[65]={0};
  7265. int tempIndex = 0;
  7266. json_object *MeterValueReq = json_object_new_object();
  7267. json_object *meterValues = json_object_new_array();
  7268. json_object *sampledValues = json_object_new_array();
  7269. DEBUG_INFO("sendMeterValuesRequest...\n");
  7270. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7271. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  7272. //set value
  7273. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  7274. //UTC Date time
  7275. struct timeval tmnow;
  7276. struct tm *tm;
  7277. char buf[28];//, usec_buf[6];
  7278. gettimeofday(&tmnow, NULL);
  7279. time_t t;
  7280. t = time(NULL);
  7281. /*UTC time and date*/
  7282. tm = gmtime(&t);
  7283. if(dataType == ReadingContextEnumType_Sample_Clock)
  7284. {
  7285. struct tm *tmTarget;
  7286. struct timeb tbTarget;
  7287. tbTarget.time = mktime(tm);
  7288. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  7289. tmTarget = gmtime(&tbTarget.time);
  7290. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7291. }
  7292. else
  7293. {
  7294. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7295. }
  7296. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  7297. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7298. //idx_sample=0;
  7299. //********************************(1)Current.Import L1************************************************/
  7300. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7301. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7302. (dataType == ReadingContextEnumType_Trigger))
  7303. {
  7304. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7305. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7306. {
  7307. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7308. {
  7309. tempIndex = ((gun_index==2) ? 1: 0);
  7310. }
  7311. else
  7312. {
  7313. tempIndex = gun_index;
  7314. }
  7315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7316. {
  7317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7318. {
  7319. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent*100))/100.0;
  7320. }
  7321. }
  7322. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7323. }
  7324. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7325. {
  7326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7327. {
  7328. tempIndex = ((gun_index==2) ? 1: 0);
  7329. }
  7330. else
  7331. {
  7332. tempIndex = gun_index;
  7333. }
  7334. for (int index = 0; index < CCS_QUANTITY; index++)
  7335. {
  7336. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7337. {
  7338. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent*100))/100.0;
  7339. }
  7340. }
  7341. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7342. }
  7343. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7344. {
  7345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7346. {
  7347. tempIndex = ((gun_index==2) ? 1: 0);
  7348. }
  7349. else
  7350. {
  7351. tempIndex = gun_index;
  7352. }
  7353. for (int index = 0; index < GB_QUANTITY; index++)
  7354. {
  7355. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7356. {
  7357. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent*100))/100.0;
  7358. }
  7359. }
  7360. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7361. }
  7362. else if(gunType[gun_index] == GUN_TYPE_DO)
  7363. {
  7364. tempIndex = gun_index;
  7365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7366. {
  7367. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7368. {
  7369. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent*100))/100.0;
  7370. }
  7371. }
  7372. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7373. }
  7374. else
  7375. {
  7376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7377. {
  7378. tempIndex = 2;
  7379. }
  7380. else
  7381. {
  7382. tempIndex = gun_index;
  7383. }
  7384. for (int index = 0; index < AC_QUANTITY; index++)
  7385. {
  7386. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7387. {
  7388. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent*100))/100.0;
  7389. }
  7390. }
  7391. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7392. }
  7393. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  7394. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7395. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7396. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  7397. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  7398. }
  7399. //idx_sample=1;
  7400. //********************************(2)Energy.Active.Import.Register ************************************************/
  7401. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7402. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7403. (dataType == ReadingContextEnumType_Trigger))
  7404. {
  7405. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7406. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7407. {
  7408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7409. {
  7410. tempIndex = ((gun_index==2) ? 1: 0);
  7411. }
  7412. else
  7413. {
  7414. tempIndex = gun_index;
  7415. }
  7416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7417. {
  7418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7419. {
  7420. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*100))/100.0;
  7421. }
  7422. }
  7423. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7424. }
  7425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7426. {
  7427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7428. {
  7429. tempIndex = ((gun_index==2) ? 1: 0);
  7430. }
  7431. else
  7432. {
  7433. tempIndex = gun_index;
  7434. }
  7435. for (int index = 0; index < CCS_QUANTITY; index++)
  7436. {
  7437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7438. {
  7439. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*100))/100.0;
  7440. }
  7441. }
  7442. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7443. }
  7444. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7445. {
  7446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7447. {
  7448. tempIndex = ((gun_index==2) ? 1: 0);
  7449. }
  7450. else
  7451. {
  7452. tempIndex = gun_index;
  7453. }
  7454. for (int index = 0; index < GB_QUANTITY; index++)
  7455. {
  7456. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7457. {
  7458. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*100))/100.0;
  7459. }
  7460. }
  7461. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7462. }
  7463. else if(gunType[gun_index] == GUN_TYPE_DO)
  7464. {
  7465. tempIndex = gun_index;
  7466. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7467. {
  7468. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7469. {
  7470. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*100))/100.0;
  7471. }
  7472. }
  7473. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7474. }
  7475. else
  7476. {
  7477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7478. {
  7479. tempIndex = 2;
  7480. }
  7481. else
  7482. {
  7483. tempIndex = gun_index;
  7484. }
  7485. for (int index = 0; index < AC_QUANTITY; index++)
  7486. {
  7487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7488. {
  7489. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*100))/100.0;
  7490. }
  7491. }
  7492. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7493. }
  7494. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  7495. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  7496. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7497. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  7498. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7499. }
  7500. //idx_sample=2;
  7501. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7502. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7503. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7504. (dataType == ReadingContextEnumType_Trigger))
  7505. {
  7506. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7507. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7508. {
  7509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7510. {
  7511. tempIndex = ((gun_index==2) ? 1: 0);
  7512. }
  7513. else
  7514. {
  7515. tempIndex = gun_index;
  7516. }
  7517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7518. {
  7519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7520. {
  7521. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*100))/100.0;
  7522. if(dataType == ReadingContextEnumType_Sample_Clock)
  7523. {
  7524. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7525. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7526. }
  7527. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7528. {
  7529. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7530. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7531. }
  7532. else
  7533. {
  7534. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7535. }
  7536. }
  7537. } // END OF FOR CHAdeMO_QUANTITY
  7538. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7539. }
  7540. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7541. {
  7542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7543. {
  7544. tempIndex = ((gun_index==2) ? 1: 0);
  7545. }
  7546. else
  7547. {
  7548. tempIndex = gun_index;
  7549. }
  7550. for (int index = 0; index < CCS_QUANTITY; index++)
  7551. {
  7552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7553. {
  7554. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*100))/100.0;
  7555. if(dataType == ReadingContextEnumType_Sample_Clock)
  7556. {
  7557. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7558. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7559. }
  7560. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7561. {
  7562. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7563. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7564. }
  7565. else
  7566. {
  7567. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7568. }
  7569. }
  7570. } // END OF CCS_QUANTITY
  7571. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7572. }
  7573. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7574. {
  7575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7576. {
  7577. tempIndex = ((gun_index==2) ? 1: 0);
  7578. }
  7579. else
  7580. {
  7581. tempIndex = gun_index;
  7582. }
  7583. for (int index = 0; index < GB_QUANTITY; index++)
  7584. {
  7585. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7586. {
  7587. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*100))/100.0;
  7588. if(dataType == ReadingContextEnumType_Sample_Clock)
  7589. {
  7590. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7591. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7592. }
  7593. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7594. {
  7595. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7596. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7597. }
  7598. else
  7599. {
  7600. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7601. }
  7602. }
  7603. } // END OF GB_QUANTITY
  7604. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7605. }
  7606. else if(gunType[gun_index] == GUN_TYPE_DO)
  7607. {
  7608. tempIndex = gun_index;
  7609. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7610. {
  7611. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7612. {
  7613. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*100))/100.0;
  7614. if(dataType == ReadingContextEnumType_Sample_Clock)
  7615. {
  7616. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]);
  7617. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7618. }
  7619. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7620. {
  7621. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7622. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7623. }
  7624. else
  7625. {
  7626. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7627. }
  7628. }
  7629. }
  7630. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7631. }
  7632. else
  7633. {
  7634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7635. {
  7636. tempIndex = 2;
  7637. }
  7638. else
  7639. {
  7640. tempIndex = gun_index;
  7641. }
  7642. for (int index = 0; index < AC_QUANTITY; index++)
  7643. {
  7644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7645. {
  7646. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*100))/100.0;
  7647. if(dataType == ReadingContextEnumType_Sample_Clock)
  7648. {
  7649. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7650. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7651. }
  7652. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7653. {
  7654. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7655. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7656. }
  7657. else
  7658. {
  7659. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7660. }
  7661. }
  7662. }
  7663. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7664. }
  7665. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  7666. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  7667. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7668. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  7669. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7670. }
  7671. //idx_sample=3;
  7672. //********************************(4)Power.Active.Import************************************************/
  7673. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7674. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7675. (dataType == ReadingContextEnumType_Trigger))
  7676. {
  7677. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7678. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7679. {
  7680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7681. {
  7682. tempIndex = ((gun_index==2) ? 1: 0);
  7683. }
  7684. else
  7685. {
  7686. tempIndex = gun_index;
  7687. }
  7688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7689. {
  7690. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7691. {
  7692. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower*100))/100.0;
  7693. }
  7694. } // END OF FOR
  7695. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7696. }
  7697. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7698. {
  7699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7700. {
  7701. tempIndex = ((gun_index==2) ? 1: 0);
  7702. }
  7703. else
  7704. {
  7705. tempIndex = gun_index;
  7706. }
  7707. for (int index = 0; index < CCS_QUANTITY; index++)
  7708. {
  7709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7710. {
  7711. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower*100))/100.0;
  7712. }
  7713. }
  7714. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7715. }
  7716. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7717. {
  7718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7719. {
  7720. tempIndex = ((gun_index==2) ? 1: 0);
  7721. }
  7722. else
  7723. {
  7724. tempIndex = gun_index;
  7725. }
  7726. for (int index = 0; index < GB_QUANTITY; index++)
  7727. {
  7728. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7729. {
  7730. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7731. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower*100))/100.0;
  7732. }
  7733. }
  7734. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7735. }
  7736. else if(gunType[gun_index] == GUN_TYPE_DO)
  7737. {
  7738. tempIndex = gun_index;
  7739. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7740. {
  7741. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7742. {
  7743. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7744. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower*100))/100.0;
  7745. }
  7746. }
  7747. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7748. }
  7749. else
  7750. {
  7751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7752. {
  7753. tempIndex = 2;
  7754. }
  7755. else
  7756. {
  7757. tempIndex = gun_index;
  7758. }
  7759. for (int index = 0; index < AC_QUANTITY; index++)
  7760. {
  7761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7762. {
  7763. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower*100))/100.0;
  7764. }
  7765. }
  7766. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7767. }
  7768. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  7769. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  7770. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7771. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  7772. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  7773. }
  7774. //idx_sample=4;
  7775. //***********************************************(5)VOLTAGE L1******************************************************/
  7776. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7777. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7778. (dataType == ReadingContextEnumType_Trigger))
  7779. {
  7780. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7781. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7782. {
  7783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7784. {
  7785. tempIndex = ((gun_index==2) ? 1: 0);
  7786. }
  7787. else
  7788. {
  7789. tempIndex = gun_index;
  7790. }
  7791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7792. {
  7793. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7794. {
  7795. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage*100))/100.0;
  7796. }
  7797. }
  7798. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7799. }
  7800. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7801. {
  7802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7803. {
  7804. tempIndex = ((gun_index==2) ? 1: 0);
  7805. }
  7806. else
  7807. {
  7808. tempIndex = gun_index;
  7809. }
  7810. for (int index = 0; index < CCS_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7813. {
  7814. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage*100))/100.0;
  7815. }
  7816. }
  7817. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7818. }
  7819. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7820. {
  7821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7822. {
  7823. tempIndex = ((gun_index==2) ? 1: 0);
  7824. }
  7825. else
  7826. {
  7827. tempIndex = gun_index;
  7828. }
  7829. for (int index = 0; index < GB_QUANTITY; index++)
  7830. {
  7831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7832. {
  7833. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage*100))/100.0;
  7834. }
  7835. }
  7836. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7837. }
  7838. else if(gunType[gun_index] == GUN_TYPE_DO)
  7839. {
  7840. tempIndex = gun_index;
  7841. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7842. {
  7843. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7844. {
  7845. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage*100))/100.0;
  7846. }
  7847. }
  7848. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7849. }
  7850. else
  7851. {
  7852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7853. {
  7854. tempIndex = 2;
  7855. }
  7856. else
  7857. {
  7858. tempIndex = gun_index;
  7859. }
  7860. for (int index = 0; index < AC_QUANTITY; index++)
  7861. {
  7862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7863. {
  7864. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage*100))/100.0;
  7865. }
  7866. }
  7867. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7868. }
  7869. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  7870. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7871. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7872. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  7873. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  7874. }
  7875. //***********************************************(6)SOC******************************************************/
  7876. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  7877. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  7878. (dataType == ReadingContextEnumType_Trigger))
  7879. {
  7880. 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))
  7881. {
  7882. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7883. {
  7884. tempIndex = ((gun_index==2) ? 1: 0);
  7885. }
  7886. else
  7887. {
  7888. tempIndex = gun_index;
  7889. }
  7890. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7891. {
  7892. //tempIndex = ((gun_index==2) ? 1: 0);
  7893. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7894. {
  7895. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7896. {
  7897. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  7898. }
  7899. }
  7900. }
  7901. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7902. {
  7903. //tempIndex = ((gun_index==2) ? 1: 0);
  7904. for (int index = 0; index < CCS_QUANTITY; index++)
  7905. {
  7906. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7907. {
  7908. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  7909. }
  7910. }
  7911. }
  7912. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7913. {
  7914. //tempIndex = ((gun_index==2) ? 1: 0);
  7915. for (int index = 0; index < GB_QUANTITY; index++)
  7916. {
  7917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7918. {
  7919. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  7920. }
  7921. }
  7922. }
  7923. else if(gunType[gun_index] == GUN_TYPE_DO)
  7924. {
  7925. //tempIndex = ((gun_index==2) ? 1: 0);
  7926. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7927. {
  7928. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7929. {
  7930. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  7931. }
  7932. }
  7933. }
  7934. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  7935. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  7936. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7937. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  7938. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  7939. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  7940. }
  7941. }
  7942. //********************************(7)Current.Import L2************************************************/
  7943. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7944. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7945. (dataType == ReadingContextEnumType_Trigger))
  7946. {
  7947. // Only for AC 3 phase
  7948. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7949. {
  7950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7951. {
  7952. tempIndex = 2;
  7953. }
  7954. else
  7955. {
  7956. tempIndex = gun_index;
  7957. }
  7958. for (int index = 0; index < AC_QUANTITY; index++)
  7959. {
  7960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7961. {
  7962. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2*100))/100.0;
  7963. }
  7964. }
  7965. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  7966. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  7967. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7968. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7969. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  7970. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  7971. }
  7972. }
  7973. //********************************(8)Current.Import L3************************************************/
  7974. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7975. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7976. (dataType == ReadingContextEnumType_Trigger))
  7977. {
  7978. // Only for AC 3 phase
  7979. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7980. {
  7981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7982. {
  7983. tempIndex = 2;
  7984. }
  7985. else
  7986. {
  7987. tempIndex = gun_index;
  7988. }
  7989. for (int index = 0; index < AC_QUANTITY; index++)
  7990. {
  7991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7992. {
  7993. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3*100))/100.0;
  7994. }
  7995. }
  7996. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7997. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  7998. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7999. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8000. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8001. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8002. }
  8003. }
  8004. //***********************************************(9)VOLTAGE L2******************************************************/
  8005. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8006. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8007. (dataType == ReadingContextEnumType_Trigger))
  8008. {
  8009. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8010. {
  8011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8012. {
  8013. tempIndex = 2;
  8014. }
  8015. else
  8016. {
  8017. tempIndex = gun_index;
  8018. }
  8019. for (int index = 0; index < AC_QUANTITY; index++)
  8020. {
  8021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8022. {
  8023. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2*100))/100.0;
  8024. }
  8025. }
  8026. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8027. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8028. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8029. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8030. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8031. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8032. }
  8033. }
  8034. //***********************************************(10)VOLTAGE L3******************************************************/
  8035. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8036. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8037. (dataType == ReadingContextEnumType_Trigger))
  8038. {
  8039. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8040. {
  8041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8042. {
  8043. tempIndex = 2;
  8044. }
  8045. else
  8046. {
  8047. tempIndex = gun_index;
  8048. }
  8049. for (int index = 0; index < AC_QUANTITY; index++)
  8050. {
  8051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8052. {
  8053. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3*100))/100.0;
  8054. }
  8055. }
  8056. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8057. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8058. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8059. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8060. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8061. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8062. }
  8063. }
  8064. //***********************************************(11)Current.Offered******************************************************/
  8065. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8066. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8067. (dataType == ReadingContextEnumType_Trigger))
  8068. {
  8069. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8070. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8071. {
  8072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8073. {
  8074. tempIndex = ((gun_index==2) ? 1: 0);
  8075. }
  8076. else
  8077. {
  8078. tempIndex = gun_index;
  8079. }
  8080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8081. {
  8082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8083. {
  8084. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10);
  8085. }
  8086. } // END OF FOR
  8087. }
  8088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8089. {
  8090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8091. {
  8092. tempIndex = ((gun_index==2) ? 1: 0);
  8093. }
  8094. else
  8095. {
  8096. tempIndex = gun_index;
  8097. }
  8098. for (int index = 0; index < CCS_QUANTITY; index++)
  8099. {
  8100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8101. {
  8102. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10);
  8103. }
  8104. }
  8105. }
  8106. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8107. {
  8108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8109. {
  8110. tempIndex = ((gun_index==2) ? 1: 0);
  8111. }
  8112. else
  8113. {
  8114. tempIndex = gun_index;
  8115. }
  8116. for (int index = 0; index < GB_QUANTITY; index++)
  8117. {
  8118. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8119. {
  8120. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8121. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10);;
  8122. }
  8123. }
  8124. }
  8125. else if(gunType[gun_index] == GUN_TYPE_DO)
  8126. {
  8127. tempIndex = gun_index;
  8128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8129. {
  8130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8131. {
  8132. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8133. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10);;
  8134. }
  8135. }
  8136. }
  8137. else
  8138. {
  8139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8140. {
  8141. tempIndex = 2;
  8142. }
  8143. else
  8144. {
  8145. tempIndex = gun_index;
  8146. }
  8147. for (int index = 0; index < AC_QUANTITY; index++)
  8148. {
  8149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8150. {
  8151. uint16_t currentOffer;
  8152. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8153. {
  8154. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8155. }
  8156. else
  8157. {
  8158. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8159. }
  8160. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8161. }
  8162. }
  8163. }
  8164. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8165. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8166. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8167. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8168. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8169. }
  8170. //***********************************************(12)Power.Offered******************************************************/
  8171. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8172. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8173. (dataType == ReadingContextEnumType_Trigger))
  8174. {
  8175. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8176. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8177. {
  8178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8179. {
  8180. tempIndex = ((gun_index==2) ? 1: 0);
  8181. }
  8182. else
  8183. {
  8184. tempIndex = gun_index;
  8185. }
  8186. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8187. {
  8188. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8189. {
  8190. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100);
  8191. }
  8192. } // END OF FOR
  8193. }
  8194. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8195. {
  8196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8197. {
  8198. tempIndex = ((gun_index==2) ? 1: 0);
  8199. }
  8200. else
  8201. {
  8202. tempIndex = gun_index;
  8203. }
  8204. for (int index = 0; index < CCS_QUANTITY; index++)
  8205. {
  8206. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8207. {
  8208. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100);
  8209. }
  8210. }
  8211. }
  8212. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8213. {
  8214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8215. {
  8216. tempIndex = ((gun_index==2) ? 1: 0);
  8217. }
  8218. else
  8219. {
  8220. tempIndex = gun_index;
  8221. }
  8222. for (int index = 0; index < GB_QUANTITY; index++)
  8223. {
  8224. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8225. {
  8226. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8227. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100);
  8228. }
  8229. }
  8230. }
  8231. else if(gunType[gun_index] == GUN_TYPE_DO)
  8232. {
  8233. tempIndex = gun_index;
  8234. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8235. {
  8236. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8237. {
  8238. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8239. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100);
  8240. }
  8241. }
  8242. }
  8243. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8244. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8245. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8246. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8247. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8248. }
  8249. // Message create ====================================================================================================
  8250. random_uuid(guid);
  8251. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8252. {
  8253. json_object *meterValue = json_object_new_object();
  8254. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8255. {
  8256. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8257. {
  8258. json_object *sampledValue = json_object_new_object();
  8259. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8260. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8261. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8262. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8263. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8264. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8265. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8266. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8267. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8268. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8269. {
  8270. json_object *unitOfMeasure = json_object_new_object();
  8271. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8272. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8273. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8274. }
  8275. json_object_array_add(sampledValues, sampledValue);
  8276. }
  8277. }
  8278. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8279. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8280. json_object_array_add(meterValues, meterValue);
  8281. idxMeter++;
  8282. }
  8283. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8284. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8285. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8286. ,MESSAGE_TYPE_CALL
  8287. ,guid
  8288. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8289. json_object_put(MeterValueReq);
  8290. if((dataType != ReadingContextEnumType_Trigger) &&
  8291. (dataType != ReadingContextEnumType_Sample_Clock))
  8292. {
  8293. // Transaction meter value send by TransactionEvent message
  8294. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8295. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8296. result = PASS;
  8297. }
  8298. else
  8299. {
  8300. // Put request guid to hash map
  8301. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8302. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8303. {
  8304. result = PASS;
  8305. }
  8306. if((dataType != ReadingContextEnumType_Trigger) &&
  8307. (dataType != ReadingContextEnumType_Sample_Clock))
  8308. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8309. else
  8310. {
  8311. if(FirstHeartBeat)
  8312. LWS_Send(queuedata);
  8313. }
  8314. }
  8315. return result;
  8316. }
  8317. int sendNotifyChargingLimitRequest(int gun_index)
  8318. {
  8319. mtrace();
  8320. int result = FAIL;
  8321. char message[4096]={0};
  8322. char guid[37]={0};
  8323. char tempdata[128]={0};
  8324. json_object *NotifyChargingLimit = json_object_new_object();
  8325. json_object *chargingLimit = json_object_new_object();
  8326. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8327. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8328. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8329. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8330. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8331. random_uuid(guid);
  8332. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8333. json_object_put(NotifyChargingLimit);
  8334. LWS_Send(message);
  8335. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8336. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8337. {
  8338. result = PASS;
  8339. }
  8340. return result;
  8341. }
  8342. int sendNotifyCustomerInformationRequest()
  8343. {
  8344. mtrace();
  8345. int result = FAIL;
  8346. char message[4096]={0};
  8347. char guid[37]={0};
  8348. char tempdata[128]={0};
  8349. json_object *NotifyCustomerInformation = json_object_new_object();
  8350. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8351. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8352. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8353. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8354. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8355. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8356. random_uuid(guid);
  8357. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8358. json_object_put(NotifyCustomerInformation);
  8359. LWS_Send(message);
  8360. sprintf(tempdata, "NotifyCustomerInformation,0");
  8361. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8362. {
  8363. result = PASS;
  8364. }
  8365. return result;
  8366. }
  8367. int sendNotifyDisplayMessagesRequest()
  8368. {
  8369. mtrace();
  8370. int result = FAIL;
  8371. char message[4096]={0};
  8372. char guid[37]={0};
  8373. char tempdata[128]={0};
  8374. json_object *NotifyDisplayMessages = json_object_new_object();
  8375. json_object *messageInfos = json_object_new_array();
  8376. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8377. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8378. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8379. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8380. {
  8381. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8382. {
  8383. json_object *messageInfo = json_object_new_object();
  8384. json_object *message = json_object_new_object();
  8385. json_object *display = json_object_new_object();
  8386. json_object *evse = json_object_new_object();
  8387. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8388. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8389. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8390. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8391. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8392. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8393. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8394. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8395. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8396. json_object_object_add(messageInfo, "message", message);
  8397. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8398. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8399. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8400. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8401. json_object_object_add(display, "evse",evse);
  8402. json_object_object_add(messageInfo, "evse", display);
  8403. json_object_array_add(messageInfos, messageInfo);
  8404. }
  8405. }
  8406. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8407. random_uuid(guid);
  8408. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8409. json_object_put(NotifyDisplayMessages);
  8410. LWS_Send(message);
  8411. sprintf(tempdata, "NotifyDisplayMessages,0");
  8412. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8413. {
  8414. result = PASS;
  8415. }
  8416. return result;
  8417. }
  8418. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8419. {
  8420. mtrace();
  8421. int result = FAIL;
  8422. char message[4096]={0};
  8423. char guid[37]={0};
  8424. char tempdata[128]={0};
  8425. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8426. json_object *chargingNeeds = json_object_new_object();
  8427. json_object *acChargingParameters = json_object_new_object();
  8428. json_object *dcChargingParameters = json_object_new_object();
  8429. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8430. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8431. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8432. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8433. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8434. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8435. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8436. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8437. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8438. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8439. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8440. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8441. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8442. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8443. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8444. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8445. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8446. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8447. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8448. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8449. random_uuid(guid);
  8450. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8451. json_object_put(NotifyEVChargingNeeds);
  8452. LWS_Send(message);
  8453. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8454. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8455. {
  8456. result = PASS;
  8457. }
  8458. return result;
  8459. }
  8460. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8461. {
  8462. mtrace();
  8463. int result = FAIL;
  8464. char message[4096]={0};
  8465. char guid[37]={0};
  8466. char tempdata[128]={0};
  8467. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8468. json_object *chargingSchedule = json_object_new_object();
  8469. json_object *periods = json_object_new_array();
  8470. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8471. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8472. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8473. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8474. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8475. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8476. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8477. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8479. {
  8480. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8481. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8482. {
  8483. json_object *Period = json_object_new_object();
  8484. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8485. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8486. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8487. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8488. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8489. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8490. json_object_array_add(periods, Period);
  8491. }
  8492. }
  8493. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8494. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8495. random_uuid(guid);
  8496. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8497. json_object_put(NotifyEVChargingSchedule);
  8498. LWS_Send(message);
  8499. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8500. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8501. {
  8502. result = PASS;
  8503. }
  8504. return result;
  8505. }
  8506. int sendNotifyEventRequest()
  8507. {
  8508. mtrace();
  8509. int result = FAIL;
  8510. char message[4096]={0};
  8511. char guid[37]={0};
  8512. char tempdata[128]={0};
  8513. json_object *NotifyEvent = json_object_new_object();
  8514. json_object *eventDatas = json_object_new_array();
  8515. DEBUG_INFO("sendNotifyEventRequest...\n");
  8516. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8517. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8518. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8519. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8520. {
  8521. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8522. {
  8523. json_object *eventData = json_object_new_object();
  8524. json_object *component = json_object_new_object();
  8525. json_object *evse = json_object_new_object();
  8526. json_object *variable = json_object_new_object();
  8527. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8528. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8529. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8530. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8531. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8532. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8533. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8534. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8535. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8536. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8537. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8538. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8539. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8540. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8541. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8542. json_object_object_add(component, "evse",evse);
  8543. json_object_object_add(eventData, "component", component);
  8544. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8545. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8546. json_object_object_add(eventData, "variable", variable);
  8547. json_object_array_add(eventDatas, eventData);
  8548. }
  8549. }
  8550. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8551. random_uuid(guid);
  8552. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8553. json_object_put(NotifyEvent);
  8554. LWS_Send(message);
  8555. sprintf(tempdata, "NotifyEvent,0");
  8556. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8557. {
  8558. result = PASS;
  8559. }
  8560. return result;
  8561. }
  8562. int sendNotifyMonitoringReportRequest()
  8563. {
  8564. mtrace();
  8565. int result = FAIL;
  8566. char message[4096]={0};
  8567. char guid[37]={0};
  8568. char tempdata[128]={0};
  8569. json_object *NotifyMonitoringReport = json_object_new_object();
  8570. json_object *monitors = json_object_new_array();
  8571. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8572. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8573. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8574. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8575. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8576. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8577. {
  8578. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8579. {
  8580. json_object *monitor = json_object_new_object();
  8581. json_object *component = json_object_new_object();
  8582. json_object *evse = json_object_new_object();
  8583. json_object *variable = json_object_new_object();
  8584. json_object *variableMonitorings = json_object_new_array();
  8585. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8586. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8587. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8588. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8589. json_object_object_add(component, "evse",evse);
  8590. json_object_object_add(monitor, "component", component);
  8591. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8592. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8593. json_object_object_add(monitor, "variable", variable);
  8594. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8595. {
  8596. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8597. {
  8598. json_object *variableMonitoring = json_object_new_object();
  8599. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8600. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8601. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8602. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8603. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8604. json_object_array_add(variableMonitorings, variableMonitoring);
  8605. }
  8606. }
  8607. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8608. json_object_array_add(monitors, monitor);
  8609. }
  8610. }
  8611. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8612. random_uuid(guid);
  8613. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8614. json_object_put(NotifyMonitoringReport);
  8615. LWS_Send(message);
  8616. sprintf(tempdata, "NotifyMonitoringReport,0");
  8617. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8618. {
  8619. result = PASS;
  8620. }
  8621. return result;
  8622. }
  8623. int sendNotifyReportRequest()
  8624. {
  8625. mtrace();
  8626. int result = FAIL;
  8627. char message[4096]={0};
  8628. char guid[37]={0};
  8629. char tempdata[128]={0};
  8630. json_object *NotifyReport = json_object_new_object();
  8631. json_object *reportDatas = json_object_new_array();
  8632. DEBUG_INFO("sendNotifyReportRequest...\n");
  8633. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8634. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8635. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8636. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8637. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8638. {
  8639. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8640. {
  8641. json_object *reportData = json_object_new_object();
  8642. json_object *component = json_object_new_object();
  8643. json_object *evse = json_object_new_object();
  8644. json_object *variable = json_object_new_object();
  8645. json_object *variableAttributes = json_object_new_array();
  8646. json_object *variableCharacteristics = json_object_new_object();
  8647. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8648. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8649. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8650. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8651. json_object_object_add(component, "evse",evse);
  8652. json_object_object_add(reportData, "component", component);
  8653. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8654. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8655. json_object_object_add(reportData, "variable",variable);
  8656. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  8657. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  8658. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  8659. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  8660. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  8661. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  8662. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  8663. {
  8664. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  8665. {
  8666. json_object *variableAttribute = json_object_new_object();
  8667. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  8668. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  8669. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  8670. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  8671. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  8672. json_object_array_add(variableAttributes, variableAttribute);
  8673. }
  8674. }
  8675. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  8676. json_object_array_add(reportDatas, reportData);
  8677. }
  8678. }
  8679. json_object_object_add(NotifyReport, "reportData", reportDatas);
  8680. random_uuid(guid);
  8681. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  8682. json_object_put(NotifyReport);
  8683. LWS_SendNow(message);
  8684. sprintf(tempdata, "NotifyReport,0");
  8685. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8686. {
  8687. result = PASS;
  8688. }
  8689. return result;
  8690. }
  8691. int sendPublishFirmwareStatusNotificationRequest()
  8692. {
  8693. mtrace();
  8694. int result = FAIL;
  8695. char message[4096]={0};
  8696. char guid[37]={0};
  8697. char tempdata[128]={0};
  8698. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  8699. json_object *locations = json_object_new_array();
  8700. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  8701. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  8702. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  8703. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  8704. {
  8705. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  8706. }
  8707. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  8708. random_uuid(guid);
  8709. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8710. json_object_put(PublishFirmwareStatusNotification);
  8711. LWS_Send(message);
  8712. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  8713. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8714. {
  8715. result = PASS;
  8716. }
  8717. return result;
  8718. }
  8719. int sendReportChargingProfilesRequest(int gun_index)
  8720. {
  8721. mtrace();
  8722. int result = FAIL;
  8723. char message[4096]={0};
  8724. char guid[37]={0};
  8725. char tempdata[128]={0};
  8726. json_object *ReportChargingProfiles = json_object_new_object();
  8727. json_object *chargingProfiles = json_object_new_array();
  8728. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  8729. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  8730. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  8731. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  8732. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  8733. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  8734. {
  8735. json_object *chargingProfile = json_object_new_object();
  8736. json_object *chargingSchedules = json_object_new_array();
  8737. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  8738. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  8739. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  8740. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  8741. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  8742. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  8743. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  8744. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  8745. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  8746. {
  8747. json_object *chargingSchedule = json_object_new_object();
  8748. json_object *chargingSchedulePeriods = json_object_new_array();
  8749. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  8750. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  8751. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  8752. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  8753. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  8754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  8755. {
  8756. json_object *chargingSchedulePeriod = json_object_new_object();
  8757. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  8758. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  8759. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  8760. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  8761. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  8762. }
  8763. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  8764. json_object_array_add(chargingSchedules, chargingSchedule);
  8765. }
  8766. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  8767. json_object_array_add(chargingProfiles, chargingProfile);
  8768. }
  8769. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  8770. random_uuid(guid);
  8771. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8772. json_object_put(ReportChargingProfiles);
  8773. LWS_Send(message);
  8774. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  8775. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8776. {
  8777. result = PASS;
  8778. }
  8779. return result;
  8780. }
  8781. int sendReservationStatusUpdateRequest(int gun_index)
  8782. {
  8783. mtrace();
  8784. int result = FAIL;
  8785. char message[4096]={0};
  8786. char guid[37]={0};
  8787. char tempdata[128]={0};
  8788. json_object *ReservationStatusUpdate = json_object_new_object();
  8789. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  8790. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  8791. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  8792. random_uuid(guid);
  8793. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  8794. json_object_put(ReservationStatusUpdate);
  8795. LWS_Send(message);
  8796. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  8797. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8798. {
  8799. result = PASS;
  8800. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  8801. }
  8802. return result;
  8803. }
  8804. int sendSecurityEventNotificationRequest()
  8805. {
  8806. mtrace();
  8807. int result = FAIL;
  8808. char message[4096]={0};
  8809. char guid[37]={0};
  8810. char tempdata[128]={0};
  8811. struct timeval tmnow;
  8812. struct tm *tm;
  8813. char buf[28];//, usec_buf[6];
  8814. json_object *SecurityEventNotification = json_object_new_object();
  8815. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8816. DB_getSecurityEventType();
  8817. gettimeofday(&tmnow, NULL);
  8818. time_t t;
  8819. t = time(NULL);
  8820. /*UTC time and date*/
  8821. tm = gmtime(&t);
  8822. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8823. #if 0 // remove temporally
  8824. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  8825. strcat(buf,".");
  8826. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  8827. strcat(buf,usec_buf);
  8828. #endif
  8829. printf("%s",buf);
  8830. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  8831. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  8832. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  8833. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  8834. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  8835. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  8836. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  8837. random_uuid(guid);
  8838. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8839. json_object_put(SecurityEventNotification);
  8840. LWS_Send(message);
  8841. sprintf(tempdata, "SecurityEventNotification,0");
  8842. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8843. {
  8844. result = PASS;
  8845. }
  8846. return result;
  8847. }
  8848. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  8849. {
  8850. mtrace();
  8851. int result = FAIL;
  8852. char message[4096]={0};
  8853. char guid[37]={0};
  8854. char tempdata[128]={0};
  8855. json_object *SignCertificate = json_object_new_object();
  8856. DEBUG_INFO("sendSignCertificateRequest...\n");
  8857. // Read csr file content
  8858. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  8859. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  8860. char *line = NULL;
  8861. size_t len = 0;
  8862. while(getline(&line, &len, fp) != -1)
  8863. {
  8864. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8865. {
  8866. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  8867. }
  8868. }
  8869. fclose(fp);
  8870. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  8871. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  8872. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  8873. random_uuid(guid);
  8874. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8875. json_object_put(SignCertificate);
  8876. LWS_Send(message);
  8877. sprintf(tempdata, "SignCertificate,0");
  8878. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8879. {
  8880. result = PASS;
  8881. }
  8882. return result;
  8883. }
  8884. int sendStatusNotificationRequest(int gun_index)
  8885. {
  8886. mtrace();
  8887. int result = FAIL;
  8888. char message[600]={0};
  8889. char guid[37];
  8890. int currentStatus = 0;
  8891. struct timeval tmnow;
  8892. struct tm *tm;
  8893. char buf[28];//, usec_buf[6];
  8894. char tempdata[65]={0};
  8895. int tempIndex = 0;
  8896. uint8_t isStateChanged = TRUE;
  8897. DEBUG_INFO("sendStatusNotificationRequest...\n");
  8898. gettimeofday(&tmnow, NULL);
  8899. time_t t;
  8900. t = time(NULL);
  8901. /*UTC time and date*/
  8902. tm = gmtime(&t);
  8903. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8904. #if 0 // remove temporally
  8905. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  8906. strcat(buf,".");
  8907. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  8908. strcat(buf,usec_buf);
  8909. #endif
  8910. printf("%s",buf);
  8911. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  8912. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  8913. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  8914. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  8915. /*
  8916. enum _SYSTEM_STATUS
  8917. {
  8918. S_BOOTING = 0,
  8919. S_IDLE, = 1
  8920. S_AUTHORIZING, =2
  8921. S_REASSIGN_CHECK, =3
  8922. S_REASSIGN, =4
  8923. S_PRECHARGE, =5
  8924. S_PREPARING_FOR_EV, =6
  8925. S_PREPARING_FOR_EVSE, =7
  8926. S_CHARGING, =8
  8927. S_TERMINATING, =9
  8928. S_COMPLETE, =10
  8929. S_ALARM, =11
  8930. S_FAULT =12
  8931. }
  8932. */
  8933. //check Transaction active
  8934. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  8935. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8936. {
  8937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8938. {
  8939. tempIndex = ((gun_index==2) ? 1: 0);
  8940. }
  8941. else
  8942. {
  8943. tempIndex = gun_index;
  8944. }
  8945. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8946. {
  8947. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  8948. {
  8949. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  8950. {
  8951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8952. {
  8953. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8954. }
  8955. else
  8956. {
  8957. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8958. }
  8959. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8960. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8961. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8962. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8963. }
  8964. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8965. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8966. ) //S_PRECHARGE
  8967. {
  8968. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8969. }
  8970. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8971. {
  8972. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8973. }
  8974. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8975. {
  8976. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8977. }
  8978. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8979. {
  8980. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8981. }
  8982. 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
  8983. {
  8984. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8985. }
  8986. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8987. {
  8988. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8989. }
  8990. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8991. {
  8992. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8993. }
  8994. } //end of the same index
  8995. }//end of for CHAdeMO_QUANTITY
  8996. }
  8997. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8998. {
  8999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9000. {
  9001. tempIndex = ((gun_index==2) ? 1: 0);
  9002. }
  9003. else
  9004. {
  9005. tempIndex = gun_index;
  9006. }
  9007. for (int index = 0; index < CCS_QUANTITY; index++)
  9008. {
  9009. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9010. {
  9011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9012. {
  9013. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9014. {
  9015. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9016. }
  9017. else
  9018. {
  9019. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9020. }
  9021. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9022. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9023. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9024. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9025. }
  9026. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9027. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9028. ) //S_PRECHARGE
  9029. {
  9030. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9031. }
  9032. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9033. {
  9034. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9035. }
  9036. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9037. {
  9038. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9039. }
  9040. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9041. {
  9042. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9043. }
  9044. 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
  9045. {
  9046. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9047. }
  9048. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9049. {
  9050. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9051. }
  9052. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9053. {
  9054. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9055. }
  9056. } //end of the same index
  9057. } // end of for CCS_QUANTITY
  9058. }
  9059. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9060. {
  9061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9062. {
  9063. tempIndex = ((gun_index==2) ? 1: 0);
  9064. }
  9065. else
  9066. {
  9067. tempIndex = gun_index;
  9068. }
  9069. for (int index = 0; index < GB_QUANTITY; index++)
  9070. {
  9071. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9072. {
  9073. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9074. {
  9075. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9076. {
  9077. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9078. }
  9079. else
  9080. {
  9081. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9082. }
  9083. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9084. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9085. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9086. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9087. }
  9088. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9089. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9090. ) //S_PRECHARGE
  9091. {
  9092. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9093. }
  9094. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9095. {
  9096. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9097. }
  9098. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9099. {
  9100. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9101. }
  9102. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9103. {
  9104. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9105. }
  9106. 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
  9107. {
  9108. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9109. }
  9110. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9111. {
  9112. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9113. }
  9114. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9115. {
  9116. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9117. }
  9118. } //end of the same index
  9119. } // end of for GB_QUANTITY
  9120. }
  9121. else if(gunType[gun_index] == GUN_TYPE_DO)
  9122. {
  9123. tempIndex = gun_index;
  9124. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9125. {
  9126. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9127. {
  9128. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9129. {
  9130. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9131. {
  9132. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9133. }
  9134. else
  9135. {
  9136. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9137. }
  9138. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9139. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9140. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9141. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9142. }
  9143. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9144. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9145. ) //S_PRECHARGE
  9146. {
  9147. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9148. }
  9149. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9150. {
  9151. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9152. }
  9153. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9154. {
  9155. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9156. }
  9157. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9158. {
  9159. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9160. }
  9161. 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
  9162. {
  9163. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9164. }
  9165. 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
  9166. {
  9167. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9168. }
  9169. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9170. {
  9171. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9172. }
  9173. } //end of the same index
  9174. }
  9175. }
  9176. else
  9177. {
  9178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9179. {
  9180. tempIndex = 2;
  9181. }
  9182. else
  9183. {
  9184. tempIndex = gun_index;
  9185. }
  9186. for (int index = 0; index < AC_QUANTITY; index++)
  9187. {
  9188. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9189. {
  9190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9191. {
  9192. 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))
  9193. {
  9194. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9195. }
  9196. else
  9197. {
  9198. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9199. }
  9200. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9201. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9202. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9203. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9204. }
  9205. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9206. {
  9207. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9208. }
  9209. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9210. {
  9211. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9212. }
  9213. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9214. {
  9215. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9216. }
  9217. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9218. {
  9219. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9220. }
  9221. 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
  9222. {
  9223. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9224. }
  9225. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9226. {
  9227. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9228. }
  9229. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9230. {
  9231. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9232. }
  9233. }//end of the same index
  9234. }//end of for AC_QUANTITY
  9235. }
  9236. //it's option
  9237. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9238. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9239. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "TRUE") != 0))
  9240. {
  9241. isStateChanged = FALSE;
  9242. }
  9243. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9244. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9245. random_uuid(guid);
  9246. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9247. , MESSAGE_TYPE_CALL
  9248. , guid
  9249. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9250. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9251. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9252. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9253. if((server_sign == TRUE) && isStateChanged)
  9254. {
  9255. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9256. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9257. LWS_Send(message);
  9258. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9259. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9260. {
  9261. result = PASS;
  9262. }
  9263. }
  9264. else
  9265. {
  9266. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9267. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9268. result = PASS;
  9269. }
  9270. return result;
  9271. }
  9272. int sendTransactionEventRequest(int gun_index)
  9273. {
  9274. mtrace();
  9275. int result = FAIL;
  9276. char message[1024*20]={0};
  9277. char guid[37]={0};
  9278. char tempdata[128]={0};
  9279. uint8_t tempIndex;
  9280. json_object *TransactionEvent = json_object_new_object();
  9281. json_object *transactionInfo = json_object_new_object();
  9282. json_object *idToken = json_object_new_object();
  9283. json_object *evse = json_object_new_object();
  9284. json_object *meterValues = json_object_new_array();
  9285. char TempStopTransaction[256];
  9286. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9287. DEBUG_INFO("sendTransactionEventRequest...\n");
  9288. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9289. {
  9290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9291. {
  9292. tempIndex = ((gun_index==2) ? 1: 0);
  9293. }
  9294. else
  9295. {
  9296. tempIndex = gun_index;
  9297. }
  9298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9299. {
  9300. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9301. {
  9302. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9303. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9304. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9305. else
  9306. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9307. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9308. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9309. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9310. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9311. {
  9312. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9313. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9314. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9315. {
  9316. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9317. }
  9318. else
  9319. {
  9320. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9321. }
  9322. }
  9323. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9324. {
  9325. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9326. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9327. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9328. }
  9329. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9330. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9331. ) //S_PRECHARGE
  9332. {
  9333. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9334. {
  9335. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9336. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9337. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9338. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9339. }
  9340. else
  9341. {
  9342. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9343. }
  9344. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9345. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9346. }
  9347. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9348. {
  9349. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9350. {
  9351. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9352. {
  9353. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9354. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9355. }
  9356. else
  9357. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9358. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9359. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9360. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9361. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9362. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9363. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9364. }
  9365. else
  9366. {
  9367. storeTempStopTransaction(gun_index);
  9368. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9369. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9370. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9371. }
  9372. }
  9373. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9374. {
  9375. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9376. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9377. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9378. if((access(TempStopTransaction,F_OK))!=-1)
  9379. {
  9380. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9381. }
  9382. }
  9383. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9384. {
  9385. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9386. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9387. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9388. }
  9389. 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
  9390. {
  9391. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9392. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9393. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9394. }
  9395. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9396. {
  9397. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9398. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9399. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9400. }
  9401. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9402. {
  9403. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9404. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9405. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9406. }
  9407. } //end of the same index
  9408. }//end of for CHAdeMO_QUANTITY
  9409. }
  9410. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9411. {
  9412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9413. {
  9414. tempIndex = ((gun_index==2) ? 1: 0);
  9415. }
  9416. else
  9417. {
  9418. tempIndex = gun_index;
  9419. }
  9420. for (int index = 0; index < CCS_QUANTITY; index++)
  9421. {
  9422. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9423. {
  9424. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9425. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9426. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9427. else
  9428. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9429. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9430. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9431. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9433. {
  9434. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9435. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9436. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9437. {
  9438. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9439. }
  9440. else
  9441. {
  9442. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9443. }
  9444. }
  9445. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9446. {
  9447. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9448. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9449. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9450. }
  9451. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9452. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9453. ) //S_PRECHARGE
  9454. {
  9455. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9456. {
  9457. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9458. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9459. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9460. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9461. }
  9462. else
  9463. {
  9464. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9465. }
  9466. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9467. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9468. }
  9469. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9470. {
  9471. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9472. {
  9473. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9474. {
  9475. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9476. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9477. }
  9478. else
  9479. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9480. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9481. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9482. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9483. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9484. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9485. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9486. }
  9487. else
  9488. {
  9489. storeTempStopTransaction(gun_index);
  9490. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9491. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9492. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9493. }
  9494. }
  9495. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9496. {
  9497. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9498. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9499. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9500. if((access(TempStopTransaction,F_OK))!=-1)
  9501. {
  9502. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9503. }
  9504. }
  9505. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9506. {
  9507. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9508. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9509. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9510. }
  9511. 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
  9512. {
  9513. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9514. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9515. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9516. }
  9517. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9518. {
  9519. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9520. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9521. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9522. }
  9523. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9524. {
  9525. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9526. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9527. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9528. }
  9529. } //end of the same index
  9530. } // end of for CCS_QUANTITY
  9531. }
  9532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9533. {
  9534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9535. {
  9536. tempIndex = ((gun_index==2) ? 1: 0);
  9537. }
  9538. else
  9539. {
  9540. tempIndex = gun_index;
  9541. }
  9542. for (int index = 0; index < GB_QUANTITY; index++)
  9543. {
  9544. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9545. {
  9546. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9547. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9548. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9549. else
  9550. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9551. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9552. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9553. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9555. {
  9556. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9557. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9559. {
  9560. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9561. }
  9562. else
  9563. {
  9564. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9565. }
  9566. }
  9567. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9568. {
  9569. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9570. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9571. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9572. }
  9573. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9574. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9575. ) //S_PRECHARGE
  9576. {
  9577. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9578. {
  9579. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9580. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9581. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9582. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9583. }
  9584. else
  9585. {
  9586. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9587. }
  9588. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9589. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9590. }
  9591. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9592. {
  9593. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9594. {
  9595. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  9596. {
  9597. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9598. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9599. }
  9600. else
  9601. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9602. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9603. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9604. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9605. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9606. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9607. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  9608. }
  9609. else
  9610. {
  9611. storeTempStopTransaction(gun_index);
  9612. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9613. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9614. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9615. }
  9616. }
  9617. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9618. {
  9619. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9620. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9621. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9622. if((access(TempStopTransaction,F_OK))!=-1)
  9623. {
  9624. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9625. }
  9626. }
  9627. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9628. {
  9629. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9630. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9631. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9632. }
  9633. 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
  9634. {
  9635. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9636. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9637. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9638. }
  9639. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9640. {
  9641. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9642. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9643. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9644. }
  9645. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9646. {
  9647. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9648. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9649. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9650. }
  9651. } //end of the same index
  9652. } // end of for GB_QUANTITY
  9653. }
  9654. else if(gunType[gun_index] == GUN_TYPE_DO)
  9655. {
  9656. tempIndex = gun_index;
  9657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9658. {
  9659. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9660. {
  9661. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9662. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9663. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9664. else
  9665. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9666. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9667. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9668. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9670. {
  9671. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9672. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9673. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9674. {
  9675. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9676. }
  9677. else
  9678. {
  9679. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9680. }
  9681. }
  9682. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9683. {
  9684. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9685. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9686. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9687. }
  9688. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9689. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9690. ) //S_PRECHARGE
  9691. {
  9692. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9693. {
  9694. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9696. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9697. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9698. }
  9699. else
  9700. {
  9701. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9702. }
  9703. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9704. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9705. }
  9706. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9707. {
  9708. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9709. {
  9710. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  9711. {
  9712. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9713. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9714. }
  9715. else
  9716. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9717. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9719. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9720. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9721. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9722. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  9723. }
  9724. else
  9725. {
  9726. storeTempStopTransaction(gun_index);
  9727. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9728. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9729. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9730. }
  9731. }
  9732. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9733. {
  9734. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9735. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9736. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9737. if((access(TempStopTransaction,F_OK))!=-1)
  9738. {
  9739. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9740. }
  9741. }
  9742. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9743. {
  9744. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9745. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9746. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9747. }
  9748. 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
  9749. {
  9750. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9751. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9752. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9753. }
  9754. 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
  9755. {
  9756. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9757. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9758. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9759. }
  9760. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9761. {
  9762. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9764. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9765. }
  9766. } //end of the same index
  9767. }
  9768. }
  9769. else
  9770. {
  9771. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9772. {
  9773. tempIndex = 2;
  9774. }
  9775. else
  9776. {
  9777. tempIndex = gun_index;
  9778. }
  9779. for (int index = 0; index < AC_QUANTITY; index++)
  9780. {
  9781. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9782. {
  9783. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9784. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9785. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9786. else
  9787. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9788. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9789. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9790. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9792. {
  9793. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9795. 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))
  9796. {
  9797. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9798. }
  9799. else
  9800. {
  9801. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9802. }
  9803. }
  9804. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9805. {
  9806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9807. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9808. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9809. }
  9810. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9811. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9812. ) //S_PRECHARGE
  9813. {
  9814. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9815. {
  9816. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9819. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9820. }
  9821. else
  9822. {
  9823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9824. }
  9825. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9826. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9827. }
  9828. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9829. {
  9830. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9831. {
  9832. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  9833. {
  9834. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9836. }
  9837. else
  9838. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9839. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9840. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9841. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9842. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9843. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9844. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  9845. }
  9846. else
  9847. {
  9848. storeTempStopTransaction(gun_index);
  9849. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9850. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9851. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9852. }
  9853. }
  9854. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9855. {
  9856. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9857. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9858. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9859. if((access(TempStopTransaction,F_OK))!=-1)
  9860. {
  9861. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9862. }
  9863. }
  9864. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9865. {
  9866. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9867. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9868. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9869. }
  9870. 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
  9871. {
  9872. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9873. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9874. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9875. }
  9876. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9877. {
  9878. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9879. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9880. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9881. }
  9882. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9883. {
  9884. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9885. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9886. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9887. }
  9888. }//end of the same index
  9889. }//end of for AC_QUANTITY
  9890. }
  9891. // Message
  9892. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9893. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  9894. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  9895. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  9896. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  9897. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  9898. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  9899. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  9900. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  9901. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  9902. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  9903. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  9904. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  9905. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  9906. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  9907. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  9908. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  9909. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  9910. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  9911. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  9912. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  9913. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  9914. {
  9915. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  9916. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  9917. json_object_object_add(TransactionEvent, "idToken", idToken);
  9918. }
  9919. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  9920. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  9921. json_object_object_add(TransactionEvent, "evse", evse);
  9922. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  9923. {
  9924. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  9925. {
  9926. json_object *meterValue = json_object_new_object();
  9927. json_object *sampledValues = json_object_new_array();
  9928. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  9929. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  9930. {
  9931. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  9932. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  9933. {
  9934. if(((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)) ||
  9935. (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  9936. {
  9937. json_object *sampledValue = json_object_new_object();
  9938. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  9939. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  9940. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  9941. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  9942. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  9943. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  9944. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  9945. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  9946. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  9947. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  9948. {
  9949. json_object *unitOfMeasure = json_object_new_object();
  9950. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  9951. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  9952. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  9953. }
  9954. json_object_array_add(sampledValues, sampledValue);
  9955. }
  9956. }
  9957. }
  9958. json_object_object_add(meterValue, "sampledValue", sampledValues);
  9959. json_object_array_add(meterValues, meterValue);
  9960. }
  9961. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  9962. }
  9963. random_uuid(guid);
  9964. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  9965. json_object_put(TransactionEvent);
  9966. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  9967. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9968. {
  9969. result = PASS;
  9970. }
  9971. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  9972. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  9973. OCPP_insert_transaction_msg(YES, message);
  9974. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  9975. {
  9976. OCPP_insert_transaction_msg(NO, message);
  9977. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  9978. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9979. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9980. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9981. }
  9982. return result;
  9983. }
  9984. //==========================================
  9985. // send confirm routine
  9986. //==========================================
  9987. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  9988. {
  9989. mtrace();
  9990. int result = FAIL;
  9991. char message[4096]={0};
  9992. json_object *CancelReservation = json_object_new_object();
  9993. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  9994. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  9995. sprintf(message,"[%d,\"%s\",%s]"
  9996. ,MESSAGE_TYPE_CALLRESULT
  9997. ,uuid
  9998. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  9999. json_object_put(CancelReservation);
  10000. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10001. LWS_Send(message);
  10002. result = TRUE;
  10003. return result;
  10004. }
  10005. int sendCertificateSignedConfirmation(char *uuid)
  10006. {
  10007. mtrace();
  10008. int result = FAIL;
  10009. char message[4096]={0};
  10010. json_object *CertificateSigned = json_object_new_object();
  10011. json_object *statusInfo = json_object_new_object();
  10012. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10013. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10014. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10015. {
  10016. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10017. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10018. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10019. }
  10020. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10021. sprintf(message,"[%d,\"%s\",%s]"
  10022. ,MESSAGE_TYPE_CALLRESULT
  10023. ,uuid
  10024. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10025. json_object_put(CertificateSigned);
  10026. LWS_Send(message);
  10027. result = TRUE;
  10028. return result;
  10029. }
  10030. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10031. {
  10032. mtrace();
  10033. int result = FAIL;
  10034. char message[4096]={0};
  10035. json_object *ChangeAvailability = json_object_new_object();
  10036. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10037. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10038. sprintf(message,"[%d,\"%s\",%s]"
  10039. ,MESSAGE_TYPE_CALLRESULT
  10040. ,uuid
  10041. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10042. json_object_put(ChangeAvailability);
  10043. LWS_Send(message);
  10044. result = TRUE;
  10045. return result;
  10046. }
  10047. int sendClearCacheConfirmation(char *uuid)
  10048. {
  10049. mtrace();
  10050. int result = FAIL;
  10051. char message[4096]={0};
  10052. json_object *ClearCache = json_object_new_object();
  10053. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10054. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10055. sprintf(message,"[%d,\"%s\",%s]"
  10056. ,MESSAGE_TYPE_CALLRESULT
  10057. ,uuid
  10058. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10059. json_object_put(ClearCache);
  10060. LWS_Send(message);
  10061. result = TRUE;
  10062. return result;
  10063. }
  10064. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10065. {
  10066. mtrace();
  10067. int result = FAIL;
  10068. char message[500]={0};
  10069. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10070. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10071. LWS_Send(message);
  10072. return result;
  10073. }
  10074. int sendClearDisplayMessageConfirmation(char *uuid)
  10075. {
  10076. mtrace();
  10077. int result = FAIL;
  10078. char message[4096]={0};
  10079. json_object *ClearDisplayMessage = json_object_new_object();
  10080. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10081. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10082. sprintf(message,"[%d,\"%s\",%s]"
  10083. ,MESSAGE_TYPE_CALLRESULT
  10084. ,uuid
  10085. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10086. json_object_put(ClearDisplayMessage);
  10087. LWS_Send(message);
  10088. result = TRUE;
  10089. return result;
  10090. }
  10091. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10092. {
  10093. mtrace();
  10094. int result = FAIL;
  10095. char message[4096]={0};
  10096. json_object *ClearVariableMonitoring = json_object_new_object();
  10097. json_object *clearMonitoringResults = json_object_new_array();
  10098. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10099. for(int idx=0;idx<variableQuantity;idx++)
  10100. {
  10101. json_object *clearMonitoringResult = json_object_new_object();
  10102. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10103. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10104. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10105. }
  10106. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10107. sprintf(message,"[%d,\"%s\",%s]"
  10108. ,MESSAGE_TYPE_CALLRESULT
  10109. ,uuid
  10110. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10111. json_object_put(ClearVariableMonitoring);
  10112. LWS_Send(message);
  10113. result = TRUE;
  10114. return result;
  10115. }
  10116. int sendCostUpdatedConfirmation(char *uuid)
  10117. {
  10118. mtrace();
  10119. int result = FAIL;
  10120. char message[4096]={0};
  10121. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10122. sprintf(message,"[%d,\"%s\",{}]"
  10123. ,MESSAGE_TYPE_CALLRESULT
  10124. ,uuid);
  10125. LWS_Send(message);
  10126. result = TRUE;
  10127. return result;
  10128. }
  10129. int sendCustomerInformationConfirmation(char *uuid)
  10130. {
  10131. mtrace();
  10132. int result = FAIL;
  10133. char message[4096]={0};
  10134. json_object *CustomerInformation = json_object_new_object();
  10135. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10136. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10137. sprintf(message,"[%d,\"%s\",%s]"
  10138. ,MESSAGE_TYPE_CALLRESULT
  10139. ,uuid
  10140. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10141. json_object_put(CustomerInformation);
  10142. LWS_Send(message);
  10143. result = TRUE;
  10144. return result;
  10145. }
  10146. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10147. {
  10148. mtrace();
  10149. int result = FAIL;
  10150. char message[4096]={0};
  10151. json_object *DataTransfer = json_object_new_object();
  10152. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10153. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10154. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10155. sprintf(message,"[%d,\"%s\",%s]"
  10156. ,MESSAGE_TYPE_CALLRESULT
  10157. ,uuid
  10158. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10159. json_object_put(DataTransfer);
  10160. LWS_Send(message);
  10161. result = TRUE;
  10162. return result;
  10163. }
  10164. int sendDeleteCertificateConfirmation(char *uuid)
  10165. {
  10166. mtrace();
  10167. int result = FAIL;
  10168. char message[4096]={0};
  10169. json_object *DeleteCertificate = json_object_new_object();
  10170. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10171. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10172. sprintf(message,"[%d,\"%s\",%s]"
  10173. ,MESSAGE_TYPE_CALLRESULT
  10174. ,uuid
  10175. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10176. json_object_put(DeleteCertificate);
  10177. LWS_Send(message);
  10178. result = TRUE;
  10179. return result;
  10180. }
  10181. int sendGetBaseReportConfirmation(char *uuid)
  10182. {
  10183. mtrace();
  10184. int result = FAIL;
  10185. char message[4096]={0};
  10186. json_object *GetBaseReport = json_object_new_object();
  10187. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10188. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10189. sprintf(message,"[%d,\"%s\",%s]"
  10190. ,MESSAGE_TYPE_CALLRESULT
  10191. ,uuid
  10192. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10193. json_object_put(GetBaseReport);
  10194. LWS_Send(message);
  10195. result = TRUE;
  10196. return result;
  10197. }
  10198. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10199. {
  10200. mtrace();
  10201. int result = FAIL;
  10202. char message[4096]={0};
  10203. json_object *GetChargingProfiles = json_object_new_object();
  10204. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10205. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10206. sprintf(message,"[%d,\"%s\",%s]"
  10207. ,MESSAGE_TYPE_CALLRESULT
  10208. ,uuid
  10209. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10210. json_object_put(GetChargingProfiles);
  10211. LWS_Send(message);
  10212. result = TRUE;
  10213. return result;
  10214. }
  10215. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  10216. {
  10217. mtrace();
  10218. int result = FAIL;
  10219. char message[4096]={0};
  10220. int CompositeScheduleIndex = 0;
  10221. json_object *GetCompositeSchedule = json_object_new_object();
  10222. json_object *schedule = json_object_new_object();
  10223. json_object *chargingSchedule = json_object_new_object();
  10224. json_object *chargingSchedulePeriod = json_object_new_array();
  10225. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10226. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10227. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  10228. json_object_object_add(chargingSchedule, "evseId", json_object_new_int(CompositeScheduleIndex));
  10229. if(nPeriod == 0)
  10230. {
  10231. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10232. {
  10233. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10234. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10235. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10236. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10237. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10238. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10239. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10240. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10241. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10242. {
  10243. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10244. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10245. {
  10246. json_object *Period = json_object_new_object();
  10247. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10248. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10249. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10250. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10251. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10252. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10253. json_object_array_add(chargingSchedulePeriod, Period);
  10254. }
  10255. }
  10256. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10257. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10258. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10259. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10260. }
  10261. }
  10262. else
  10263. {
  10264. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10265. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10266. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10267. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10268. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10269. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10270. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10271. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10272. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10273. {
  10274. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10275. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10276. {
  10277. json_object *Period = json_object_new_object();
  10278. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10279. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10280. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10281. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10282. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10283. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10284. json_object_array_add(chargingSchedulePeriod, Period);
  10285. }
  10286. }
  10287. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10288. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10289. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10290. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10291. }
  10292. sprintf(message,"[%d,\"%s\",%s]"
  10293. ,MESSAGE_TYPE_CALLRESULT
  10294. ,uuid
  10295. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10296. json_object_put(GetCompositeSchedule);
  10297. LWS_Send(message);
  10298. result = TRUE;
  10299. return result;
  10300. }
  10301. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10302. {
  10303. mtrace();
  10304. int result = FAIL;
  10305. char message[4096]={0};
  10306. json_object *GetGetDisplayMessages = json_object_new_object();
  10307. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10308. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10309. sprintf(message,"[%d,\"%s\",%s]"
  10310. ,MESSAGE_TYPE_CALLRESULT
  10311. ,uuid
  10312. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10313. json_object_put(GetGetDisplayMessages);
  10314. LWS_Send(message);
  10315. result = TRUE;
  10316. return result;
  10317. }
  10318. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10319. {
  10320. mtrace();
  10321. int result = FAIL;
  10322. char message[4096]={0};
  10323. json_object *GetInstalledCertificateIds = json_object_new_object();
  10324. json_object *certificateHashDataChains = json_object_new_array();
  10325. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10326. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10327. for(int idx=0;idx<certQuantity;idx++)
  10328. {
  10329. json_object *cert = json_object_new_object();
  10330. json_object *certificateHashData = json_object_new_object();
  10331. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10332. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10333. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10334. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10335. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10336. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10337. json_object_array_add(certificateHashDataChains, cert);
  10338. }
  10339. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10340. sprintf(message,"[%d,\"%s\",%s]"
  10341. ,MESSAGE_TYPE_CALLRESULT
  10342. ,uuid
  10343. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10344. json_object_put(GetInstalledCertificateIds);
  10345. LWS_Send(message);
  10346. result = TRUE;
  10347. return result;
  10348. }
  10349. int sendGetLocalListVersionConfirmation(char *uuid)
  10350. {
  10351. mtrace();
  10352. int result = FAIL;
  10353. char message[4096]={0};
  10354. json_object *GetLocalListVersion = json_object_new_object();
  10355. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10356. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10357. sprintf(message,"[%d,\"%s\",%s]"
  10358. ,MESSAGE_TYPE_CALLRESULT
  10359. ,uuid
  10360. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10361. json_object_put(GetLocalListVersion);
  10362. LWS_Send(message);
  10363. result = TRUE;
  10364. return result;
  10365. }
  10366. int sendGetLogConfirmation(char *uuid)
  10367. {
  10368. mtrace();
  10369. int result = FAIL;
  10370. char message[4096]={0};
  10371. json_object *GetLog = json_object_new_object();
  10372. DEBUG_INFO("sendGetLogConfirmation...\n");
  10373. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10374. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10375. sprintf(message,"[%d,\"%s\",%s]"
  10376. ,MESSAGE_TYPE_CALLRESULT
  10377. ,uuid
  10378. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10379. json_object_put(GetLog);
  10380. LWS_Send(message);
  10381. result = TRUE;
  10382. return result;
  10383. }
  10384. int sendGetMonitoringReportConfirmation(char *uuid)
  10385. {
  10386. mtrace();
  10387. int result = FAIL;
  10388. char message[4096]={0};
  10389. json_object *GetMonitoringReport = json_object_new_object();
  10390. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10391. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10392. sprintf(message,"[%d,\"%s\",%s]"
  10393. ,MESSAGE_TYPE_CALLRESULT
  10394. ,uuid
  10395. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10396. json_object_put(GetMonitoringReport);
  10397. LWS_Send(message);
  10398. result = TRUE;
  10399. return result;
  10400. }
  10401. int sendGetReportConfirmation(char *uuid)
  10402. {
  10403. mtrace();
  10404. int result = FAIL;
  10405. char message[4096]={0};
  10406. json_object *GetReport = json_object_new_object();
  10407. DEBUG_INFO("sendGetReportConfirmation...\n");
  10408. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10409. sprintf(message,"[%d,\"%s\",%s]"
  10410. ,MESSAGE_TYPE_CALLRESULT
  10411. ,uuid
  10412. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10413. json_object_put(GetReport);
  10414. LWS_Send(message);
  10415. result = TRUE;
  10416. return result;
  10417. }
  10418. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  10419. {
  10420. mtrace();
  10421. int result = FAIL;
  10422. char message[4096]={0};
  10423. json_object *GetTransactionStatus = json_object_new_object();
  10424. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10425. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  10426. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  10427. sprintf(message,"[%d,\"%s\",%s]"
  10428. ,MESSAGE_TYPE_CALLRESULT
  10429. ,uuid
  10430. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10431. json_object_put(GetTransactionStatus);
  10432. LWS_Send(message);
  10433. result = TRUE;
  10434. return result;
  10435. }
  10436. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10437. {
  10438. mtrace();
  10439. int result = FAIL;
  10440. char message[4096]={0};
  10441. json_object *GetVariables = json_object_new_object();
  10442. json_object *getVariableResults = json_object_new_array();
  10443. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10444. for(int idx=0;idx<variableQuantity;idx++)
  10445. {
  10446. json_object *variableResult = json_object_new_object();
  10447. json_object *component = json_object_new_object();
  10448. json_object *variable = json_object_new_object();
  10449. json_object *evse = json_object_new_object();
  10450. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10451. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10452. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10453. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10454. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10455. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10456. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10457. json_object_object_add(component, "evse", evse);
  10458. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10459. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10460. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10461. json_object_object_add(variableResult, "component", component);
  10462. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10463. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10464. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10465. json_object_object_add(variableResult, "variable", variable);
  10466. json_object_array_add(getVariableResults, variableResult);
  10467. }
  10468. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10469. sprintf(message,"[%d,\"%s\",%s]"
  10470. ,MESSAGE_TYPE_CALLRESULT
  10471. ,uuid
  10472. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10473. json_object_put(GetVariables);
  10474. LWS_Send(message);
  10475. result = TRUE;
  10476. return result;
  10477. }
  10478. int sendInstallCertificateConfirmation(char *uuid)
  10479. {
  10480. mtrace();
  10481. int result = FAIL;
  10482. char message[4096]={0};
  10483. json_object *InstallCertificate = json_object_new_object();
  10484. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10485. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10486. sprintf(message,"[%d,\"%s\",%s]"
  10487. ,MESSAGE_TYPE_CALLRESULT
  10488. ,uuid
  10489. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10490. json_object_put(InstallCertificate);
  10491. LWS_Send(message);
  10492. result = TRUE;
  10493. return result;
  10494. }
  10495. int sendPublishFirmwareConfirmation(char *uuid)
  10496. {
  10497. mtrace();
  10498. int result = FAIL;
  10499. char message[4096]={0};
  10500. json_object *PublishFirmware = json_object_new_object();
  10501. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10502. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10503. sprintf(message,"[%d,\"%s\",%s]"
  10504. ,MESSAGE_TYPE_CALLRESULT
  10505. ,uuid
  10506. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10507. json_object_put(PublishFirmware);
  10508. LWS_Send(message);
  10509. result = TRUE;
  10510. return result;
  10511. }
  10512. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10513. {
  10514. mtrace();
  10515. int result = FAIL;
  10516. char message[4096]={0};
  10517. json_object *RemoteStartTransaction = json_object_new_object();
  10518. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10519. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10520. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10521. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10522. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10523. sprintf(message,"[%d,\"%s\",%s]"
  10524. ,MESSAGE_TYPE_CALLRESULT
  10525. ,uuid
  10526. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10527. json_object_put(RemoteStartTransaction);
  10528. LWS_Send(message);
  10529. result = TRUE;
  10530. return result;
  10531. }
  10532. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10533. {
  10534. mtrace();
  10535. int result = FAIL;
  10536. char message[4096]={0};
  10537. json_object *RemoteStopTransaction = json_object_new_object();
  10538. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  10539. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  10540. sprintf(message,"[%d,\"%s\",%s]"
  10541. ,MESSAGE_TYPE_CALLRESULT
  10542. ,uuid
  10543. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  10544. json_object_put(RemoteStopTransaction);
  10545. LWS_Send(message);
  10546. result = TRUE;
  10547. return result;
  10548. }
  10549. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  10550. {
  10551. mtrace();
  10552. int result = FAIL;
  10553. char message[4096]={0};
  10554. json_object *ReserveNow = json_object_new_object();
  10555. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  10556. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  10557. sprintf(message,"[%d,\"%s\",%s]"
  10558. ,MESSAGE_TYPE_CALLRESULT
  10559. ,uuid
  10560. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10561. json_object_put(ReserveNow);
  10562. LWS_Send(message);
  10563. result = TRUE;
  10564. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10565. return result;
  10566. }
  10567. int sendResetConfirmation(char *uuid)
  10568. {
  10569. mtrace();
  10570. int result = FAIL;
  10571. char message[4096]={0};
  10572. json_object *Reset = json_object_new_object();
  10573. DEBUG_INFO("sendResetConfirmation...\n");
  10574. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10575. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10576. sprintf(message,"[%d,\"%s\",%s]"
  10577. ,MESSAGE_TYPE_CALLRESULT
  10578. ,uuid
  10579. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10580. json_object_put(Reset);
  10581. LWS_Send(message);
  10582. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10583. {
  10584. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10585. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10586. }
  10587. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10588. {
  10589. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10590. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10591. }
  10592. result = TRUE;
  10593. return result;
  10594. }
  10595. int sendSendLocalListConfirmation(char *uuid)
  10596. {
  10597. mtrace();
  10598. int result = FAIL;
  10599. char message[4096]={0};
  10600. json_object *SendLocalList = json_object_new_object();
  10601. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  10602. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10603. sprintf(message,"[%d,\"%s\",%s]"
  10604. ,MESSAGE_TYPE_CALLRESULT
  10605. ,uuid
  10606. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10607. json_object_put(SendLocalList);
  10608. LWS_Send(message);
  10609. result = TRUE;
  10610. return result;
  10611. }
  10612. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10613. {
  10614. mtrace();
  10615. int result = FAIL;
  10616. char message[4096]={0};
  10617. json_object *SetChargingProfile = json_object_new_object();
  10618. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  10619. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  10620. sprintf(message,"[%d,\"%s\",%s]"
  10621. ,MESSAGE_TYPE_CALLRESULT
  10622. ,uuid
  10623. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10624. json_object_put(SetChargingProfile);
  10625. LWS_Send(message);
  10626. result = TRUE;
  10627. return result;
  10628. }
  10629. int sendSetDisplayMessagesConfirmation(char *uuid)
  10630. {
  10631. mtrace();
  10632. int result = FAIL;
  10633. char message[4096]={0};
  10634. json_object *SetDisplayMessage = json_object_new_object();
  10635. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  10636. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  10637. sprintf(message,"[%d,\"%s\",%s]"
  10638. ,MESSAGE_TYPE_CALLRESULT
  10639. ,uuid
  10640. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10641. json_object_put(SetDisplayMessage);
  10642. LWS_Send(message);
  10643. result = TRUE;
  10644. return result;
  10645. }
  10646. int sendSetMonitoringBaseConfirmation(char *uuid)
  10647. {
  10648. mtrace();
  10649. int result = FAIL;
  10650. char message[4096]={0};
  10651. json_object *SetMonitoringBase = json_object_new_object();
  10652. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  10653. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  10654. sprintf(message,"[%d,\"%s\",%s]"
  10655. ,MESSAGE_TYPE_CALLRESULT
  10656. ,uuid
  10657. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  10658. json_object_put(SetMonitoringBase);
  10659. LWS_Send(message);
  10660. result = TRUE;
  10661. return result;
  10662. }
  10663. int sendSetMonitoringLevelConfirmation(char *uuid)
  10664. {
  10665. mtrace();
  10666. int result = FAIL;
  10667. char message[4096]={0};
  10668. json_object *SetMonitoringLevel = json_object_new_object();
  10669. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  10670. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  10671. sprintf(message,"[%d,\"%s\",%s]"
  10672. ,MESSAGE_TYPE_CALLRESULT
  10673. ,uuid
  10674. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  10675. json_object_put(SetMonitoringLevel);
  10676. LWS_Send(message);
  10677. result = TRUE;
  10678. return result;
  10679. }
  10680. int sendSetNetworkProfileConfirmation(char *uuid)
  10681. {
  10682. mtrace();
  10683. int result = FAIL;
  10684. char message[4096]={0};
  10685. json_object *SetNetworkProfile = json_object_new_object();
  10686. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  10687. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  10688. sprintf(message,"[%d,\"%s\",%s]"
  10689. ,MESSAGE_TYPE_CALLRESULT
  10690. ,uuid
  10691. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  10692. json_object_put(SetNetworkProfile);
  10693. LWS_Send(message);
  10694. result = TRUE;
  10695. return result;
  10696. }
  10697. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10698. {
  10699. mtrace();
  10700. int result = FAIL;
  10701. char message[4096]={0};
  10702. json_object *SetVariableMonitoring = json_object_new_object();
  10703. json_object *setMonitoringResults = json_object_new_array();
  10704. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  10705. for(int idx=0;idx<variableQuantity;idx++)
  10706. {
  10707. json_object *variableMonitorResult = json_object_new_object();
  10708. json_object *component = json_object_new_object();
  10709. json_object *variable = json_object_new_object();
  10710. json_object *evse = json_object_new_object();
  10711. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  10712. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  10713. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  10714. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  10715. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  10716. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  10717. json_object_object_add(component, "evse", evse);
  10718. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  10719. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  10720. json_object_object_add(variableMonitorResult, "component", component);
  10721. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  10722. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  10723. json_object_object_add(variableMonitorResult, "variable", variable);
  10724. json_object_array_add(setMonitoringResults, variableMonitorResult);
  10725. }
  10726. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  10727. sprintf(message,"[%d,\"%s\",%s]"
  10728. ,MESSAGE_TYPE_CALLRESULT
  10729. ,uuid
  10730. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10731. json_object_put(SetVariableMonitoring);
  10732. LWS_Send(message);
  10733. result = TRUE;
  10734. return result;
  10735. }
  10736. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  10737. {
  10738. mtrace();
  10739. int result = FAIL;
  10740. char message[4096]={0};
  10741. json_object *SetVariable = json_object_new_object();
  10742. json_object *setVariableResults = json_object_new_array();
  10743. DEBUG_INFO("sendSetVariableConfirmation...\n");
  10744. for(int idx=0;idx<variableQuantity;idx++)
  10745. {
  10746. json_object *variableResult = json_object_new_object();
  10747. json_object *component = json_object_new_object();
  10748. json_object *variable = json_object_new_object();
  10749. json_object *evse = json_object_new_object();
  10750. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  10751. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  10752. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  10753. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  10754. json_object_object_add(component, "evse", evse);
  10755. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  10756. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  10757. json_object_object_add(variableResult, "component", component);
  10758. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  10759. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  10760. json_object_object_add(variableResult, "variable", variable);
  10761. json_object_array_add(setVariableResults, variableResult);
  10762. }
  10763. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  10764. sprintf(message,"[%d,\"%s\",%s]"
  10765. ,MESSAGE_TYPE_CALLRESULT
  10766. ,uuid
  10767. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  10768. json_object_put(SetVariable);
  10769. LWS_Send(message);
  10770. result = TRUE;
  10771. return result;
  10772. }
  10773. int sendTriggerMessageConfirmation(char *uuid)
  10774. {
  10775. mtrace();
  10776. int result = FAIL;
  10777. char message[4096]={0};
  10778. json_object *TriggerMessage = json_object_new_object();
  10779. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  10780. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  10781. sprintf(message,"[%d,\"%s\",%s]",
  10782. MESSAGE_TYPE_CALLRESULT,
  10783. uuid,
  10784. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  10785. json_object_put(TriggerMessage);
  10786. LWS_Send(message);
  10787. result = TRUE;
  10788. return result;
  10789. }
  10790. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  10791. {
  10792. mtrace();
  10793. int result = FAIL;
  10794. char message[4096]={0};
  10795. json_object *UnlockConnector = json_object_new_object();
  10796. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  10797. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  10798. sprintf(message,"[%d,\"%s\",%s]",
  10799. MESSAGE_TYPE_CALLRESULT,
  10800. uuid,
  10801. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  10802. json_object_put(UnlockConnector);
  10803. LWS_Send(message);
  10804. result = TRUE;
  10805. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  10806. return result;
  10807. }
  10808. int sendUnpublishFirmwareConfirmation(char *uuid)
  10809. {
  10810. mtrace();
  10811. int result = FAIL;
  10812. char message[4096]={0};
  10813. json_object *UnpublishFirmware = json_object_new_object();
  10814. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  10815. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  10816. sprintf(message,"[%d,\"%s\",%s]"
  10817. ,MESSAGE_TYPE_CALLRESULT
  10818. ,uuid
  10819. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  10820. json_object_put(UnpublishFirmware);
  10821. LWS_Send(message);
  10822. result = TRUE;
  10823. return result;
  10824. }
  10825. int sendUpdateFirmwareConfirmation(char *uuid)
  10826. {
  10827. mtrace();
  10828. int result = FAIL;
  10829. char message[4096]={0};
  10830. json_object *UpdateFirmware = json_object_new_object();
  10831. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  10832. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  10833. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  10834. sprintf(message,"[%d,\"%s\",%s]"
  10835. ,MESSAGE_TYPE_CALLRESULT
  10836. ,uuid
  10837. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  10838. json_object_put(UpdateFirmware);
  10839. LWS_Send(message);
  10840. result = TRUE;
  10841. return result;
  10842. }
  10843. int sendUnknownConfirmation(char *uuid)
  10844. {
  10845. mtrace();
  10846. int result = FAIL;
  10847. char message[256]={0};
  10848. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  10849. DEBUG_INFO("sendUnknownConfirmation...\n");
  10850. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  10851. LWS_Send(message);
  10852. result = TRUE;
  10853. return result;
  10854. }
  10855. //==========================================
  10856. // send CallError routine
  10857. //==========================================
  10858. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  10859. {
  10860. mtrace();
  10861. char message[220]={0};
  10862. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  10863. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  10864. LWS_Send(message);
  10865. }
  10866. //==========================================
  10867. // Handle server request routine Start
  10868. //==========================================
  10869. int handleCancelReservationRequest(char *uuid, char *payload)
  10870. {
  10871. mtrace();
  10872. int result = FAIL;
  10873. int gunNO = 0;
  10874. int reservationIdInt = -1;
  10875. DEBUG_INFO("handleCancelReservationRequest...\n");
  10876. json_object *CancelReservation;
  10877. CancelReservation = json_tokener_parse(payload);
  10878. if(!is_error(CancelReservation))
  10879. {
  10880. // Required data
  10881. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  10882. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  10883. }
  10884. json_object_put(CancelReservation);
  10885. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  10886. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  10887. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  10888. if(reservationIdInt != -1)
  10889. {
  10890. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10891. //check Transaction active
  10892. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  10893. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10894. {
  10895. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  10896. {
  10897. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10898. if(gunType[2] == GUN_TYPE_CHAdeMO)
  10899. {
  10900. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  10901. }
  10902. else
  10903. {
  10904. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  10905. }
  10906. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10907. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10908. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10909. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10910. goto end;
  10911. }
  10912. }
  10913. for (int index = 0; index < CCS_QUANTITY; index++)
  10914. {
  10915. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  10916. {
  10917. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10918. if(gunType[2] == GUN_TYPE_CCS)
  10919. {
  10920. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  10921. }
  10922. else
  10923. {
  10924. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  10925. }
  10926. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10927. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10928. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10929. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10930. goto end;
  10931. }
  10932. }
  10933. for (int index = 0; index < GB_QUANTITY; index++)
  10934. {
  10935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  10936. {
  10937. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10938. if(gunType[2] == GUN_TYPE_GBT)
  10939. {
  10940. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  10941. }
  10942. else
  10943. {
  10944. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  10945. }
  10946. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10947. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10948. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10949. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10950. goto end;
  10951. }
  10952. }
  10953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10954. {
  10955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  10956. {
  10957. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10958. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  10959. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10960. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10961. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10962. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10963. goto end;
  10964. }
  10965. }
  10966. for (int index = 0; index < AC_QUANTITY; index++)
  10967. {
  10968. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  10969. {
  10970. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10972. {
  10973. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  10974. }
  10975. else
  10976. {
  10977. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  10978. }
  10979. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10980. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10981. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10982. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10983. goto end;
  10984. }
  10985. }
  10986. }
  10987. //The reservationId does NOT match the reservationId
  10988. sendCancelReservationConfirmation(uuid, gunNO);
  10989. end:
  10990. // Fill in ocpp packet uuid
  10991. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  10992. return result;
  10993. }
  10994. int handleCertificateSignedRequest(char *uuid, char *payload)
  10995. {
  10996. mtrace();
  10997. int result = FAIL;
  10998. json_object *CertificateSigned;
  10999. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11000. CertificateSigned = json_tokener_parse(payload);
  11001. if(!is_error(CertificateSigned))
  11002. {
  11003. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11004. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11005. // Required data
  11006. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11007. // Optional data
  11008. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11009. {
  11010. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11011. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11012. {
  11013. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11014. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11015. fclose(fp);
  11016. }
  11017. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11018. {
  11019. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11020. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11021. fclose(fp);
  11022. }
  11023. }
  11024. else
  11025. {
  11026. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11027. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11028. fclose(fp);
  11029. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11030. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11031. fclose(fp);
  11032. }
  11033. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11034. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11035. }
  11036. else
  11037. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11038. json_object_put(CertificateSigned);
  11039. sendCertificateSignedConfirmation(uuid);
  11040. return result;
  11041. }
  11042. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11043. {
  11044. mtrace();
  11045. int result = FAIL;
  11046. int evseId = 0, gunIndex = 0;
  11047. char operationalStatus[16]={0};
  11048. char comfirmstr[20];
  11049. int specificId = FALSE;
  11050. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11051. json_object *ChangeAvailability;
  11052. ChangeAvailability = json_tokener_parse(payload);
  11053. if(!is_error(ChangeAvailability))
  11054. {
  11055. // Required data
  11056. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11057. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11058. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11059. {
  11060. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11061. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11062. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11063. }
  11064. }
  11065. json_object_put(ChangeAvailability);
  11066. if((evseId != 0) && (evseId <= gunTotalNumber))
  11067. {
  11068. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  11069. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11070. }
  11071. else if(evseId == 0)
  11072. {
  11073. for(int i=0; i < gunTotalNumber; i++)
  11074. {
  11075. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  11076. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11077. }
  11078. }
  11079. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11080. {
  11081. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  11082. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11083. }
  11084. else if(gunIndex == 0)
  11085. {
  11086. for(int i=0; i < gunTotalNumber; i++)
  11087. {
  11088. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  11089. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11090. }
  11091. }
  11092. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11093. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11094. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  11095. {
  11096. specificId = TRUE;
  11097. }
  11098. if(specificId == FALSE)
  11099. goto end;
  11100. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11101. {
  11102. //----------------------gunIndex is 0 ------------------------------------------------//
  11103. if(gunIndex == 0)
  11104. {
  11105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11106. {
  11107. for(int i=0; i < gunTotalNumber; i++)
  11108. {
  11109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11110. {
  11111. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11112. {
  11113. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11114. {
  11115. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11116. goto end;
  11117. }
  11118. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11119. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11120. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11121. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11122. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11123. {
  11124. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11125. goto end;
  11126. }
  11127. }
  11128. }//END FOR CHAdeMO_QUANTITY
  11129. for (int index = 0; index < CCS_QUANTITY; index++)
  11130. {
  11131. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11132. {
  11133. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11134. {
  11135. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11136. goto end;
  11137. }
  11138. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11139. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11140. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11141. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11142. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11143. {
  11144. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11145. goto end;
  11146. }
  11147. }
  11148. }//END FOR CCS_QUANTITY
  11149. for (int index = 0; index < GB_QUANTITY; index++)
  11150. {
  11151. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11152. {
  11153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11154. {
  11155. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11156. goto end;
  11157. }
  11158. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11159. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11160. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11161. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11162. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11163. {
  11164. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11165. goto end;
  11166. }
  11167. }
  11168. }// END FOR GB_QUANTITY
  11169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11170. {
  11171. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11172. {
  11173. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11174. {
  11175. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11176. goto end;
  11177. }
  11178. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11179. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11180. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11181. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11182. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11183. {
  11184. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11185. goto end;
  11186. }
  11187. }
  11188. }// END FOR DO_QUANTITY
  11189. for (int index = 0; index < AC_QUANTITY; index++)
  11190. {
  11191. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11192. {
  11193. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11194. {
  11195. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11196. goto end;
  11197. }
  11198. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11199. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11200. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11201. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11202. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11203. {
  11204. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11205. goto end;
  11206. }
  11207. }
  11208. }//END FOR AC_QUANTITY
  11209. }// END FOR gunTotalNumber
  11210. }
  11211. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11212. {
  11213. for(int i=0; i < gunTotalNumber; i++)
  11214. {
  11215. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11216. {
  11217. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11218. goto end;
  11219. }
  11220. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11221. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11222. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11223. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11224. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11225. {
  11226. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11227. goto end;
  11228. }
  11229. }
  11230. }
  11231. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11232. goto end;
  11233. }
  11234. //----------------------gunIndex is not 0 ------------------------------------------------//
  11235. //check Transaction active
  11236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11237. {
  11238. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  11239. {
  11240. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11241. {
  11242. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11243. goto end;
  11244. }
  11245. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11246. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11247. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11248. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11249. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11250. {
  11251. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11252. goto end;
  11253. }
  11254. else
  11255. {
  11256. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11257. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11258. goto end;
  11259. }
  11260. }
  11261. }//END FOR CHAdeMO_QUANTITY
  11262. for (int index = 0; index < CCS_QUANTITY; index++)
  11263. {
  11264. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  11265. {
  11266. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11267. {
  11268. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11269. goto end;
  11270. }
  11271. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11272. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11273. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11274. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11275. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11276. {
  11277. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11278. goto end;
  11279. }
  11280. else
  11281. {
  11282. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11283. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11284. goto end;
  11285. }
  11286. }
  11287. }//END FOR CCS_QUANTITY
  11288. for (int index = 0; index < GB_QUANTITY; index++)
  11289. {
  11290. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  11291. {
  11292. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11293. {
  11294. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11295. goto end;
  11296. }
  11297. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11298. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11299. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11300. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11301. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11302. {
  11303. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11304. goto end;
  11305. }
  11306. else
  11307. {
  11308. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11309. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11310. goto end;
  11311. }
  11312. }
  11313. }// END FOR GB_QUANTITY
  11314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11315. {
  11316. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  11317. {
  11318. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11319. {
  11320. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11321. goto end;
  11322. }
  11323. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11324. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11325. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11326. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11327. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11328. {
  11329. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11330. goto end;
  11331. }
  11332. else
  11333. {
  11334. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11335. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11336. goto end;
  11337. }
  11338. }
  11339. }// END FOR DO_QUANTITY
  11340. for (int index = 0; index < AC_QUANTITY; index++)
  11341. {
  11342. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  11343. {
  11344. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11345. {
  11346. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11347. goto end;
  11348. }
  11349. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11350. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11351. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11352. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11353. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11354. {
  11355. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11356. goto end;
  11357. }
  11358. else
  11359. {
  11360. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11361. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11362. goto end;
  11363. }
  11364. }
  11365. }//END FOR AC_QUANTITY
  11366. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11367. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11368. {
  11369. //----------------------gunIndex is 0 ------------------------------------------------//
  11370. if(gunIndex == 0)
  11371. {
  11372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11373. {
  11374. for(int i=0; i < gunTotalNumber; i++)
  11375. {
  11376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11377. {
  11378. 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
  11379. {
  11380. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11381. goto end;
  11382. }
  11383. }//END FOR CHAdeMO_QUANTITY
  11384. for (int index = 0; index < CCS_QUANTITY; index++)
  11385. {
  11386. 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
  11387. {
  11388. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11389. goto end;
  11390. }
  11391. }//END FOR CCS_QUANTITY
  11392. for (int index = 0; index < GB_QUANTITY; index++)
  11393. {
  11394. 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
  11395. {
  11396. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11397. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11398. goto end;
  11399. }
  11400. }// END FOR GB_QUANTITY
  11401. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11402. {
  11403. 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
  11404. {
  11405. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11406. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11407. goto end;
  11408. }
  11409. }// END FOR DO_QUANTITY
  11410. for (int index = 0; index < AC_QUANTITY; index++)
  11411. {
  11412. 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
  11413. {
  11414. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11415. goto end;
  11416. }
  11417. }//END FOR CHAdeMO_QUANTITY
  11418. }// END FOR gunTotalNumber
  11419. }
  11420. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11421. {
  11422. for(int i=0; i < gunTotalNumber; i++)
  11423. {
  11424. for (int index = 0; index < AC_QUANTITY; index++)
  11425. {
  11426. 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
  11427. {
  11428. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11429. goto end;
  11430. }
  11431. }//END FOR CHAdeMO_QUANTITY
  11432. } // END FOR gunTotalNumber
  11433. }
  11434. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11435. goto end;
  11436. }
  11437. //----------------------gunIndex is not 0 ------------------------------------------------//
  11438. //check Transaction active
  11439. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11440. {
  11441. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11442. {
  11443. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11444. goto end;
  11445. }
  11446. }//END FOR CHAdeMO_QUANTITY
  11447. for (int index = 0; index < CCS_QUANTITY; index++)
  11448. {
  11449. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11450. {
  11451. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11452. goto end;
  11453. }
  11454. }//END FOR CCS_QUANTITY
  11455. for (int index = 0; index < GB_QUANTITY; index++)
  11456. {
  11457. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11458. {
  11459. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11460. goto end;
  11461. }
  11462. }// END FOR GB_QUANTITY
  11463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11464. {
  11465. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11466. {
  11467. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11468. goto end;
  11469. }
  11470. }// END FOR DO_QUANTITY
  11471. for (int index = 0; index < AC_QUANTITY; index++)
  11472. {
  11473. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11474. {
  11475. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11476. goto end;
  11477. }
  11478. }//END FOR AC_QUANTITY
  11479. }//END FOR AvailabilityEnumTypeStr[Operative]
  11480. end:
  11481. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11482. {
  11483. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  11484. }
  11485. else
  11486. {
  11487. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11488. }
  11489. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11490. {
  11491. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11492. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11493. }
  11494. else if(gunIndex == 0)
  11495. {
  11496. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11497. {
  11498. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  11499. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  11500. }
  11501. }
  11502. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  11503. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11504. return result;
  11505. }
  11506. int handleClearCacheRequest(char *uuid, char *payload)
  11507. {
  11508. mtrace();
  11509. int result = FAIL;
  11510. char rmFileCmd[100]={0};
  11511. struct stat stats;
  11512. DEBUG_INFO("handleClearCacheRequest...\n");
  11513. stat("/Storage/OCPP", &stats);
  11514. // Check for directory existence
  11515. if (S_ISDIR(stats.st_mode) == 1)
  11516. {}
  11517. else
  11518. {
  11519. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  11520. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  11521. system(rmFileCmd);
  11522. }
  11523. if(DB_cleanLocalCache() != PASS)
  11524. {
  11525. DEBUG_INFO("open AuthorizationCache file failed\n");
  11526. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  11527. }
  11528. else
  11529. {
  11530. DEBUG_INFO("open AuthorizationCache file successful\n");
  11531. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  11532. }
  11533. sendClearCacheConfirmation(uuid);
  11534. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11535. return result;
  11536. }
  11537. int handleClearChargingProfileRequest(char *uuid, char *payload)
  11538. {
  11539. mtrace();
  11540. int result = FAIL;
  11541. int resultRename;
  11542. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  11543. char chargingProfilePurposeStr[26]={0};
  11544. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  11545. char tempchargingProfilePurposeStr[26]={0};
  11546. char sstr[160]={0};
  11547. char str[100]={0};
  11548. int c = 0;
  11549. char *loc;
  11550. char fname[200]={0};
  11551. char comfirmstr[20]={0};
  11552. char word[1600]={0};
  11553. int clearflag = FALSE;
  11554. int chargingProfileIdIsNULL = FALSE;
  11555. int connectorIsNULL = FALSE;
  11556. int chargingProfilePurposeIsNULL = FALSE;
  11557. int stackLevelIsNULL = FALSE;
  11558. //int GotoEnd = FALSE;
  11559. FILE *fptr1, *fptr2;
  11560. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  11561. int n_chargingProfile=0;
  11562. int isEmptyFile = FALSE;
  11563. char sLineWord[1600]={0};
  11564. char chargingProfiles[10][100]={0};
  11565. int ChargeProfileCount = 0;
  11566. int ch;
  11567. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11568. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11569. json_object *ClearChargingProfile;
  11570. ClearChargingProfile = json_tokener_parse(payload);
  11571. if(!is_error(ClearChargingProfile))
  11572. {
  11573. // Optional data
  11574. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  11575. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  11576. else
  11577. chargingProfileIdIsNULL = TRUE;
  11578. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  11579. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  11580. else
  11581. connectorIsNULL = TRUE;
  11582. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  11583. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  11584. else
  11585. chargingProfilePurposeIsNULL = TRUE;
  11586. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  11587. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  11588. else
  11589. stackLevelIsNULL = TRUE;
  11590. }
  11591. json_object_put(ClearChargingProfile);
  11592. if(connectorIsNULL == FALSE)
  11593. {
  11594. switch(connectorIdInt)
  11595. {
  11596. case 0:
  11597. if(chargingProfilePurposeIsNULL == TRUE)
  11598. {
  11599. int l = 0;
  11600. strcpy(fname, ChargingStationMaxProfile_JSON);
  11601. if((access(fname,F_OK))!=-1)
  11602. {
  11603. strcpy(chargingProfiles[l], fname);
  11604. l = l + 1;
  11605. }
  11606. strcpy(fname, TxDefaultProfile_0_JSON);
  11607. if((access(fname,F_OK))!=-1)
  11608. {
  11609. strcpy(chargingProfiles[l], fname);
  11610. l = l + 1;
  11611. }
  11612. ChargeProfileCount = l;
  11613. }
  11614. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  11615. {
  11616. strcpy(fname, ChargingStationMaxProfile_JSON);
  11617. if((access(fname,F_OK))!=-1)
  11618. {
  11619. strcpy(chargingProfiles[0], fname);
  11620. ChargeProfileCount = 1;
  11621. }
  11622. }
  11623. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11624. {
  11625. strcpy(fname, TxDefaultProfile_0_JSON);
  11626. if((access(fname,F_OK))!=-1)
  11627. {
  11628. strcpy(chargingProfiles[0], fname);
  11629. ChargeProfileCount = 1;
  11630. }
  11631. }
  11632. break;
  11633. default:
  11634. if(chargingProfilePurposeIsNULL == TRUE)
  11635. {
  11636. int m = 0;
  11637. memset(fname, 0, ARRAY_SIZE(fname));
  11638. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11639. if((access(fname,F_OK))!=-1)
  11640. {
  11641. strcpy(chargingProfiles[m], fname);
  11642. m = m + 1;
  11643. }
  11644. memset(fname, 0, ARRAY_SIZE(fname));
  11645. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11646. if((access(fname,F_OK))!=-1)
  11647. {
  11648. strcpy(chargingProfiles[m], fname);
  11649. m = m + 1;
  11650. }
  11651. ChargeProfileCount = m;
  11652. }
  11653. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11654. {
  11655. //strcpy(fname, TxDefaultProfile_1_JSON);
  11656. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11657. if((access(fname,F_OK))!=-1)
  11658. {
  11659. strcpy(chargingProfiles[0], fname);
  11660. ChargeProfileCount = 1;
  11661. }
  11662. }
  11663. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  11664. {
  11665. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11666. if((access(fname,F_OK))!=-1)
  11667. {
  11668. strcpy(chargingProfiles[0], fname);
  11669. ChargeProfileCount = 1;
  11670. }
  11671. }
  11672. //strcpy(fname, ChargePointMaxProfile_JSON );
  11673. break;
  11674. }
  11675. }
  11676. else // Check all Charging Profiles
  11677. {
  11678. int i = 0;
  11679. char fnametemp[200]={0};
  11680. ChargeProfileCount = 0;
  11681. //Check ChargePointMaxProfile.json exit
  11682. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11683. {
  11684. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  11685. i = i + 1;
  11686. }
  11687. //Check TxDefaultProfile_%d.json
  11688. for(int j=1; j <= gunTotalNumber; j++)
  11689. {
  11690. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11691. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  11692. if((access(fnametemp,F_OK))!=-1)
  11693. {
  11694. strcpy(chargingProfiles[i], fnametemp);
  11695. i = i + 1;
  11696. }
  11697. }
  11698. //Check TxProfile_%d.json
  11699. for(int j=1; j <= gunTotalNumber; j++)
  11700. {
  11701. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11702. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  11703. if((access(fnametemp,F_OK))!=-1)
  11704. {
  11705. strcpy(chargingProfiles[i], fnametemp);
  11706. i = i + 1;
  11707. }
  11708. }
  11709. ChargeProfileCount = i;
  11710. }// End connectorIsNULL is TRUE
  11711. if(ChargeProfileCount == 0)
  11712. {
  11713. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11714. goto end;
  11715. }
  11716. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  11717. {
  11718. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11719. goto end;
  11720. }
  11721. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  11722. {
  11723. memset(str, 0, ARRAY_SIZE(str));
  11724. // clear temp file
  11725. sprintf(str,"rm -f %s",temp);
  11726. system(str);
  11727. for(int k=0; k < ChargeProfileCount; k++)
  11728. {
  11729. memset(str, 0, ARRAY_SIZE(str));
  11730. //clear file in C
  11731. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11732. system(str);
  11733. }
  11734. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11735. goto end;
  11736. }
  11737. else if(connectorIsNULL == TRUE)
  11738. {
  11739. for(int k=0; k < ChargeProfileCount; k++)
  11740. {
  11741. fptr1 = fopen(chargingProfiles[k], "r");
  11742. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  11743. //Check Charging Profile Count
  11744. while(fscanf(fptr1, "%s", word) != EOF)
  11745. {
  11746. //DEBUG_INFO("word=%s\n",word);
  11747. if(strstr(word, "id")!= NULL)
  11748. {
  11749. //DEBUG_INFO("test id \n");
  11750. n_chargingProfile = n_chargingProfile + 1;
  11751. //DEBUG_INFO("id Found\n");
  11752. }
  11753. }
  11754. rewind(fptr1);
  11755. //search Charging Profile Element
  11756. //int i= 0;
  11757. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11758. {
  11759. //------------------------tempconnectorIdInt------------------------//
  11760. loc = strstr(sLineWord, "connectorId");
  11761. c = 0;
  11762. memset(sstr ,0, sizeof(sstr) );
  11763. while (loc[strlen("connectorId")+2+c] != ',')
  11764. {
  11765. sstr[c] = loc[strlen("connectorId")+2+c];
  11766. c++;
  11767. }
  11768. sstr[c] = '\0';
  11769. tempconnectorIdInt = atoi(sstr);
  11770. printf("file's gun number is %d\n", tempconnectorIdInt);
  11771. //--------------------------id--------------------//
  11772. c = 0;
  11773. loc = strstr(sLineWord, "id");
  11774. memset(sstr ,0, ARRAY_SIZE(sstr));
  11775. while (loc[strlen("id")+2+c] != ',')
  11776. {
  11777. sstr[c] = loc[strlen("id")+2+c];
  11778. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11779. c++;
  11780. }
  11781. sstr[c] = '\0';
  11782. tempchargingProfileIdInt = atoi(sstr);
  11783. //stackLevel
  11784. c = 0;
  11785. loc = strstr(sLineWord, "stackLevel");
  11786. memset(sstr ,0, ARRAY_SIZE(sstr));
  11787. while (loc[strlen("stackLevel")+2+c] != ',')
  11788. {
  11789. sstr[c] = loc[strlen("stackLevel")+2+c];
  11790. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11791. c++;
  11792. }
  11793. sstr[c] = '\0';
  11794. tempstackLevelInt = atoi(sstr);
  11795. c = 0;
  11796. loc = strstr(sLineWord, "chargingProfilePurpose");
  11797. memset(sstr ,0, ARRAY_SIZE(sstr));
  11798. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11799. {
  11800. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11801. c++;
  11802. }
  11803. sstr[c] = '\0';
  11804. strcpy(tempchargingProfilePurposeStr, sstr);
  11805. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11806. {
  11807. //------- not write to fptr2-------//
  11808. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11809. //clearflag = TRUE;
  11810. }
  11811. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11812. {
  11813. //------- not write to fptr2-------//
  11814. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11815. }
  11816. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  11817. {
  11818. //------- not write to fptr2-------//
  11819. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11820. }
  11821. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  11822. {
  11823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11824. }
  11825. else
  11826. {
  11827. fprintf(fptr2, sLineWord);//writing data into file
  11828. }
  11829. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11830. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11831. if(clearflag == TRUE)
  11832. {
  11833. fclose(fptr1);
  11834. fclose(fptr2);
  11835. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11836. system(str);
  11837. // clear temp file
  11838. sprintf(str,"rm -f %s",temp);
  11839. system(str);
  11840. }
  11841. else
  11842. {
  11843. fclose(fptr1);
  11844. fclose(fptr2);
  11845. memset(str, 0, ARRAY_SIZE(str));
  11846. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11847. system(str);
  11848. resultRename = rename(temp, chargingProfiles[k]);
  11849. if(resultRename == 0)
  11850. {
  11851. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  11852. }
  11853. else
  11854. {
  11855. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  11856. }
  11857. if(comfirmstr[0]== 0)
  11858. {
  11859. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11860. }
  11861. //Check chargingProfile is empty file
  11862. /*------ Read the file ----------------*/
  11863. fptr1=fopen(chargingProfiles[k],"r");
  11864. ch=fgetc(fptr1);
  11865. rewind(fptr1);
  11866. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11867. if(ch!=EOF)
  11868. {
  11869. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  11870. {
  11871. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  11872. if(sLineWord[0]=='\0')
  11873. {
  11874. isEmptyFile = TRUE;
  11875. break;
  11876. }
  11877. else
  11878. {
  11879. isEmptyFile = FALSE;
  11880. break;
  11881. }
  11882. }
  11883. }
  11884. else
  11885. isEmptyFile = TRUE;
  11886. fclose(fptr1);
  11887. if(isEmptyFile == TRUE)
  11888. {
  11889. memset(str, 0, ARRAY_SIZE(str));
  11890. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11891. system(str);
  11892. }
  11893. }
  11894. }// End of while(int k=0; k < ChargePointCount; k++)
  11895. }
  11896. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  11897. {
  11898. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  11899. for(int k=0; k < ChargeProfileCount; k++)
  11900. {
  11901. fptr1 = fopen(chargingProfiles[k], "r");
  11902. fptr2 = fopen(temp, "w+");
  11903. //Check Charging Profile Count
  11904. while(fscanf(fptr1, "%s", word) != EOF)
  11905. {
  11906. //DEBUG_INFO("word=%s\n",word);
  11907. if(strstr(word, "id")!= NULL)
  11908. {
  11909. n_chargingProfile = n_chargingProfile + 1;
  11910. }
  11911. }
  11912. rewind(fptr1);
  11913. //search Charging Profile Element
  11914. //int i= 0;
  11915. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11916. {
  11917. //*************************tempconnectorIdInt*********************************/
  11918. loc = strstr(sLineWord, "connectorId");
  11919. c = 0;
  11920. memset(sstr ,0, ARRAY_SIZE(sstr));
  11921. while (loc[strlen("connectorId")+2+c] != ',')
  11922. {
  11923. sstr[c] = loc[strlen("connectorId")+2+c];
  11924. c++;
  11925. }
  11926. sstr[c] = '\0';
  11927. tempconnectorIdInt = atoi(sstr);
  11928. //id
  11929. c = 0;
  11930. loc = strstr(sLineWord, "id");
  11931. memset(sstr ,0, ARRAY_SIZE(sstr));
  11932. while (loc[strlen("id")+2+c] != ',')
  11933. {
  11934. sstr[c] = loc[strlen("id")+2+c];
  11935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11936. c++;
  11937. }
  11938. sstr[c] = '\0';
  11939. tempchargingProfileIdInt = atoi(sstr);
  11940. //stackLevel
  11941. c = 0;
  11942. loc = strstr(sLineWord, "stackLevel");
  11943. memset(sstr ,0, ARRAY_SIZE(sstr));
  11944. while (loc[strlen("stackLevel")+2+c] != ',')
  11945. {
  11946. sstr[c] = loc[strlen("stackLevel")+2+c];
  11947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11948. c++;
  11949. }
  11950. sstr[c] = '\0';
  11951. tempstackLevelInt = atoi(sstr);
  11952. c = 0;
  11953. loc = strstr(sLineWord, "chargingProfilePurpose");
  11954. memset(sstr ,0, ARRAY_SIZE(sstr));
  11955. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11956. {
  11957. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11958. c++;
  11959. }
  11960. sstr[c] = '\0';
  11961. strcpy(tempchargingProfilePurposeStr, sstr);
  11962. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11963. {
  11964. //------- not write to fptr2-------//
  11965. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11966. //clearflag = TRUE;
  11967. }
  11968. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  11969. {
  11970. //------- not write to fptr2-------//
  11971. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11972. }
  11973. else if(stackLevelIsNULL == TRUE)
  11974. {
  11975. //Clear Whole File
  11976. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11977. clearflag = TRUE;
  11978. break;
  11979. }
  11980. else
  11981. {
  11982. fprintf(fptr2, sLineWord);//writing data into file
  11983. }
  11984. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11985. }
  11986. if(clearflag == TRUE)
  11987. {
  11988. fclose(fptr1);
  11989. fclose(fptr2);
  11990. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11991. system(str);
  11992. // clear temp file
  11993. sprintf(str,"rm -f %s",temp);
  11994. system(str);
  11995. }
  11996. else
  11997. {
  11998. fclose(fptr1);
  11999. fclose(fptr2);
  12000. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12001. system(str);
  12002. resultRename = rename(temp, chargingProfiles[k]);
  12003. if(resultRename == 0)
  12004. {
  12005. DEBUG_INFO("File ChargingProfile renamed successfully");
  12006. }
  12007. else
  12008. {
  12009. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12010. }
  12011. if(comfirmstr[0]== 0)
  12012. {
  12013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12014. }
  12015. //Check chargingProfile is empty file
  12016. /*------ Read the file ----------------*/
  12017. fptr1=fopen(chargingProfiles[k],"r");
  12018. ch=fgetc(fptr1);
  12019. rewind(fptr1);
  12020. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12021. if(ch!=EOF)
  12022. {
  12023. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12024. {
  12025. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12026. if(sLineWord[0]=='\0')
  12027. {
  12028. isEmptyFile = TRUE;
  12029. break;
  12030. }
  12031. else
  12032. {
  12033. isEmptyFile = FALSE;
  12034. break;
  12035. }
  12036. }
  12037. }
  12038. else
  12039. isEmptyFile = TRUE;
  12040. fclose(fptr1);
  12041. if(isEmptyFile == TRUE)
  12042. {
  12043. memset(str, 0, ARRAY_SIZE(str));
  12044. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12045. system(str);
  12046. }
  12047. /*------- End of reading ---------------*/
  12048. }
  12049. } // while(int k=0; k < ChargeProfileCount; k++)
  12050. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12051. end:
  12052. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12053. {
  12054. if(connectorIdInt == 0)
  12055. {
  12056. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12057. {
  12058. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12059. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12060. }
  12061. }
  12062. else
  12063. {
  12064. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12065. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  12066. }
  12067. }
  12068. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12069. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12070. return result;
  12071. }
  12072. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12073. {
  12074. mtrace();
  12075. int result = FAIL;
  12076. json_object *ClearDisplayMessage;
  12077. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12078. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12079. ClearDisplayMessage = json_tokener_parse(payload);
  12080. if(!is_error(ClearDisplayMessage))
  12081. {
  12082. // Required data
  12083. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12084. {
  12085. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12086. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12087. }
  12088. }
  12089. json_object_put(ClearDisplayMessage);
  12090. sendCostUpdatedConfirmation(uuid);
  12091. return result;
  12092. }
  12093. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12094. {
  12095. mtrace();
  12096. int result = FAIL;
  12097. json_object *ClearVariableMonitorin;
  12098. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12099. ClearVariableMonitorin = json_tokener_parse(payload);
  12100. if(!is_error(ClearVariableMonitorin))
  12101. {
  12102. // Required data
  12103. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12104. {
  12105. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12106. {
  12107. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12108. /*
  12109. * TODO:
  12110. * 1. Check response
  12111. */
  12112. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12113. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12114. }
  12115. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12116. }
  12117. }
  12118. json_object_put(ClearVariableMonitorin);
  12119. return result;
  12120. }
  12121. int handleCostUpdatedRequest(char *uuid, char *payload)
  12122. {
  12123. mtrace();
  12124. int result = FAIL;
  12125. json_object *CostUpdate;
  12126. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12127. CostUpdate = json_tokener_parse(payload);
  12128. if(!is_error(CostUpdate))
  12129. {
  12130. // Required data
  12131. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12132. {
  12133. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12134. }
  12135. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12136. {
  12137. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12138. }
  12139. }
  12140. json_object_put(CostUpdate);
  12141. sendCostUpdatedConfirmation(uuid);
  12142. return result;
  12143. }
  12144. int handleCustomerInformationRequest(char *uuid, char *payload)
  12145. {
  12146. mtrace();
  12147. int result = FAIL;
  12148. json_object *CustomerInformation;
  12149. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12150. CustomerInformation = json_tokener_parse(payload);
  12151. if(!is_error(CustomerInformation))
  12152. {
  12153. // Required data
  12154. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12155. {
  12156. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12157. }
  12158. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12159. {
  12160. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12161. }
  12162. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12163. {
  12164. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12165. }
  12166. // Optional data
  12167. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12168. {
  12169. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12170. {
  12171. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12172. }
  12173. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12174. {
  12175. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12176. }
  12177. }
  12178. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12179. {
  12180. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12181. {
  12182. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12183. }
  12184. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12185. {
  12186. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12187. }
  12188. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12189. {
  12190. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12191. }
  12192. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12193. {
  12194. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12195. }
  12196. }
  12197. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12198. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12199. }
  12200. else
  12201. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12202. json_object_put(CustomerInformation);
  12203. sendCustomerInformationConfirmation(uuid);
  12204. return result;
  12205. }
  12206. void createFirmwareVersionByDataTransfer(void)
  12207. {
  12208. json_object *FirmwareDataTransfer = json_object_new_object();
  12209. // AC & DC model
  12210. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12211. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12212. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12213. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12214. // DC model
  12215. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12216. {
  12217. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12218. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12219. (gunType[3] != GUN_TYPE_UNKNOWN))
  12220. {
  12221. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12222. }
  12223. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12224. {
  12225. // DS DM DW
  12226. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12227. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12228. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12229. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12230. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12231. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12232. }
  12233. else
  12234. {
  12235. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12236. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12237. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12238. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12239. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12240. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12241. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12242. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12243. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12244. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12245. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12246. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12247. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12248. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12249. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12250. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12251. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12252. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12253. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12254. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12255. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12256. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12257. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12258. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12259. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12260. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12261. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12262. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12263. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12264. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12265. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12266. }
  12267. }
  12268. // 4G model
  12269. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12270. {
  12271. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12272. }
  12273. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12274. json_object_put(FirmwareDataTransfer);
  12275. }
  12276. int handleDataTransferRequest(char *uuid, char *payload)
  12277. {
  12278. mtrace();
  12279. int result = PASS;
  12280. DEBUG_INFO("handleDataTransferRequest...\n");
  12281. if((uuid != NULL) && (payload != NULL))
  12282. {
  12283. json_object *DataTransfer;
  12284. DataTransfer = json_tokener_parse(payload);
  12285. if(!is_error(DataTransfer))
  12286. {
  12287. // Required data
  12288. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12289. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12290. // Optional data
  12291. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12292. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12293. if(json_object_object_get(DataTransfer, "data") != NULL)
  12294. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12295. result = PASS;
  12296. }
  12297. json_object_put(DataTransfer);
  12298. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12299. {
  12300. // Send all moudle firmware version on EVSE
  12301. createFirmwareVersionByDataTransfer();
  12302. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12303. }
  12304. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12305. {
  12306. system("/usr/bin/run_tmate_restart.sh &");
  12307. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12308. }
  12309. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12310. {
  12311. json_object *data;
  12312. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12313. if(!is_error(data))
  12314. {
  12315. 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))
  12316. {
  12317. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12318. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12319. if(json_object_object_get(data, "SOC") != NULL)
  12320. {
  12321. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12322. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12323. }
  12324. if(json_object_object_get(data, "Energy") != NULL)
  12325. {
  12326. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12327. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12328. }
  12329. if(json_object_object_get(data, "Duration") != NULL)
  12330. {
  12331. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12332. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12333. }
  12334. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12335. }
  12336. else
  12337. {
  12338. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12339. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12340. }
  12341. }
  12342. else
  12343. {
  12344. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12345. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12346. }
  12347. json_object_put(data);
  12348. }
  12349. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12350. {
  12351. json_object *data;
  12352. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12353. if(!is_error(data))
  12354. {
  12355. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12356. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12357. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12358. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12359. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12360. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12361. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12362. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12363. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12364. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12365. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12366. }
  12367. else
  12368. {
  12369. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12370. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12371. }
  12372. json_object_put(data);
  12373. }
  12374. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12375. {
  12376. json_object *data;
  12377. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12378. if(!is_error(data))
  12379. {
  12380. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12381. if(json_object_object_get(data, "Content_Type") != NULL)
  12382. {
  12383. 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))
  12384. {
  12385. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12386. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12387. {
  12388. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12389. }
  12390. }
  12391. else
  12392. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12393. }
  12394. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12395. }
  12396. else
  12397. {
  12398. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12399. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12400. }
  12401. json_object_put(data);
  12402. }
  12403. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12404. {
  12405. json_object *data;
  12406. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12407. if(!is_error(data))
  12408. {
  12409. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12410. if(json_object_object_get(data, "ConnectorId") != NULL)
  12411. {
  12412. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12413. }
  12414. if(json_object_object_get(data, "Page_Index") != NULL)
  12415. {
  12416. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12417. }
  12418. if(json_object_object_get(data, "Duration") != NULL)
  12419. {
  12420. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12421. }
  12422. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12423. }
  12424. else
  12425. {
  12426. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12427. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12428. }
  12429. json_object_put(data);
  12430. }
  12431. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12432. {
  12433. json_object *data;
  12434. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12435. if(!is_error(data))
  12436. {
  12437. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12438. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12439. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12440. {
  12441. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12442. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12443. else
  12444. {
  12445. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12446. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12447. }
  12448. }
  12449. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12450. {
  12451. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12452. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12453. else
  12454. {
  12455. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12456. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12457. }
  12458. }
  12459. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12460. {
  12461. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12462. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12463. else
  12464. {
  12465. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12466. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12467. }
  12468. }
  12469. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12470. {
  12471. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12472. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12473. else
  12474. {
  12475. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12476. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12477. }
  12478. }
  12479. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12480. {
  12481. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12482. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12483. else
  12484. {
  12485. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12486. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12487. }
  12488. }
  12489. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12490. {
  12491. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  12492. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  12493. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  12494. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  12495. else
  12496. {
  12497. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12498. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12499. }
  12500. }
  12501. if(json_object_object_get(data, "isAuthentication") != NULL)
  12502. {
  12503. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  12504. {
  12505. case 0:
  12506. case 1:
  12507. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  12508. break;
  12509. default:
  12510. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12511. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12512. break;
  12513. }
  12514. }
  12515. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  12516. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12517. }
  12518. else
  12519. {
  12520. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12521. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12522. }
  12523. json_object_put(data);
  12524. }
  12525. else
  12526. {
  12527. // Can not find valid message id
  12528. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12529. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  12530. ,ShmOCPP20Data->DataTransfer[0].vendorId
  12531. ,ShmOCPP20Data->DataTransfer[0].messageId
  12532. ,ShmOCPP20Data->DataTransfer[0].data);
  12533. }
  12534. }
  12535. else
  12536. {
  12537. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12538. result = FAIL;
  12539. }
  12540. sendDataTransferConfirmation(uuid, 0);
  12541. return result;
  12542. }
  12543. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12544. {
  12545. mtrace();
  12546. int result = FAIL;
  12547. json_object *DeleteCertificate;
  12548. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12549. DeleteCertificate = json_tokener_parse(payload);
  12550. if(!is_error(DeleteCertificate))
  12551. {
  12552. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  12553. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  12554. // Required data
  12555. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  12556. {
  12557. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  12558. {
  12559. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12560. }
  12561. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  12562. {
  12563. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12564. }
  12565. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  12566. {
  12567. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12568. }
  12569. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  12570. {
  12571. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12572. }
  12573. /*
  12574. * TODO:
  12575. * 1. Delete certification and response
  12576. */
  12577. if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA256]) != NULL)
  12578. {
  12579. }
  12580. else if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA384]) != NULL)
  12581. {
  12582. }
  12583. else
  12584. {
  12585. }
  12586. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  12587. }
  12588. }
  12589. else
  12590. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  12591. json_object_put(DeleteCertificate);
  12592. sendDeleteCertificateConfirmation(uuid);
  12593. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12594. return result;
  12595. }
  12596. int handleGetBaseReportRequest(char *uuid, char *payload)
  12597. {
  12598. mtrace();
  12599. int result = FAIL;
  12600. json_object *GetBaseRepor;
  12601. DEBUG_INFO("handleGetBaseReportRequest...\n");
  12602. GetBaseRepor = json_tokener_parse(payload);
  12603. if(!is_error(GetBaseRepor))
  12604. {
  12605. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  12606. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  12607. // Required data
  12608. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  12609. {
  12610. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  12611. }
  12612. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  12613. {
  12614. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  12615. }
  12616. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  12617. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12618. else
  12619. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12620. }
  12621. else
  12622. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12623. json_object_put(GetBaseRepor);
  12624. sendGetBaseReportConfirmation(uuid);
  12625. return result;
  12626. }
  12627. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  12628. {
  12629. mtrace();
  12630. int result = FAIL;
  12631. int gun_index = -1;
  12632. json_object *GetChargingProfiles;
  12633. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  12634. GetChargingProfiles = json_tokener_parse(payload);
  12635. if(!is_error(GetChargingProfiles))
  12636. {
  12637. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  12638. {
  12639. 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;
  12640. }
  12641. if(gun_index >-1)
  12642. {
  12643. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  12644. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  12645. // Required data
  12646. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  12647. {
  12648. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  12649. }
  12650. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  12651. {
  12652. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  12653. {
  12654. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  12655. }
  12656. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  12657. {
  12658. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  12659. }
  12660. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  12661. {
  12662. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  12663. {
  12664. 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)));
  12665. }
  12666. }
  12667. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  12668. {
  12669. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  12670. {
  12671. 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));
  12672. }
  12673. }
  12674. }
  12675. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  12676. }
  12677. else
  12678. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  12679. }
  12680. json_object_put(GetChargingProfiles);
  12681. sendGetChargingProfilesConfirmation(uuid, gun_index);
  12682. return result;
  12683. }
  12684. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  12685. {
  12686. mtrace();
  12687. int result = FAIL;
  12688. int connectorIdInt, durationInt;
  12689. char chargingRateUnitStr[4]={0};
  12690. char comfirmstr[20];
  12691. int confirmPeriods = 0;
  12692. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  12693. json_object *GetCompositeSchedule;
  12694. GetCompositeSchedule = json_tokener_parse(payload);
  12695. if(!is_error(GetCompositeSchedule))
  12696. {
  12697. // Required data
  12698. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  12699. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  12700. else
  12701. connectorIdInt = -1;
  12702. if(json_object_object_get(GetCompositeSchedule, "duration"))
  12703. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  12704. else
  12705. durationInt = 86400;
  12706. // Optional data
  12707. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  12708. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  12709. }
  12710. json_object_put(GetCompositeSchedule);
  12711. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  12712. if((connectorIdInt == 0) ||
  12713. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  12714. {
  12715. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  12716. struct ChargingProfileType tmpProfile[1];
  12717. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  12718. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  12719. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  12720. {
  12721. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  12722. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  12723. }
  12724. else
  12725. {
  12726. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  12727. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  12728. }
  12729. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12730. {
  12731. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  12732. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  12733. }
  12734. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  12735. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12736. {
  12737. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  12738. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  12739. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  12740. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  12741. (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))
  12742. {
  12743. confirmPeriods = idx;
  12744. break;
  12745. }
  12746. }
  12747. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  12748. {
  12749. confirmPeriods += 1;
  12750. }
  12751. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12752. }
  12753. else
  12754. {
  12755. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  12756. }
  12757. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  12758. return result;
  12759. }
  12760. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  12761. {
  12762. mtrace();
  12763. int result = FAIL;
  12764. json_object *GetDisplayMessages;
  12765. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  12766. GetDisplayMessages = json_tokener_parse(payload);
  12767. if(!is_error(GetDisplayMessages))
  12768. {
  12769. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  12770. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  12771. // Required data
  12772. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  12773. {
  12774. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  12775. }
  12776. // Optional data
  12777. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  12778. {
  12779. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  12780. }
  12781. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  12782. {
  12783. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  12784. }
  12785. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  12786. {
  12787. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  12788. {
  12789. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  12790. }
  12791. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  12792. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  12793. }
  12794. else
  12795. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  12796. }
  12797. json_object_put(GetDisplayMessages);
  12798. return result;
  12799. }
  12800. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12801. {
  12802. mtrace();
  12803. int result = FAIL;
  12804. json_object *GetInstalledCertificateIds;
  12805. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12806. GetInstalledCertificateIds = json_tokener_parse(payload);
  12807. if(!is_error(GetInstalledCertificateIds))
  12808. {
  12809. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  12810. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  12811. // Optional data
  12812. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  12813. {
  12814. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  12815. {
  12816. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  12817. /*
  12818. * TODO:
  12819. * 1. Get installed certificate info for response
  12820. */
  12821. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GRootCertificate]) != NULL)
  12822. {
  12823. }
  12824. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_MORootCertificate]) != NULL)
  12825. {
  12826. }
  12827. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_CSMSRootCertificate]) != NULL)
  12828. {
  12829. }
  12830. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GCertificateChain]) != NULL)
  12831. {
  12832. }
  12833. else
  12834. {
  12835. }
  12836. }
  12837. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  12838. }
  12839. else
  12840. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  12841. }
  12842. json_object_put(GetInstalledCertificateIds);
  12843. sendInstallCertificateConfirmation(uuid);
  12844. return result;
  12845. }
  12846. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  12847. {
  12848. mtrace();
  12849. int result = FAIL;
  12850. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  12851. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  12852. {
  12853. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  12854. localversion = 0;
  12855. }
  12856. else
  12857. {
  12858. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  12859. localversion = 0;
  12860. DB_getListVerion();
  12861. }
  12862. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  12863. sendGetLocalListVersionConfirmation(uuid);
  12864. return result;
  12865. }
  12866. static char fnamePlusPath[100]={0};
  12867. static char fnamePWithNoPath[60]={0};
  12868. void checkUploadLog(void)
  12869. {
  12870. FILE *fp;
  12871. /* Open the command for reading. */
  12872. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  12873. if (fp == NULL) {
  12874. printf("Failed to run command\n" );
  12875. exit(1);
  12876. }
  12877. int ftppathlen = 0;
  12878. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  12879. int i = 0;
  12880. /* Read the output a line at a time - output it. */
  12881. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  12882. if(i==0)
  12883. {
  12884. ftppathlen = strlen(fnamePlusPath);
  12885. printf("%s\n", fnamePlusPath);
  12886. fnamePlusPath[ftppathlen]='\0';
  12887. break;
  12888. }
  12889. i= i+1;
  12890. }
  12891. /* close */
  12892. pclose(fp);
  12893. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  12894. {
  12895. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  12896. {
  12897. fnamePlusPath[k]='\0';
  12898. }
  12899. }
  12900. i=1;
  12901. //char fname[60]={0};
  12902. while(i < ftppathlen)
  12903. {
  12904. int len=ftppathlen-i;
  12905. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  12906. {
  12907. printf("compare '/' all right\n");
  12908. break;
  12909. }
  12910. i=i+1;
  12911. }
  12912. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  12913. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  12914. fnamePWithNoPath[i+1] = '\0';
  12915. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  12916. {
  12917. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  12918. {
  12919. fnamePWithNoPath[j]='\0';
  12920. }
  12921. }
  12922. FILE* fp1 = fopen(fnamePlusPath, "r");
  12923. if (fp1)
  12924. {
  12925. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  12926. // file exists
  12927. fclose(fp1);
  12928. }
  12929. else
  12930. {
  12931. // file doesn't exist
  12932. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  12933. }
  12934. }
  12935. void* GetLogProcess(void* data)
  12936. {
  12937. pthread_detach(pthread_self());
  12938. mtrace();
  12939. int requestId, retriesInt=0, retryIntervalInt=0;
  12940. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  12941. 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};
  12942. int port=0;
  12943. int isSuccess = FALSE;
  12944. char ftpbuf[1024]={0};
  12945. char cmdBuf[2048];
  12946. struct tm *tmNow;
  12947. time_t CurrentTime;
  12948. struct tm tmStart;
  12949. struct tm tmStop;
  12950. CurrentTime = time(NULL);
  12951. tmNow=localtime(&CurrentTime);
  12952. uint16_t targetYear, targetMonth;
  12953. json_object *GetLog;
  12954. DEBUG_INFO("GetGetProcess...\n");
  12955. GetLog = json_tokener_parse(data);
  12956. if(!is_error(GetLog))
  12957. {
  12958. // Required data
  12959. if(json_object_object_get(GetLog, "requestId") != NULL)
  12960. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12961. if(json_object_object_get(GetLog, "logType") != NULL)
  12962. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12963. if(json_object_object_get(GetLog, "log") != NULL)
  12964. {
  12965. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  12966. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12967. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12968. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12969. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12970. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12971. }
  12972. // Optional data
  12973. if(json_object_object_get(GetLog, "retries") != NULL)
  12974. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12975. else
  12976. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  12977. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12978. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12979. else
  12980. retryIntervalInt = 30;
  12981. }
  12982. json_object_put(GetLog);
  12983. ShmOCPP20Data->GetLog.requestId = requestId;
  12984. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  12985. {
  12986. /*
  12987. * TODO:
  12988. * 1. Pack security log
  12989. */
  12990. }
  12991. else
  12992. {
  12993. // Pack log to compress file
  12994. 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) &&
  12995. (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))
  12996. {
  12997. // Pack system log
  12998. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  12999. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13000. targetYear = tmStart.tm_year;
  13001. targetMonth = tmStart.tm_mon;
  13002. do
  13003. {
  13004. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13005. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13006. if(targetMonth+1>=13)
  13007. {
  13008. targetYear += 1;
  13009. targetMonth = 1;
  13010. }
  13011. else
  13012. {
  13013. targetMonth += 1;
  13014. }
  13015. }while((targetYear < (tmNow->tm_year+1900)) ||
  13016. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13017. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13018. system(cmdBuf);
  13019. // Pack charging & event log
  13020. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13021. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13022. targetYear = tmStart.tm_year;
  13023. targetMonth = tmStart.tm_mon;
  13024. do
  13025. {
  13026. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13027. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  13028. if(targetMonth+1>=13)
  13029. {
  13030. targetYear += 1;
  13031. targetMonth = 1;
  13032. }
  13033. else
  13034. {
  13035. targetMonth += 1;
  13036. }
  13037. }while((targetYear < (tmNow->tm_year+1900)) ||
  13038. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13039. if(isCancelUploadLog)
  13040. {
  13041. isCancelUploadLog = FALSE;
  13042. pthread_exit(NULL);
  13043. }
  13044. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13045. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13046. system(cmdBuf);
  13047. // Combine log file
  13048. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13049. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13050. }
  13051. else
  13052. {
  13053. system("exec /root/logPackTools 'log' 6");
  13054. }
  13055. }
  13056. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13057. system(cmdBuf);
  13058. checkUploadLog();
  13059. //****************location*******************/
  13060. if(strcmp(remoteLocation,"")==0)
  13061. {
  13062. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13063. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13064. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13065. goto end;
  13066. }
  13067. memset(protocol, 0, ARRAY_SIZE(protocol));
  13068. memset(user, 0, ARRAY_SIZE(user) );
  13069. memset(password, 0, ARRAY_SIZE(password));
  13070. memset(host, 0, ARRAY_SIZE(host));
  13071. memset(path, 0, ARRAY_SIZE(path));
  13072. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13073. memset(host1, 0, ARRAY_SIZE(host1));
  13074. memset(path1, 0, ARRAY_SIZE(path1));
  13075. /*location: ftp://user:password@host:port/path*/
  13076. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13077. if((access(fnamePlusPath,F_OK))!=-1)
  13078. {
  13079. DEBUG_INFO("fnamePlusPath exist.\n");
  13080. }
  13081. else
  13082. {
  13083. DEBUG_INFO("fnamePlusPath not exist!\n");
  13084. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13085. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13086. goto end;
  13087. }
  13088. if(strchr(remoteLocation,'@')==NULL)
  13089. {
  13090. sscanf(remoteLocation,
  13091. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13092. protocol, host, &port, path);
  13093. strcpy(user,"anonymous");
  13094. strcpy(password,"");
  13095. }
  13096. else
  13097. {
  13098. //DEBUG_INFO("pch=%s\n", pch);
  13099. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13100. protocol, user, password, host, &port, path);
  13101. }
  13102. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13103. {
  13104. DEBUG_INFO("protocol is not ftp/http ! \n");
  13105. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13106. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13107. goto end;
  13108. }
  13109. if(strncmp(remoteLocation,"http", 4) == 0)
  13110. {
  13111. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13112. sprintf(ftppath,"/%s", path);
  13113. do
  13114. {
  13115. if(isCancelUploadLog)
  13116. {
  13117. isCancelUploadLog = FALSE;
  13118. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  13119. pthread_exit(NULL);
  13120. }
  13121. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13122. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13123. sleep(3);
  13124. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13125. if(!isSuccess)
  13126. {
  13127. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13128. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13129. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13130. sleep(retryIntervalInt);
  13131. }
  13132. else
  13133. {
  13134. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13135. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13136. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13137. }
  13138. retriesInt--;
  13139. }while((isSuccess == 0)&&(retriesInt >= 0));
  13140. }
  13141. else
  13142. {
  13143. sscanf(host,"%[^/]%s",host1, path1);
  13144. if(strlen(path) > 0)
  13145. sprintf(ftppath,"/%s", path);
  13146. else
  13147. sprintf(ftppath,"/%s", path1);
  13148. int ftppathlen=strlen(ftppath);
  13149. int i=1;
  13150. char filenametemp[50];
  13151. while(i < ftppathlen)
  13152. {
  13153. int len=ftppathlen-i;
  13154. if(ftppath[len]== 47) // '/' ascll code: 47
  13155. {
  13156. DEBUG_INFO("find '/' all right\n");
  13157. break;
  13158. }
  13159. i=i+1;
  13160. }
  13161. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13162. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13163. filenametemp[i+1] = 0;
  13164. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13165. if(port == 0)
  13166. port = 21;
  13167. do
  13168. {
  13169. if(isCancelUploadLog)
  13170. {
  13171. isCancelUploadLog = FALSE;
  13172. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  13173. pthread_exit(NULL);
  13174. }
  13175. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13176. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13177. sleep(3);
  13178. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13179. if(!isSuccess)
  13180. {
  13181. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13182. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13183. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13184. sleep(retryIntervalInt);
  13185. }
  13186. else
  13187. {
  13188. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13189. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13190. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13191. }
  13192. retriesInt--;
  13193. }while((!isSuccess)&&(retriesInt >= 0));
  13194. }
  13195. end:
  13196. system("rm -f /mnt/*");
  13197. sleep(5);
  13198. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13199. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13200. interLock.isGetLogGoing = OFF;
  13201. pthread_exit(NULL);
  13202. }
  13203. int handleGetLogRequest(char *uuid, char *payload)
  13204. {
  13205. mtrace();
  13206. int result = FAIL;
  13207. char fName[258];
  13208. time_t CurrentTime;
  13209. struct tm *tm;
  13210. pthread_t th_Status;
  13211. CurrentTime = time(NULL);
  13212. tm = localtime(&CurrentTime);
  13213. 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);
  13214. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  13215. if(interLock.isGetLogGoing)
  13216. {
  13217. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  13218. isCancelUploadLog = TRUE;
  13219. interLock.isGetLogGoing = OFF;
  13220. sleep(1);
  13221. }
  13222. else
  13223. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  13224. sendGetLogConfirmation(uuid);
  13225. if(!interLock.isGetLogGoing)
  13226. {
  13227. interLock.isGetLogGoing = ON;
  13228. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  13229. sleep(1);
  13230. }
  13231. else
  13232. {
  13233. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  13234. }
  13235. return result;
  13236. }
  13237. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  13238. {
  13239. mtrace();
  13240. int result = FAIL;
  13241. json_object *GetMonitoringReport;
  13242. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  13243. GetMonitoringReport = json_tokener_parse(payload);
  13244. if(!is_error(GetMonitoringReport))
  13245. {
  13246. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  13247. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  13248. // Required data
  13249. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  13250. {
  13251. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  13252. }
  13253. // Optional data
  13254. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  13255. {
  13256. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  13257. }
  13258. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  13259. {
  13260. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  13261. {
  13262. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  13263. {
  13264. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  13265. {
  13266. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  13267. {
  13268. 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")));
  13269. }
  13270. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13271. {
  13272. 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")));
  13273. }
  13274. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13275. {
  13276. 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)
  13277. {
  13278. 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"));
  13279. }
  13280. 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)
  13281. {
  13282. 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"));
  13283. }
  13284. }
  13285. }
  13286. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  13287. {
  13288. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13289. {
  13290. 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")));
  13291. }
  13292. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13293. {
  13294. 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")));
  13295. }
  13296. }
  13297. }
  13298. }
  13299. }
  13300. }
  13301. json_object_put(GetMonitoringReport);
  13302. /*
  13303. * TODO:
  13304. * 1. Response result
  13305. */
  13306. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13307. sendGetMonitoringReportConfirmation(uuid);
  13308. return result;
  13309. }
  13310. int handleGetReportRequest(char *uuid, char *payload)
  13311. {
  13312. mtrace();
  13313. int result = FAIL;
  13314. json_object *GetReport;
  13315. DEBUG_INFO("handleGetReportRequest...\n");
  13316. GetReport = json_tokener_parse(payload);
  13317. if(!is_error(GetReport))
  13318. {
  13319. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  13320. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  13321. // Required data
  13322. if(json_object_object_get(GetReport, "requestId") != NULL)
  13323. {
  13324. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  13325. }
  13326. // Optional data
  13327. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  13328. {
  13329. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  13330. }
  13331. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  13332. {
  13333. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  13334. {
  13335. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  13336. {
  13337. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  13338. {
  13339. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  13340. {
  13341. 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")));
  13342. }
  13343. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13344. {
  13345. 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")));
  13346. }
  13347. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13348. {
  13349. 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)
  13350. {
  13351. 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"));
  13352. }
  13353. 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)
  13354. {
  13355. 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"));
  13356. }
  13357. }
  13358. }
  13359. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  13360. {
  13361. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13362. {
  13363. 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")));
  13364. }
  13365. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13366. {
  13367. 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")));
  13368. }
  13369. }
  13370. }
  13371. }
  13372. }
  13373. }
  13374. json_object_put(GetReport);
  13375. /*
  13376. * TODO:
  13377. * 1. Response result
  13378. */
  13379. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13380. sendGetReportConfirmation(uuid);
  13381. return result;
  13382. }
  13383. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  13384. {
  13385. mtrace();
  13386. int result = FAIL;
  13387. int8_t gun_index = -1;
  13388. json_object *GetTransactionStatus;
  13389. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  13390. GetTransactionStatus = json_tokener_parse(payload);
  13391. if(!is_error(GetTransactionStatus))
  13392. {
  13393. /*
  13394. * TODO:
  13395. * 1. Check transaction locate which connector
  13396. */
  13397. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  13398. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  13399. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  13400. {
  13401. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  13402. }
  13403. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  13404. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  13405. }
  13406. json_object_put(GetTransactionStatus);
  13407. sendGetTransactionStatusConfirmation(uuid, gun_index);
  13408. return result;
  13409. }
  13410. int handleGetVariablesRequest(char *uuid, char *payload)
  13411. {
  13412. mtrace();
  13413. int result = FAIL;
  13414. int isUnknownComponent = TRUE;
  13415. json_object *GetVariables;
  13416. DEBUG_INFO("handleGetVariablesRequest...\n");
  13417. GetVariables = json_tokener_parse(payload);
  13418. if(!is_error(GetVariables))
  13419. {
  13420. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  13421. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  13422. // Required data
  13423. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  13424. {
  13425. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  13426. {
  13427. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  13428. {
  13429. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  13430. {
  13431. 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")));
  13432. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  13433. }
  13434. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  13435. {
  13436. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  13437. }*/
  13438. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  13439. {
  13440. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  13441. {
  13442. 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")));
  13443. }
  13444. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  13445. {
  13446. 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")));
  13447. }
  13448. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  13449. {
  13450. 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)
  13451. {
  13452. 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"));
  13453. }
  13454. 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)
  13455. {
  13456. 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"));
  13457. }
  13458. }
  13459. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  13460. }
  13461. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  13462. {
  13463. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  13464. {
  13465. 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")));
  13466. }
  13467. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  13468. {
  13469. 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")));
  13470. }
  13471. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  13472. }
  13473. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13474. {
  13475. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  13476. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  13477. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  13478. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  13479. {
  13480. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  13481. isUnknownComponent = FALSE;
  13482. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  13483. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  13484. {
  13485. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  13486. break;
  13487. }
  13488. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13489. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  13490. {
  13491. struct sysinfo s_info;
  13492. int error = sysinfo(&s_info);
  13493. if(error != 0)
  13494. {
  13495. DEBUG_WARN("System uptime get error: %d\n", error);
  13496. }
  13497. else
  13498. {
  13499. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  13500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  13501. }
  13502. }
  13503. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13504. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  13505. {
  13506. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  13507. }
  13508. else
  13509. {
  13510. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  13511. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  13512. }
  13513. break;
  13514. }
  13515. else
  13516. {
  13517. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  13518. {
  13519. isUnknownComponent = FALSE;
  13520. }
  13521. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  13522. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  13523. }
  13524. }
  13525. if(isUnknownComponent == TRUE)
  13526. {
  13527. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  13528. }
  13529. }
  13530. }
  13531. }
  13532. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  13533. }
  13534. json_object_put(GetVariables);
  13535. return result;
  13536. }
  13537. int handleInstallCertificateRequest(char *uuid, char *payload)
  13538. {
  13539. mtrace();
  13540. int result = FAIL;
  13541. json_object *InstallCertificate;
  13542. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13543. InstallCertificate = json_tokener_parse(payload);
  13544. if(!is_error(InstallCertificate))
  13545. {
  13546. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  13547. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  13548. // Required data
  13549. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  13550. {
  13551. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13552. }
  13553. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  13554. {
  13555. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13556. }
  13557. }
  13558. json_object_put(InstallCertificate);
  13559. /*
  13560. * TODO:
  13561. * 1. Install certification preocess and response
  13562. */
  13563. if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]))
  13564. {
  13565. }
  13566. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]))
  13567. {
  13568. }
  13569. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]))
  13570. {
  13571. }
  13572. else
  13573. {
  13574. }
  13575. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13576. sendInstallCertificateConfirmation(uuid);
  13577. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13578. return result;
  13579. }
  13580. int handlePublishFirmwareRequest(char *uuid, char *payload)
  13581. {
  13582. mtrace();
  13583. int result = FAIL;
  13584. json_object *PublishFirmware;
  13585. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  13586. PublishFirmware = json_tokener_parse(payload);
  13587. if(!is_error(PublishFirmware))
  13588. {
  13589. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  13590. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  13591. // Required data
  13592. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  13593. {
  13594. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  13595. }
  13596. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  13597. {
  13598. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  13599. }
  13600. // Optional data
  13601. if(json_object_object_get(PublishFirmware, "location") != NULL)
  13602. {
  13603. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  13604. }
  13605. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  13606. {
  13607. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  13608. }
  13609. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  13610. {
  13611. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  13612. }
  13613. }
  13614. json_object_put(PublishFirmware);
  13615. /*
  13616. * TODO:
  13617. * 1. Publish firmware preocess and response
  13618. */
  13619. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13620. sendPublishFirmwareConfirmation(uuid);
  13621. return result;
  13622. }
  13623. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  13624. {
  13625. mtrace();
  13626. int result = FAIL;
  13627. int8_t connectorIdx = -1;
  13628. uint8_t tempIndex;
  13629. uint8_t isOverConnectorMax = FALSE;
  13630. uint8_t isPeriodOverMax = FALSE;
  13631. uint8_t isTxProfile = TRUE;
  13632. uint8_t isAllowStart = TRUE;
  13633. uint8_t filename[128]={0};
  13634. char cmdBuf[128];
  13635. FILE *filePtr;
  13636. json_object *RemoteStartTransaction;
  13637. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  13638. RemoteStartTransaction = json_tokener_parse(payload);
  13639. if(!is_error(RemoteStartTransaction))
  13640. {
  13641. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  13642. {
  13643. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  13644. {
  13645. connectorIdx = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  13646. }
  13647. else
  13648. {
  13649. isOverConnectorMax = TRUE;
  13650. DEBUG_WARN("Connector id shall not equal 0 and less than max connector id.\n");
  13651. }
  13652. }
  13653. else
  13654. {
  13655. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13656. {
  13657. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  13658. {
  13659. connectorIdx = (idx+1);
  13660. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdx);
  13661. break;
  13662. }
  13663. }
  13664. }
  13665. if(isOverConnectorMax == FALSE)
  13666. {
  13667. if(connectorIdx > 0)
  13668. {
  13669. DEBUG_INFO("Connector id: %d\n", connectorIdx);
  13670. memset(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1], 0, sizeof(struct RequestStartTransaction_20));
  13671. memcpy(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid));
  13672. // Required data
  13673. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13674. {
  13675. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13676. }
  13677. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13678. {
  13679. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13680. {
  13681. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13682. }
  13683. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13684. {
  13685. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13686. }
  13687. }
  13688. // Optional data
  13689. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13690. {
  13691. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13692. {
  13693. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13694. }
  13695. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13696. {
  13697. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13698. }
  13699. }
  13700. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13701. {
  13702. // Check periods is over max configuration
  13703. 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))
  13704. {
  13705. isPeriodOverMax = TRUE;
  13706. }
  13707. // Check profile purpose is TxProfile
  13708. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13709. {
  13710. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13711. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13712. }
  13713. else
  13714. {
  13715. isTxProfile = FALSE;
  13716. }
  13717. }
  13718. //check Transaction active
  13719. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  13720. {
  13721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13722. {
  13723. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13724. }
  13725. else
  13726. {
  13727. tempIndex = (connectorIdx-1);
  13728. }
  13729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13730. {
  13731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  13732. {
  13733. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13734. {
  13735. //Reserved
  13736. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  13737. }
  13738. 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[connectorIdx-1].idToken.idToken) != 0))
  13739. {
  13740. //Reserved
  13741. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  13742. isAllowStart = FALSE;
  13743. }
  13744. else
  13745. {
  13746. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13747. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  13748. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  13749. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  13750. {
  13751. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  13752. isAllowStart = FALSE;
  13753. }
  13754. }//END FOR ELSE
  13755. }
  13756. }// END FOR CHAdeMO_QUANTITY
  13757. }
  13758. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  13759. {
  13760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13761. {
  13762. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13763. }
  13764. else
  13765. {
  13766. tempIndex = (connectorIdx-1);
  13767. }
  13768. for (int index = 0; index < CCS_QUANTITY; index++)
  13769. {
  13770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13771. {
  13772. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13773. {
  13774. //Reserved
  13775. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  13776. }
  13777. 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[connectorIdx-1].idToken.idToken) != 0))
  13778. {
  13779. //Reserved
  13780. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  13781. isAllowStart = FALSE;
  13782. }
  13783. else
  13784. {
  13785. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13786. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13787. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13788. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13789. {
  13790. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  13791. isAllowStart = FALSE;
  13792. }
  13793. }// END FOR ELSE
  13794. }
  13795. }// END FOR CCS_QUANTITY
  13796. }
  13797. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  13798. {
  13799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13800. {
  13801. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13802. }
  13803. else
  13804. {
  13805. tempIndex = (connectorIdx-1);
  13806. }
  13807. for (int index = 0; index < GB_QUANTITY; index++)
  13808. {
  13809. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  13810. {
  13811. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13812. {
  13813. //Reserved
  13814. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  13815. }
  13816. 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[connectorIdx-1].idToken.idToken) != 0))
  13817. {
  13818. //Reserved
  13819. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  13820. isAllowStart = FALSE;
  13821. }
  13822. else
  13823. {
  13824. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13825. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13826. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13827. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13828. {
  13829. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  13830. isAllowStart = FALSE;
  13831. }
  13832. }// END FOR ELSE
  13833. }
  13834. } // END FOR GB_QUANTITY
  13835. }
  13836. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  13837. {
  13838. tempIndex = (connectorIdx-1);
  13839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13840. {
  13841. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  13842. {
  13843. 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[connectorIdx-1].idToken.idToken) == 0))
  13844. {
  13845. //Reserved
  13846. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  13847. }
  13848. 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[connectorIdx-1].idToken.idToken) != 0))
  13849. {
  13850. //Reserved
  13851. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  13852. isAllowStart = FALSE;
  13853. }
  13854. else
  13855. {
  13856. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13857. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13858. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13859. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13860. {
  13861. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  13862. isAllowStart = FALSE;
  13863. }
  13864. }// END FOR ELSE
  13865. }
  13866. } // END FOR GB_QUANTITY
  13867. }
  13868. else
  13869. {
  13870. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13871. {
  13872. tempIndex = 2;
  13873. }
  13874. else
  13875. {
  13876. tempIndex = (connectorIdx-1);
  13877. }
  13878. for (int index = 0; index < AC_QUANTITY; index++)
  13879. {
  13880. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  13881. {
  13882. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13883. {
  13884. //Reserved
  13885. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  13886. }
  13887. 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[connectorIdx-1].idToken.idToken) != 0))
  13888. {
  13889. //Reserved
  13890. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  13891. isAllowStart = FALSE;
  13892. }
  13893. else
  13894. {
  13895. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13896. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13897. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13898. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13899. {
  13900. DEBUG_WARN("AC connector not allow start cause busy.\n");
  13901. isAllowStart = FALSE;
  13902. }
  13903. }//END FOR ELSE
  13904. }
  13905. }// END FOR AC_QUANTITY
  13906. }
  13907. }
  13908. else
  13909. {
  13910. DEBUG_INFO("Connector id does not specific.\n");
  13911. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13912. {
  13913. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  13914. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  13915. // Required data
  13916. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13917. {
  13918. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13919. }
  13920. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13921. {
  13922. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13923. {
  13924. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13925. }
  13926. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13927. {
  13928. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13929. }
  13930. }
  13931. // Optional data
  13932. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13933. {
  13934. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13935. {
  13936. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13937. }
  13938. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13939. {
  13940. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13941. }
  13942. }
  13943. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13944. {
  13945. // Check periods is over max configuration
  13946. 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))
  13947. {
  13948. isPeriodOverMax = TRUE;
  13949. }
  13950. // Check profile purpose is TxProfile
  13951. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13952. {
  13953. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13954. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  13955. }
  13956. else
  13957. {
  13958. isTxProfile = FALSE;
  13959. }
  13960. }
  13961. }
  13962. }
  13963. }
  13964. // Profile replace or add info
  13965. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  13966. {
  13967. if(connectorIdx != -1)
  13968. {
  13969. if(strlen((char*)filename) > 0)
  13970. {
  13971. // Save profile to file
  13972. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13973. system(cmdBuf);
  13974. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", connectorIdx);
  13975. filePtr = fopen((char*)filename, "w");
  13976. fprintf(filePtr, "{\"evseId\":%d,\"chargingProfile\":%s}\n", connectorIdx, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  13977. fclose(filePtr);
  13978. }
  13979. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  13980. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  13981. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
  13982. result = PASS;
  13983. }
  13984. else
  13985. {
  13986. uint8_t isHasIdleConnector = FALSE;
  13987. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13988. {
  13989. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  13990. {
  13991. isHasIdleConnector = TRUE;
  13992. break;
  13993. }
  13994. }
  13995. if(isHasIdleConnector == TRUE)
  13996. {
  13997. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  13998. if(strlen((char*)filename) > 0)
  13999. {
  14000. // Save profile to file
  14001. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14002. system(cmdBuf);
  14003. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  14004. filePtr = fopen((char*)filename, "w");
  14005. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14006. fclose(filePtr);
  14007. }
  14008. refreshStartTimer(&clientTime.RemoteStartWait);
  14009. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  14010. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14011. {
  14012. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14013. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  14014. }
  14015. result = PASS;
  14016. }
  14017. else
  14018. {
  14019. DEBUG_INFO("There is not any connector is idle.\n");
  14020. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14021. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14022. }
  14023. }
  14024. }
  14025. else
  14026. {
  14027. if(isOverConnectorMax != FALSE)
  14028. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  14029. if(isPeriodOverMax)
  14030. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14031. if(!isTxProfile)
  14032. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  14033. if(!isAllowStart)
  14034. DEBUG_WARN("Target connector does not allow start.\n");
  14035. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((connectorIdx-1)<0?0:(connectorIdx-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  14036. }
  14037. }
  14038. json_object_put(RemoteStartTransaction);
  14039. sendRemoteStartTransactionConfirmation(uuid, ((connectorIdx-1)<0?0:(connectorIdx-1)));
  14040. return result;
  14041. }
  14042. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  14043. {
  14044. mtrace();
  14045. int result = FAIL;
  14046. int match = FALSE;
  14047. int GunNO = 0;
  14048. int tempIndex = 0;
  14049. char transactionIdStr[37];
  14050. int transactionIdIsNULL= TRUE;
  14051. json_object *RemoteStopTransaction;
  14052. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  14053. if(server_pending == TRUE)
  14054. {
  14055. return 0;
  14056. }
  14057. RemoteStopTransaction = json_tokener_parse(payload);
  14058. if(!is_error(RemoteStopTransaction))
  14059. {
  14060. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  14061. {
  14062. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  14063. transactionIdIsNULL = FALSE;
  14064. }
  14065. }
  14066. json_object_put(RemoteStopTransaction);
  14067. if(transactionIdIsNULL == FALSE)
  14068. {
  14069. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14070. {
  14071. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  14072. {
  14073. //check Transaction active
  14074. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14075. {
  14076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14077. {
  14078. tempIndex = ((gun_index==2) ? 1: 0);
  14079. }
  14080. else
  14081. {
  14082. tempIndex = gun_index;
  14083. }
  14084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14085. {
  14086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14087. {
  14088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14089. {
  14090. match = TRUE;
  14091. GunNO = gun_index;
  14092. }
  14093. }
  14094. }// END FOR CHAdeMO_QUANTITY
  14095. }
  14096. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14097. {
  14098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14099. {
  14100. tempIndex = ((gun_index==2) ? 1: 0);
  14101. }
  14102. else
  14103. {
  14104. tempIndex = gun_index;
  14105. }
  14106. for (int index = 0; index < CCS_QUANTITY; index++)
  14107. {
  14108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14109. {
  14110. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14111. {
  14112. match = TRUE;
  14113. GunNO = gun_index;
  14114. }
  14115. }
  14116. }// END FOR CCS_QUANTITY
  14117. }
  14118. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14119. {
  14120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14121. {
  14122. tempIndex = ((gun_index==2) ? 1: 0);
  14123. }
  14124. else
  14125. {
  14126. tempIndex = gun_index;
  14127. }
  14128. for (int index = 0; index < GB_QUANTITY; index++)
  14129. {
  14130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14131. {
  14132. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14133. {
  14134. match = TRUE;
  14135. GunNO = gun_index;
  14136. }
  14137. }
  14138. }// END FOR GB_QUANTITY
  14139. }
  14140. else if(gunType[gun_index] == GUN_TYPE_DO)
  14141. {
  14142. tempIndex = gun_index;
  14143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14144. {
  14145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14146. {
  14147. 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
  14148. {
  14149. match = TRUE;
  14150. GunNO = gun_index;
  14151. }
  14152. }
  14153. }// END FOR GB_QUANTITY
  14154. }
  14155. else
  14156. {
  14157. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14158. {
  14159. tempIndex = 2;
  14160. }
  14161. else
  14162. {
  14163. tempIndex = gun_index;
  14164. }
  14165. for (int index = 0; index < AC_QUANTITY; index++)
  14166. {
  14167. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14168. {
  14169. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14170. {
  14171. match = TRUE;
  14172. GunNO = gun_index;
  14173. }
  14174. }
  14175. }// END FOR CHAdeMO_QUANTITY
  14176. } // END FOR AC ELSE
  14177. }// CHECK IF ResponseTransactionId == transactionIdInt
  14178. }//END FOR
  14179. if( match == TRUE)
  14180. {
  14181. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  14182. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14183. }
  14184. else
  14185. {
  14186. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14187. }
  14188. }
  14189. else
  14190. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14191. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  14192. return result;
  14193. }
  14194. int handleReserveNowRequest(char *uuid, char *payload)
  14195. {
  14196. mtrace();
  14197. int result = FAIL;
  14198. int connectorIdInt=0, reservationIdInt=0;
  14199. int tempIndex = 0;
  14200. json_object *ReserveNow;
  14201. DEBUG_INFO("handleReserveNowRequest ...\n");
  14202. ReserveNow = json_tokener_parse(payload);
  14203. if(!is_error(ReserveNow))
  14204. {
  14205. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  14206. {
  14207. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14208. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  14209. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  14210. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14211. }
  14212. // Required data
  14213. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  14214. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  14215. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  14216. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  14217. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  14218. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  14219. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  14220. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  14221. // Optional data
  14222. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  14223. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  14224. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  14225. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  14226. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  14227. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  14228. result = PASS;
  14229. }
  14230. json_object_put(ReserveNow);
  14231. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14232. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  14233. {
  14234. //check Transaction active
  14235. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  14236. {
  14237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14238. {
  14239. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14240. }
  14241. else
  14242. {
  14243. tempIndex = connectorIdInt -1;
  14244. }
  14245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14246. {
  14247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14248. {
  14249. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14250. {
  14251. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14252. {
  14253. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14254. {
  14255. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  14256. {
  14257. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14258. }
  14259. else
  14260. {
  14261. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14262. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14263. }
  14264. }
  14265. 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'))
  14266. {
  14267. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14268. }
  14269. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14270. {
  14271. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14272. }
  14273. else
  14274. {
  14275. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14276. }
  14277. }
  14278. 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
  14279. {
  14280. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14281. }
  14282. }
  14283. else
  14284. {
  14285. //replace reservation
  14286. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14287. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14288. }
  14289. }
  14290. } // END FOR CHAdeMO_QUANTITY
  14291. }
  14292. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  14293. {
  14294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14295. {
  14296. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14297. }
  14298. else
  14299. {
  14300. tempIndex = connectorIdInt -1;
  14301. }
  14302. for (int index = 0; index < CCS_QUANTITY; index++)
  14303. {
  14304. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14305. {
  14306. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14307. {
  14308. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14309. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14310. {
  14311. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14312. {
  14313. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  14314. {
  14315. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14316. }
  14317. else
  14318. {
  14319. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14320. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14321. }
  14322. }
  14323. 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'))
  14324. {
  14325. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14326. }
  14327. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  14328. {
  14329. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14330. }
  14331. else
  14332. {
  14333. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14334. }
  14335. }
  14336. 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
  14337. {
  14338. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14339. }
  14340. }
  14341. else
  14342. {
  14343. //replace reservation
  14344. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14345. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14346. }
  14347. }
  14348. } // END FOR CCS_QUANTITY
  14349. }
  14350. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  14351. {
  14352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14353. {
  14354. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14355. }
  14356. else
  14357. {
  14358. tempIndex = connectorIdInt -1;
  14359. }
  14360. for (int index = 0; index < GB_QUANTITY; index++)
  14361. {
  14362. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14363. {
  14364. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14365. {
  14366. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14367. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14368. {
  14369. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14370. {
  14371. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  14372. {
  14373. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14374. }
  14375. else
  14376. {
  14377. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14378. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14379. }
  14380. }
  14381. 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'))
  14382. {
  14383. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14384. }
  14385. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14386. {
  14387. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14388. }
  14389. else
  14390. {
  14391. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14392. }
  14393. }
  14394. 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
  14395. {
  14396. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14397. }
  14398. }
  14399. else
  14400. {
  14401. //replace reservation
  14402. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14403. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14404. }
  14405. }
  14406. }// END FOR GB_QUANTITY
  14407. }
  14408. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  14409. {
  14410. tempIndex = connectorIdInt -1;
  14411. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14412. {
  14413. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14414. {
  14415. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  14416. {
  14417. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14418. 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
  14419. {
  14420. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14421. {
  14422. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  14423. {
  14424. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14425. }
  14426. else
  14427. {
  14428. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14429. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14430. }
  14431. }
  14432. 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'))
  14433. {
  14434. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14435. }
  14436. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14437. {
  14438. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14439. }
  14440. else
  14441. {
  14442. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14443. }
  14444. }
  14445. 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
  14446. {
  14447. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14448. }
  14449. }
  14450. else
  14451. {
  14452. //replace reservation
  14453. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14454. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14455. }
  14456. }
  14457. }// END FOR DO_QUANTITY
  14458. }
  14459. else
  14460. {
  14461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14462. {
  14463. tempIndex = 2;
  14464. }
  14465. else
  14466. {
  14467. tempIndex = (connectorIdInt -1);
  14468. }
  14469. for (int index = 0; index < AC_QUANTITY; index++)
  14470. {
  14471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14472. {
  14473. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14474. {
  14475. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14476. {
  14477. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14478. {
  14479. 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))
  14480. {
  14481. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14482. }
  14483. else
  14484. {
  14485. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14486. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14487. }
  14488. }
  14489. 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'))
  14490. {
  14491. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14492. }
  14493. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14494. {
  14495. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14496. }
  14497. else
  14498. {
  14499. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14500. }
  14501. }
  14502. 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
  14503. {
  14504. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14505. }
  14506. }
  14507. else
  14508. {
  14509. //replace reservation
  14510. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14511. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14512. }
  14513. }
  14514. } // END FOR AC_QUANTITY
  14515. }
  14516. }
  14517. else if(connectorIdInt == 0)
  14518. {
  14519. //check Transaction active
  14520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14521. {
  14522. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14523. {
  14524. 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'))
  14525. {
  14526. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14527. goto end;
  14528. }
  14529. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14530. {
  14531. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14532. goto end;
  14533. }
  14534. 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
  14535. {
  14536. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14537. goto end;
  14538. }
  14539. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14540. {
  14541. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14542. goto end;
  14543. }
  14544. }
  14545. }// END FOR CHAdeMO_QUANTITY
  14546. for (int index = 0; index < CCS_QUANTITY; index++)
  14547. {
  14548. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14549. {
  14550. 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'))
  14551. {
  14552. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14553. goto end;
  14554. }
  14555. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  14556. {
  14557. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14558. goto end;
  14559. }
  14560. 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
  14561. {
  14562. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14563. goto end;
  14564. }
  14565. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14566. {
  14567. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14568. goto end;
  14569. }
  14570. }
  14571. } // END FOR CCS_QUANTITY
  14572. for (int index = 0; index < GB_QUANTITY; index++)
  14573. {
  14574. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14575. {
  14576. 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'))
  14577. {
  14578. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14579. goto end;
  14580. }
  14581. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14582. {
  14583. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14584. goto end;
  14585. }
  14586. 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
  14587. {
  14588. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14589. goto end;
  14590. }
  14591. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14592. {
  14593. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14594. goto end;
  14595. }
  14596. }
  14597. } // END FOR GB_QUANTITY
  14598. for (int index = 0; index < AC_QUANTITY; index++)
  14599. {
  14600. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14601. {
  14602. 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'))
  14603. {
  14604. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14605. goto end;
  14606. }
  14607. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14608. {
  14609. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14610. goto end;
  14611. }
  14612. 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
  14613. {
  14614. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14615. goto end;
  14616. }
  14617. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14618. {
  14619. 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))
  14620. {
  14621. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14622. goto end;
  14623. }
  14624. }
  14625. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14626. {
  14627. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14628. goto end;
  14629. }
  14630. }
  14631. }// END FOR AC_QUANTITY
  14632. //The connectorId is 0
  14633. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  14634. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14635. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  14636. result = TRUE;
  14637. return result;
  14638. }
  14639. else
  14640. {
  14641. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14642. }
  14643. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  14644. {
  14645. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  14646. result = TRUE;
  14647. return result;
  14648. }
  14649. end:
  14650. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  14651. return result;
  14652. }
  14653. int handleResetRequest(char *uuid, char *payload)
  14654. {
  14655. mtrace();
  14656. int result = FAIL;
  14657. json_object *Reset = json_object_new_object();
  14658. DEBUG_INFO("handleResetRequest...\n");
  14659. Reset = json_tokener_parse(payload);
  14660. if(!is_error(Reset))
  14661. {
  14662. // Required data
  14663. if(json_object_object_get(Reset, "type") != NULL)
  14664. {
  14665. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  14666. }
  14667. if(json_object_object_get(Reset, "evseId") != NULL)
  14668. {
  14669. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  14670. }
  14671. }
  14672. json_object_put(Reset);
  14673. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  14674. {
  14675. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  14676. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  14677. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  14678. result = PASS;
  14679. }
  14680. else
  14681. {
  14682. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  14683. }
  14684. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  14685. sendResetConfirmation(uuid);
  14686. return result;
  14687. }
  14688. int handleSendLocalListRequest(char *uuid, char *payload)
  14689. {
  14690. mtrace();
  14691. int result = FAIL;
  14692. int checkState_Faulted = FALSE;
  14693. json_object *SendLocalList;
  14694. DEBUG_INFO("handleSendLocalListRequest...\n");
  14695. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  14696. {
  14697. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14698. goto end;
  14699. }
  14700. SendLocalList = json_tokener_parse(payload);
  14701. if(!is_error(SendLocalList))
  14702. {
  14703. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  14704. // Required data
  14705. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  14706. {
  14707. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  14708. }
  14709. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  14710. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  14711. // Optional data
  14712. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  14713. {
  14714. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  14715. {
  14716. // Required data
  14717. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  14718. {
  14719. 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")));
  14720. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.type, "%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"), "type")));
  14721. }
  14722. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  14723. {
  14724. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.status, "%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"), "status")));
  14725. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  14726. 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")));
  14727. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  14728. 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"));
  14729. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  14730. {
  14731. 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")));
  14732. 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")));
  14733. }
  14734. }
  14735. }
  14736. }
  14737. }
  14738. json_object_put(SendLocalList);
  14739. //check Charge Point state
  14740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14741. {
  14742. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14743. {
  14744. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14745. }
  14746. }
  14747. for (int index = 0; index < CCS_QUANTITY; index++)
  14748. {
  14749. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14750. {
  14751. checkState_Faulted = TRUE; //OCPP Status
  14752. }
  14753. }
  14754. for (int index = 0; index < GB_QUANTITY; index++)
  14755. {
  14756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14757. {
  14758. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14759. }
  14760. }
  14761. for (int index = 0; index < AC_QUANTITY; index++)
  14762. {
  14763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14764. {
  14765. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14766. }
  14767. }
  14768. if(checkState_Faulted == TRUE)
  14769. {
  14770. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14771. goto end;
  14772. }
  14773. // Check update type
  14774. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  14775. {
  14776. //Local list full update
  14777. DEBUG_INFO("Local list full update.\n");
  14778. DB_getListVerion();
  14779. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14780. {
  14781. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14782. goto end;
  14783. }*/
  14784. DB_cleanLocalList();
  14785. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14786. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14787. }
  14788. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  14789. {
  14790. //Local list different update
  14791. DEBUG_INFO("Local list different update.\n");
  14792. DB_getListVerion();
  14793. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14794. {
  14795. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  14796. goto end;
  14797. }
  14798. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14799. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14800. }
  14801. else
  14802. {
  14803. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14804. goto end;
  14805. }
  14806. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  14807. end:
  14808. sendSendLocalListConfirmation(uuid);
  14809. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14810. return result;
  14811. }
  14812. int handleSetChargingProfileRequest(char *uuid, char *payload)
  14813. {
  14814. mtrace();
  14815. int result = FAIL;
  14816. struct SetChargingProfile_20 SetProfileReq = {0};
  14817. uint8_t isLostConnectorId = FALSE;
  14818. uint8_t isPeriodOverMax = FALSE;
  14819. uint8_t isStackOverMax = FALSE;
  14820. uint8_t isProfileOverMax = FALSE;
  14821. uint8_t isConnectorMismatch = FALSE;
  14822. uint8_t isTransactiodIdMismatch = FALSE;
  14823. uint8_t isInvalidLimit = FALSE;
  14824. uint8_t isWrongFormat = FALSE;
  14825. uint8_t replaceableProfileCnt = 0;
  14826. uint8_t existProfileQuantity = 0;
  14827. uint8_t filename[128]={0};
  14828. uint8_t dataLine[4096]={0};
  14829. FILE *filePtr;
  14830. json_object *SetChargingProfile;
  14831. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  14832. SetChargingProfile = json_tokener_parse(payload);
  14833. if(!is_error(SetChargingProfile))
  14834. {
  14835. // Required data
  14836. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  14837. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  14838. else
  14839. isLostConnectorId = TRUE;
  14840. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  14841. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  14842. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  14843. {
  14844. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  14845. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  14846. {
  14847. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  14848. }
  14849. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  14850. {
  14851. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  14852. }
  14853. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  14854. {
  14855. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  14856. }
  14857. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  14858. {
  14859. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  14860. }
  14861. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  14862. {
  14863. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  14864. }
  14865. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  14866. {
  14867. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  14868. }
  14869. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  14870. {
  14871. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  14872. }
  14873. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  14874. {
  14875. int chargingScheduleCount = 0;
  14876. int chargingSchedulePeriodCount = 0;
  14877. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  14878. {
  14879. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  14880. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  14881. {
  14882. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  14883. {
  14884. 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")));
  14885. }
  14886. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  14887. {
  14888. 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"));
  14889. }
  14890. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  14891. {
  14892. 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"));
  14893. }
  14894. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  14895. {
  14896. 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")));
  14897. }
  14898. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  14899. {
  14900. 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"));
  14901. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  14902. {
  14903. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  14904. {
  14905. 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)
  14906. {
  14907. 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"));
  14908. }
  14909. 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)
  14910. {
  14911. 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"));
  14912. }
  14913. 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)
  14914. {
  14915. 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"));
  14916. }
  14917. 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)
  14918. {
  14919. 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"));
  14920. }
  14921. // Check invalid limit
  14922. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  14923. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  14924. {
  14925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  14926. {
  14927. 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)))) ||
  14928. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  14929. {
  14930. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  14931. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  14932. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  14933. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  14934. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  14935. isInvalidLimit = TRUE;
  14936. }
  14937. }
  14938. else
  14939. {
  14940. 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) ||
  14941. (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)))
  14942. {
  14943. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  14944. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  14945. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  14946. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  14947. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  14948. isInvalidLimit = TRUE;
  14949. }
  14950. }
  14951. }
  14952. }
  14953. }
  14954. else
  14955. {
  14956. isPeriodOverMax = TRUE;
  14957. }
  14958. }
  14959. }
  14960. }
  14961. else
  14962. {
  14963. isWrongFormat = TRUE;
  14964. }
  14965. }
  14966. // Check periods is over max configuration
  14967. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  14968. {
  14969. if(SetProfileReq.evseId == 0)
  14970. {
  14971. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  14972. filePtr = fopen((char*)filename, "r");
  14973. if (!filePtr)
  14974. {
  14975. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  14976. filePtr = fopen((char*)filename, "w+");
  14977. }
  14978. else
  14979. {
  14980. //Check Charging Profile Count
  14981. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  14982. char *line = NULL;
  14983. size_t len = 0;
  14984. while(getline(&line, &len, filePtr) != -1)
  14985. {
  14986. json_object *obj = NULL;
  14987. obj = json_tokener_parse(line);
  14988. if(is_error(obj))
  14989. {
  14990. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  14991. }
  14992. else
  14993. {
  14994. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  14995. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  14996. {
  14997. existProfileQuantity += 1;
  14998. }
  14999. else
  15000. replaceableProfileCnt += 1;
  15001. }
  15002. //DEBUG_INFO("word=%s\n",word);
  15003. /*if(strstr((char*)dataLine, "id")!= NULL)
  15004. {
  15005. existProfileQuantity += 1;
  15006. }*/
  15007. }
  15008. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15009. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15010. {
  15011. isStackOverMax = TRUE;
  15012. }
  15013. }
  15014. fclose(filePtr);
  15015. }
  15016. else
  15017. isConnectorMismatch = TRUE;
  15018. }
  15019. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  15020. {
  15021. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  15022. isConnectorMismatch = TRUE;
  15023. if(!isConnectorMismatch)
  15024. {
  15025. if(SetProfileReq.evseId == 0)
  15026. {
  15027. int tmpExistProfileQuantity;
  15028. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  15029. {
  15030. tmpExistProfileQuantity = 0;
  15031. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15032. filePtr = fopen((char*)filename, "r");
  15033. if (!filePtr)
  15034. {
  15035. DEBUG_INFO("%s not exist, create it.\n", filename);
  15036. filePtr = fopen((char*)filename, "w+");
  15037. }
  15038. else
  15039. {
  15040. //Check Charging Profile Count
  15041. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15042. char *line = NULL;
  15043. size_t len = 0;
  15044. while(getline(&line, &len, filePtr) != -1)
  15045. {
  15046. json_object *obj = NULL;
  15047. obj = json_tokener_parse(line);
  15048. if(is_error(obj))
  15049. {
  15050. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15051. }
  15052. else
  15053. {
  15054. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15055. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15056. {
  15057. tmpExistProfileQuantity += 1;
  15058. }
  15059. else
  15060. replaceableProfileCnt += 1;
  15061. }
  15062. //DEBUG_INFO("word=%s\n",word);
  15063. /*if(strstr((char*)dataLine, "id")!= NULL)
  15064. {
  15065. tmpExistProfileQuantity += 1;
  15066. }*/
  15067. }
  15068. }
  15069. fclose(filePtr);
  15070. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15071. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15072. {
  15073. isStackOverMax = TRUE;
  15074. }
  15075. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  15076. }
  15077. }
  15078. else
  15079. {
  15080. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15081. filePtr = fopen((char*)filename, "r");
  15082. if (!filePtr)
  15083. {
  15084. DEBUG_INFO("%s not exist, create it.\n", filename);
  15085. filePtr = fopen((char*)filename, "w+");
  15086. }
  15087. else
  15088. {
  15089. //Check Charging Profile Count
  15090. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15091. char *line = NULL;
  15092. size_t len = 0;
  15093. while(getline(&line, &len, filePtr) != -1)
  15094. {
  15095. json_object *obj = NULL;
  15096. obj = json_tokener_parse(line);
  15097. if(is_error(obj))
  15098. {
  15099. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  15100. }
  15101. else
  15102. {
  15103. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15104. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15105. {
  15106. existProfileQuantity += 1;
  15107. }
  15108. else
  15109. replaceableProfileCnt += 1;
  15110. }
  15111. //DEBUG_INFO("word=%s\n",word);
  15112. /*if(strstr((char*)dataLine, "id")!= NULL)
  15113. {
  15114. existProfileQuantity += 1;
  15115. }*/
  15116. }
  15117. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15118. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15119. {
  15120. isStackOverMax = TRUE;
  15121. }
  15122. }
  15123. fclose(filePtr);
  15124. }
  15125. }
  15126. }
  15127. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15128. {
  15129. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  15130. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15131. else
  15132. isConnectorMismatch = TRUE;
  15133. if(!isConnectorMismatch)
  15134. {
  15135. filePtr = fopen((char*)filename, "r");
  15136. if (!filePtr)
  15137. {
  15138. DEBUG_INFO("%s not exist, create it.\n", filename);
  15139. filePtr = fopen((char*)filename, "w+");
  15140. }
  15141. else
  15142. {
  15143. //Check Charging Profile Count
  15144. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15145. char *line = NULL;
  15146. size_t len = 0;
  15147. while(getline(&line, &len, filePtr) != -1)
  15148. {
  15149. json_object *obj = NULL;
  15150. obj = json_tokener_parse(line);
  15151. if(is_error(obj))
  15152. {
  15153. DEBUG_ERROR("Parse TxProfile from file error.\n");
  15154. }
  15155. else
  15156. {
  15157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15159. {
  15160. existProfileQuantity += 1;
  15161. }
  15162. else
  15163. replaceableProfileCnt += 1;
  15164. }
  15165. //DEBUG_INFO("word=%s\n",word);
  15166. /*if(strstr((char*)dataLine, "id")!= NULL)
  15167. {
  15168. existProfileQuantity += 1;
  15169. }*/
  15170. }
  15171. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15172. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15173. {
  15174. isStackOverMax = TRUE;
  15175. }
  15176. }
  15177. fclose(filePtr);
  15178. if(SetProfileReq.chargingProfile.transactionId != ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId)
  15179. isTransactiodIdMismatch = TRUE;
  15180. }
  15181. }
  15182. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  15183. {
  15184. /*
  15185. * TODO:
  15186. *
  15187. */
  15188. }
  15189. else
  15190. {}
  15191. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  15192. {
  15193. FILE *fp;
  15194. char dataLine[4096]={0};
  15195. char fnametemp[128]={0};
  15196. int tmpProfileQuantity;
  15197. //Check ChargePointMaxProfile.json exit
  15198. existProfileQuantity = 0;
  15199. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  15200. {
  15201. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  15202. //Check Charging Profile Count
  15203. tmpProfileQuantity = 0;
  15204. while(fscanf(fp, "%s", dataLine) != EOF)
  15205. {
  15206. if(strstr(dataLine, "id")!= NULL)
  15207. {
  15208. existProfileQuantity += 1;
  15209. tmpProfileQuantity += 1;
  15210. }
  15211. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15212. }
  15213. fclose(fp);
  15214. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  15215. }
  15216. //Check TxDefaultProfile_%d.json
  15217. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15218. {
  15219. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15220. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15221. if((access(fnametemp,F_OK))!=-1)
  15222. {
  15223. fp = fopen(fnametemp, "r");
  15224. //Check Charging Profile Count
  15225. tmpProfileQuantity = 0;
  15226. while(fscanf(fp, "%s", dataLine) != EOF)
  15227. {
  15228. //DEBUG_INFO("word=%s\n",word);
  15229. if(strstr(dataLine, "id")!= NULL)
  15230. {
  15231. existProfileQuantity += 1;
  15232. tmpProfileQuantity += 1;
  15233. }
  15234. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15235. }
  15236. fclose(fp);
  15237. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15238. }
  15239. }
  15240. //Check TxProfile_%d.json
  15241. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15242. {
  15243. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15244. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  15245. if((access(fnametemp,F_OK))!=-1)
  15246. {
  15247. fp = fopen(fnametemp, "r");
  15248. //Check Charging Profile Count
  15249. tmpProfileQuantity = 0;
  15250. while(fscanf(fp, "%s", dataLine) != EOF)
  15251. {
  15252. if(strstr(dataLine, "id")!= NULL)
  15253. {
  15254. existProfileQuantity += 1;
  15255. tmpProfileQuantity += 1;
  15256. }
  15257. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15258. }
  15259. fclose(fp);
  15260. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15261. }
  15262. }
  15263. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  15264. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  15265. // To check total Profile quantity
  15266. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  15267. {
  15268. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15269. isProfileOverMax = TRUE;
  15270. }
  15271. else
  15272. {
  15273. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15274. isProfileOverMax = TRUE;
  15275. }
  15276. }
  15277. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  15278. }
  15279. // Profile replace or add info
  15280. if(!isLostConnectorId && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  15281. {
  15282. FILE *infile;
  15283. FILE *outfile;
  15284. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  15285. char rmFileCmd[128];
  15286. int tempchargingProfileIdInt;
  15287. int tempchargingProfileStackLevelInt;
  15288. int chkChar;
  15289. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  15290. {
  15291. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  15292. {
  15293. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  15294. }
  15295. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  15296. {
  15297. if(SetProfileReq.evseId==0)
  15298. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15299. else
  15300. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15301. }
  15302. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  15303. {
  15304. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15305. }
  15306. else
  15307. {
  15308. /*
  15309. * TODO:
  15310. *
  15311. */
  15312. }
  15313. infile = fopen ((char*)filename, "r");
  15314. outfile = fopen ((char*)tmpProfileName, "w");
  15315. chkChar = fgetc(infile);
  15316. rewind(infile);
  15317. if(chkChar == EOF)
  15318. {
  15319. // Profile is empty
  15320. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15321. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15322. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15323. fclose(infile);
  15324. fclose(outfile);
  15325. sprintf(rmFileCmd,"rm -f %s",filename);
  15326. system(rmFileCmd);
  15327. rename((char*)tmpProfileName, (char*)filename);
  15328. }
  15329. else
  15330. {
  15331. // Profile is not empty
  15332. int ChargingProfileAdded = FALSE;
  15333. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  15334. {
  15335. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  15336. json_object *tmpChargingProfile;
  15337. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  15338. if(!is_error(tmpChargingProfile))
  15339. {
  15340. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  15341. {
  15342. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  15343. {
  15344. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  15345. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  15346. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  15347. }
  15348. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15349. {
  15350. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  15351. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  15352. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  15353. }
  15354. }
  15355. }
  15356. json_object_put(tmpChargingProfile);
  15357. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  15358. {
  15359. if(ChargingProfileAdded == FALSE)
  15360. {
  15361. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15362. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15363. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15364. ChargingProfileAdded = TRUE;
  15365. }
  15366. }
  15367. else
  15368. {
  15369. fprintf(outfile,"%s\n",dataLine);
  15370. if(ChargingProfileAdded == FALSE)
  15371. {
  15372. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15373. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15374. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15375. ChargingProfileAdded = TRUE;
  15376. }
  15377. }
  15378. } // end of while loop
  15379. fclose(infile);
  15380. fclose(outfile);
  15381. sprintf(rmFileCmd,"rm -f %s",filename);
  15382. system(rmFileCmd);
  15383. rename((char*)tmpProfileName, (char*)filename);
  15384. }
  15385. }
  15386. sleep(1);
  15387. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  15388. result = PASS;
  15389. }
  15390. else
  15391. {
  15392. if(isLostConnectorId)
  15393. DEBUG_WARN("Connector id is wrong.\n");
  15394. if(isConnectorMismatch)
  15395. DEBUG_WARN("Connector id is mismatch.\n");
  15396. if(isPeriodOverMax)
  15397. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15398. if(isProfileOverMax)
  15399. DEBUG_WARN("Profile quantity is over spec.\n");
  15400. if(isTransactiodIdMismatch)
  15401. DEBUG_WARN("Transaction id is mismatch.\n");
  15402. if(isInvalidLimit)
  15403. DEBUG_WARN("Limit value is invalid.\n");
  15404. if(isStackOverMax)
  15405. DEBUG_WARN("Profile stack is over spec.\n");
  15406. if(isWrongFormat)
  15407. DEBUG_WARN("Profile format is wrong.\n");
  15408. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  15409. }
  15410. }
  15411. json_object_put(SetChargingProfile);
  15412. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  15413. {
  15414. if(SetProfileReq.evseId == 0)
  15415. {
  15416. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15417. {
  15418. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  15419. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15420. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  15421. }
  15422. }
  15423. else
  15424. {
  15425. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  15426. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15427. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  15428. }
  15429. }
  15430. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  15431. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15432. return result;
  15433. }
  15434. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  15435. {
  15436. mtrace();
  15437. int result = FAIL;
  15438. json_object *SetDisplayMessage;
  15439. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  15440. SetDisplayMessage = json_tokener_parse(payload);
  15441. if(!is_error(SetDisplayMessage))
  15442. {
  15443. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  15444. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  15445. // Required data
  15446. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  15447. {
  15448. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  15449. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  15450. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  15451. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  15452. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  15453. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  15454. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  15455. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  15456. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  15457. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  15458. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  15459. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  15460. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  15461. {
  15462. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  15463. 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")));
  15464. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  15465. 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")));
  15466. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  15467. 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")));
  15468. }
  15469. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  15470. {
  15471. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  15472. 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")));
  15473. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  15474. 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")));
  15475. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  15476. {
  15477. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  15478. 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"));
  15479. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  15480. 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"));
  15481. }
  15482. }
  15483. }
  15484. }
  15485. json_object_put(SetDisplayMessage);
  15486. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  15487. sendSetDisplayMessagesConfirmation(uuid);
  15488. // Announce CSU there is display request come from server
  15489. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  15490. return result;
  15491. }
  15492. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  15493. {
  15494. mtrace();
  15495. int result = FAIL;
  15496. json_object *SetMonitoringBase;
  15497. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  15498. SetMonitoringBase = json_tokener_parse(payload);
  15499. if(!is_error(SetMonitoringBase))
  15500. {
  15501. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  15502. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  15503. // Required data
  15504. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  15505. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  15506. }
  15507. json_object_put(SetMonitoringBase);
  15508. /*
  15509. * TODO:
  15510. * 1. Configure monitor base and response
  15511. */
  15512. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  15513. sendSetMonitoringBaseConfirmation(uuid);
  15514. return result;
  15515. }
  15516. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  15517. {
  15518. mtrace();
  15519. int result = FAIL;
  15520. json_object *SetMonitoringLevel;
  15521. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  15522. SetMonitoringLevel = json_tokener_parse(payload);
  15523. if(!is_error(SetMonitoringLevel))
  15524. {
  15525. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  15526. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  15527. // Required data
  15528. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  15529. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  15530. }
  15531. json_object_put(SetMonitoringLevel);
  15532. /*
  15533. * TODO:
  15534. * Configure monitor status and response
  15535. */
  15536. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  15537. sendSetMonitoringLevelConfirmation(uuid);
  15538. return result;
  15539. }
  15540. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  15541. {
  15542. mtrace();
  15543. int result = FAIL;
  15544. json_object *SetNetworkProfile;
  15545. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  15546. SetNetworkProfile = json_tokener_parse(payload);
  15547. if(!is_error(SetNetworkProfile))
  15548. {
  15549. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  15550. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  15551. // Required data
  15552. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  15553. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  15554. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  15555. {
  15556. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  15557. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  15558. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  15559. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  15560. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  15561. {
  15562. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  15563. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  15564. }
  15565. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  15566. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  15567. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  15568. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  15569. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  15570. {
  15571. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  15572. 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")));
  15573. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  15574. 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")));
  15575. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  15576. 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")));
  15577. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  15578. 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")));
  15579. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  15580. 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")));
  15581. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  15582. 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")));
  15583. }
  15584. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  15585. {
  15586. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  15587. {
  15588. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  15589. 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")));
  15590. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  15591. }
  15592. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  15593. {
  15594. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  15595. 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")));
  15596. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  15597. }
  15598. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  15599. {
  15600. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  15601. 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")));
  15602. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  15603. }
  15604. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  15605. 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"));
  15606. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  15607. 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")));
  15608. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  15609. 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"));
  15610. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  15611. 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")));
  15612. }
  15613. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  15614. }
  15615. }
  15616. json_object_put(SetNetworkProfile);
  15617. /*
  15618. * TODO:
  15619. * 1. Process network configuration and response
  15620. */
  15621. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  15622. {
  15623. }
  15624. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  15625. {
  15626. }
  15627. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  15628. {
  15629. }
  15630. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  15631. {
  15632. }
  15633. else
  15634. {
  15635. }
  15636. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  15637. {
  15638. }
  15639. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  15640. {
  15641. }
  15642. else
  15643. {
  15644. }
  15645. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  15646. {
  15647. }
  15648. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  15649. {
  15650. }
  15651. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  15652. {
  15653. }
  15654. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  15655. {
  15656. }
  15657. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  15658. {
  15659. }
  15660. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  15661. {
  15662. }
  15663. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  15664. {
  15665. }
  15666. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  15667. {
  15668. }
  15669. else
  15670. {
  15671. }
  15672. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  15673. {
  15674. }
  15675. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  15676. {
  15677. }
  15678. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  15679. {
  15680. }
  15681. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  15682. {
  15683. }
  15684. else
  15685. {
  15686. }
  15687. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  15688. {
  15689. }
  15690. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  15691. {
  15692. }
  15693. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  15694. {
  15695. }
  15696. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  15697. {
  15698. }
  15699. else
  15700. {
  15701. }
  15702. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  15703. sendSetNetworkProfileConfirmation(uuid);
  15704. return result;
  15705. }
  15706. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  15707. {
  15708. mtrace();
  15709. int result = FAIL;
  15710. json_object *SetVariableMonitoring;
  15711. uint8_t variableQuantity = 0;
  15712. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  15713. SetVariableMonitoring = json_tokener_parse(payload);
  15714. if(!is_error(SetVariableMonitoring))
  15715. {
  15716. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  15717. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  15718. // Required data
  15719. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  15720. {
  15721. variableQuantity++;
  15722. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  15723. {
  15724. 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"));
  15725. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  15726. }
  15727. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  15728. {
  15729. 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"));
  15730. }
  15731. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  15732. {
  15733. 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")));
  15734. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  15735. }
  15736. else
  15737. {
  15738. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  15739. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  15740. }
  15741. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  15742. {
  15743. 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"));
  15744. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  15745. }
  15746. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  15747. {
  15748. 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"));
  15749. }
  15750. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  15751. {
  15752. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  15753. {
  15754. 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")));
  15755. }
  15756. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  15757. {
  15758. 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")));
  15759. }
  15760. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  15761. {
  15762. 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)
  15763. {
  15764. 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"));
  15765. }
  15766. 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)
  15767. {
  15768. 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"));
  15769. }
  15770. }
  15771. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  15772. }
  15773. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  15774. {
  15775. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  15776. {
  15777. 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")));
  15778. }
  15779. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  15780. {
  15781. 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")));
  15782. }
  15783. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  15784. }
  15785. /*
  15786. * TODO
  15787. * Set Variables and save to DB
  15788. */
  15789. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  15790. }
  15791. }
  15792. json_object_put(SetVariableMonitoring);
  15793. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  15794. return result;
  15795. }
  15796. int handleSetVariablesRequest(char *uuid, char *payload)
  15797. {
  15798. mtrace();
  15799. int result = FAIL;
  15800. int isUnknownComponent = TRUE;
  15801. json_object *SetVariables;
  15802. DEBUG_INFO("handleSetVariablesRequest...\n");
  15803. SetVariables = json_tokener_parse(payload);
  15804. if(!is_error(SetVariables))
  15805. {
  15806. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  15807. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  15808. // Required data
  15809. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  15810. {
  15811. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  15812. {
  15813. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  15814. {
  15815. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  15816. {
  15817. 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")));
  15818. }
  15819. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  15820. {
  15821. 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")));
  15822. }
  15823. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  15824. {
  15825. 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)
  15826. {
  15827. 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"));
  15828. }
  15829. 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)
  15830. {
  15831. 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"));
  15832. }
  15833. }
  15834. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  15835. }
  15836. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  15837. {
  15838. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  15839. {
  15840. 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")));
  15841. }
  15842. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  15843. {
  15844. 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")));
  15845. }
  15846. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  15847. }
  15848. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  15849. {
  15850. 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")));
  15851. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  15852. }
  15853. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  15854. {
  15855. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  15856. }
  15857. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  15858. {
  15859. 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")));
  15860. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  15861. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  15862. {
  15863. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  15864. (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) &&
  15865. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  15866. (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))
  15867. {
  15868. isUnknownComponent = FALSE;
  15869. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  15870. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  15871. {
  15872. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  15873. break;
  15874. }
  15875. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  15876. {
  15877. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  15878. break;
  15879. }
  15880. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  15881. {
  15882. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  15883. }
  15884. else
  15885. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15886. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  15887. {
  15888. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  15889. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15890. else
  15891. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15892. }
  15893. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  15894. {
  15895. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15896. {
  15897. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15898. }
  15899. else
  15900. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  15901. }
  15902. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  15903. {
  15904. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  15905. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  15906. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  15907. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  15908. {
  15909. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "TRUE" : "FALSE");
  15910. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15911. }
  15912. }
  15913. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  15914. {
  15915. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15916. {
  15917. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15918. }
  15919. else
  15920. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15921. }
  15922. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  15923. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  15924. {
  15925. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  15926. SetOcppConnStatus(FALSE);
  15927. }
  15928. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  15929. {
  15930. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15931. {
  15932. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15933. }
  15934. else
  15935. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15936. }
  15937. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  15938. {
  15939. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15940. {
  15941. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15942. }
  15943. else
  15944. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15945. }
  15946. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  15947. {
  15948. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  15949. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  15950. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  15951. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  15952. {
  15953. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "TRUE" : "FALSE");
  15954. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  15955. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  15956. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15957. }
  15958. }
  15959. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  15960. {
  15961. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  15962. {
  15963. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15964. }
  15965. else
  15966. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15967. }
  15968. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  15969. {
  15970. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  15971. {
  15972. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15973. }
  15974. else
  15975. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15976. }
  15977. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  15978. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  15979. {
  15980. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  15981. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  15982. }
  15983. break;
  15984. }
  15985. else
  15986. {
  15987. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  15988. {
  15989. isUnknownComponent = FALSE;
  15990. }
  15991. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  15992. }
  15993. }
  15994. if(isUnknownComponent == TRUE)
  15995. {
  15996. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  15997. }
  15998. }
  15999. }
  16000. }
  16001. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  16002. }
  16003. json_object_put(SetVariables);
  16004. return result;
  16005. }
  16006. int handleTriggerMessageRequest(char *uuid, char *payload)
  16007. {
  16008. mtrace();
  16009. int result = FAIL;
  16010. int connectorIdIsNULL = FALSE;
  16011. int connectorIdInt =0;
  16012. json_object *TriggerMessage;
  16013. DEBUG_INFO("handleTriggerMessageRequest\n");
  16014. TriggerMessage = json_tokener_parse(payload);
  16015. if(!is_error(TriggerMessage))
  16016. {
  16017. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  16018. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  16019. // Required data
  16020. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  16021. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  16022. // Optional data
  16023. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  16024. {
  16025. // Required data
  16026. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  16027. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  16028. // Optional data
  16029. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  16030. {
  16031. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  16032. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  16033. }
  16034. else
  16035. connectorIdIsNULL = TRUE;
  16036. }
  16037. else
  16038. connectorIdIsNULL = TRUE;
  16039. }
  16040. json_object_put(TriggerMessage);
  16041. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  16042. {
  16043. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  16044. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  16045. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  16046. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  16047. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  16048. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  16049. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  16050. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  16051. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  16052. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  16053. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  16054. {
  16055. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  16056. sendTriggerMessageConfirmation(uuid);
  16057. return TRUE;
  16058. }
  16059. else
  16060. {
  16061. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  16062. sendTriggerMessageConfirmation(uuid);
  16063. }
  16064. }
  16065. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  16066. {
  16067. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16068. sendTriggerMessageConfirmation(uuid);
  16069. return TRUE;
  16070. }
  16071. //==========================
  16072. // Trigger message
  16073. //==========================
  16074. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  16075. {
  16076. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  16077. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  16078. {
  16079. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  16080. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16081. }
  16082. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16083. }
  16084. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  16085. {
  16086. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  16087. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  16088. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  16089. }
  16090. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  16091. {
  16092. if(server_sign)
  16093. {
  16094. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16095. sendTriggerMessageConfirmation(uuid);
  16096. return TRUE;
  16097. }
  16098. else
  16099. {
  16100. if(DB_updateBootType(BootReasonEnumType_Triggered))
  16101. server_sign = FALSE;
  16102. }
  16103. }
  16104. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  16105. {
  16106. refreshStartTimer(&clientTime.Heartbeat);
  16107. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  16108. }
  16109. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  16110. {
  16111. if(connectorIdIsNULL == FALSE)
  16112. {
  16113. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16114. {
  16115. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  16116. }
  16117. }
  16118. else
  16119. {
  16120. for(int idx=0;idx< gunTotalNumber;idx++)
  16121. {
  16122. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  16123. }
  16124. }
  16125. }
  16126. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  16127. {
  16128. if(connectorIdIsNULL == FALSE)
  16129. {
  16130. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16131. {
  16132. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  16133. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  16134. }
  16135. }
  16136. else
  16137. {
  16138. for(int idx=0;idx< gunTotalNumber;idx++)
  16139. {
  16140. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  16141. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  16142. }
  16143. }
  16144. }
  16145. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  16146. {
  16147. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16148. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16149. {
  16150. 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\" &");
  16151. }
  16152. }
  16153. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  16154. {
  16155. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16156. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16157. {
  16158. 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\" &");
  16159. }
  16160. }
  16161. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  16162. {
  16163. if(connectorIdIsNULL == FALSE)
  16164. {
  16165. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  16166. {
  16167. ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  16168. }
  16169. }
  16170. else
  16171. {
  16172. for(int idx=0;idx< gunTotalNumber;idx++)
  16173. ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  16174. }
  16175. }
  16176. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  16177. {
  16178. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16179. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16180. {
  16181. 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\" &");
  16182. }
  16183. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16184. {
  16185. 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\" &");
  16186. }
  16187. }
  16188. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  16189. {
  16190. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  16191. }
  16192. return result;
  16193. }
  16194. int handleUnlockConnectorRequest(char *uuid, char *payload)
  16195. {
  16196. mtrace();
  16197. int result = FAIL;
  16198. int connectorIdInt =0;
  16199. int tempIndex = 0;
  16200. json_object *UnlockConnector;
  16201. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  16202. UnlockConnector = json_tokener_parse(payload);
  16203. if(!is_error(UnlockConnector))
  16204. {
  16205. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  16206. {
  16207. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  16208. }
  16209. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  16210. {
  16211. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  16212. }
  16213. }
  16214. json_object_put(UnlockConnector);
  16215. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  16216. if(gunTotalNumber == 0)
  16217. {
  16218. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16219. goto end;
  16220. }
  16221. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  16222. {
  16223. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16224. goto end;
  16225. }
  16226. else
  16227. {
  16228. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  16229. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  16230. //check Transaction active
  16231. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  16232. {
  16233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16234. {
  16235. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16236. }
  16237. else
  16238. {
  16239. tempIndex = connectorIdInt -1;
  16240. }
  16241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16242. {
  16243. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  16244. {
  16245. //stop Transaction
  16246. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16247. }
  16248. }
  16249. }
  16250. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  16251. {
  16252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16253. {
  16254. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16255. }
  16256. else
  16257. {
  16258. tempIndex = connectorIdInt -1;
  16259. }
  16260. for (int index = 0; index < CCS_QUANTITY; index++)
  16261. {
  16262. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  16263. {
  16264. //stop Transaction
  16265. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16266. }
  16267. }
  16268. }
  16269. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  16270. {
  16271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16272. {
  16273. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16274. }
  16275. else
  16276. {
  16277. tempIndex = connectorIdInt -1;
  16278. }
  16279. for (int index = 0; index < GB_QUANTITY; index++)
  16280. {
  16281. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  16282. {
  16283. //stop Transaction
  16284. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16285. }
  16286. }
  16287. }
  16288. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  16289. {
  16290. tempIndex = connectorIdInt -1;
  16291. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16292. {
  16293. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  16294. {
  16295. //stop Transaction
  16296. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16297. }
  16298. }
  16299. }
  16300. else
  16301. {
  16302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16303. {
  16304. tempIndex = 2;
  16305. }
  16306. else
  16307. {
  16308. tempIndex = connectorIdInt-1;
  16309. }
  16310. for (int index = 0; index < AC_QUANTITY; index++)
  16311. {
  16312. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  16313. {
  16314. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16315. }
  16316. }
  16317. }
  16318. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  16319. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  16320. result = TRUE;
  16321. return result;
  16322. }
  16323. end:
  16324. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorConf = ON;
  16325. return result;
  16326. }
  16327. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  16328. {
  16329. mtrace();
  16330. int result = FAIL;
  16331. json_object *UnpublishFirmware;
  16332. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  16333. UnpublishFirmware = json_tokener_parse(payload);
  16334. if(!is_error(UnpublishFirmware))
  16335. {
  16336. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  16337. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  16338. // Required data
  16339. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  16340. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  16341. }
  16342. json_object_put(UnpublishFirmware);
  16343. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  16344. /*
  16345. * TODO:
  16346. * 1. Check unpublished status
  16347. */
  16348. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  16349. sendUnpublishFirmwareConfirmation(uuid);
  16350. return result;
  16351. }
  16352. static char UpdateFirmwarepayloadData[512]={0};
  16353. void *UpdateFirmwareProcess(void *data)
  16354. {
  16355. pthread_detach(pthread_self());
  16356. mtrace();
  16357. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  16358. int port=0;
  16359. int isSuccess = 0;
  16360. char ftpbuf[1024];
  16361. char temp[1024];
  16362. char * pch;
  16363. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  16364. json_object *UpdateFirmware;
  16365. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  16366. if(!is_error(UpdateFirmware))
  16367. {
  16368. // Required data
  16369. if(json_object_object_get(UpdateFirmware, "requestId"))
  16370. {
  16371. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  16372. }
  16373. if(json_object_object_get(UpdateFirmware, "firmware"))
  16374. {
  16375. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  16376. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  16377. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  16378. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  16379. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  16380. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  16381. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  16382. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  16383. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  16384. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  16385. }
  16386. // Optional data
  16387. if(json_object_object_get(UpdateFirmware, "retries"))
  16388. {
  16389. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  16390. }
  16391. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  16392. {
  16393. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  16394. }
  16395. }
  16396. json_object_put(UpdateFirmware);
  16397. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  16398. memset(path, 0, ARRAY_SIZE(path));
  16399. // Wait retrieveData
  16400. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  16401. {
  16402. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16403. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  16404. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16405. do
  16406. {
  16407. sleep(1);
  16408. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  16409. }
  16410. system("rm -f /mnt/*");
  16411. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  16412. {
  16413. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  16414. sprintf(ftppath,"/%s", path);
  16415. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  16416. DEBUG_INFO("protocol: %s\n",protocol);
  16417. DEBUG_INFO("host: %s\n",host);
  16418. DEBUG_INFO("path: %s\n",path);
  16419. DEBUG_INFO("ftppath: %s\n",ftppath);
  16420. int ftppathlen=strlen(ftppath);
  16421. int i=1;
  16422. char filenametemp[50];
  16423. while(i < ftppathlen)
  16424. {
  16425. int len=ftppathlen-i;
  16426. if(ftppath[len]== 47) // '/' ascll code: 47
  16427. {
  16428. DEBUG_INFO("compare '/' all right\n");
  16429. break;
  16430. }
  16431. i=i+1;
  16432. }
  16433. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16434. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  16435. filenametemp[i+1] = 0;
  16436. do
  16437. {
  16438. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16439. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16440. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16441. sleep(3);
  16442. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16443. if(!isSuccess)
  16444. {
  16445. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16446. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16447. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16448. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16449. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16450. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16451. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16452. }
  16453. else
  16454. {
  16455. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16456. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16457. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16458. }
  16459. ShmOCPP20Data->UpdateFirmware.retries--;
  16460. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16461. }
  16462. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  16463. {
  16464. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16465. memset(temp, 0, ARRAY_SIZE(temp));
  16466. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16467. int ftppathlen=strlen(ftpbuf);
  16468. int i=1;
  16469. char filenametemp[50];
  16470. while(i < ftppathlen)
  16471. {
  16472. int len=ftppathlen-i;
  16473. if(ftpbuf[len]== 47) // '/' ascll code: 47
  16474. {
  16475. DEBUG_INFO(" compare '/' all right\n");
  16476. break;
  16477. }
  16478. i=i+1;
  16479. }
  16480. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16481. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  16482. filenametemp[i+1] = 0;
  16483. strncpy(temp, ftpbuf, ftppathlen-i+1);
  16484. pch=strchr(temp,'@');
  16485. if(pch==NULL)
  16486. {
  16487. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16488. protocol, host, &port, path);
  16489. strcpy(user,"anonymous");
  16490. strcpy(password,"");
  16491. }
  16492. else
  16493. {
  16494. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  16495. protocol, user, password, host, &port, path);
  16496. }
  16497. sscanf(host,"%[^/]%s",host1, path1);
  16498. sprintf(ftppath,"%s", path1);
  16499. if(port == 0)
  16500. {
  16501. port = 21;
  16502. }
  16503. do
  16504. {
  16505. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16506. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16507. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16508. sleep(3);
  16509. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16510. if(!isSuccess)
  16511. {
  16512. //BulldogUtil.sleepMs(interval*1000);
  16513. DEBUG_INFO("Update firmware request and download file fail.\n");
  16514. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16515. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16516. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16517. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16518. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16519. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16520. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16521. }
  16522. else
  16523. {
  16524. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16525. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16526. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16527. }
  16528. ShmOCPP20Data->UpdateFirmware.retries--;
  16529. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16530. }
  16531. else
  16532. {
  16533. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16534. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16535. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16536. sleep(1);
  16537. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16538. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16539. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16540. }
  16541. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  16542. interLock.isUpdateFirmwareGoing = OFF;
  16543. pthread_exit(NULL);
  16544. }
  16545. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  16546. {
  16547. mtrace();
  16548. int result = FAIL;
  16549. pthread_t t;
  16550. sendUpdateFirmwareConfirmation(uuid);
  16551. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  16552. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  16553. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  16554. if(!interLock.isUpdateFirmwareGoing)
  16555. {
  16556. interLock.isUpdateFirmwareGoing = ON;
  16557. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  16558. sleep(1);
  16559. }
  16560. else
  16561. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  16562. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  16563. return result;
  16564. }
  16565. int handleUnknownRequest(char *uuid, char *payload)
  16566. {
  16567. mtrace();
  16568. int result = FAIL;
  16569. DEBUG_INFO("handleUnknownRequest...\n");
  16570. sendUnknownConfirmation(uuid);
  16571. result = PASS;
  16572. return result;
  16573. }
  16574. //==========================================
  16575. // Handle server response routine
  16576. //==========================================
  16577. void handleAuthorizeResponse(char *payload, int gun_index)
  16578. {
  16579. mtrace();
  16580. DEBUG_INFO("handleAuthorizeResponse...\n");
  16581. json_object *Authorize;
  16582. Authorize = json_tokener_parse(payload);
  16583. if(!is_error(Authorize))
  16584. {
  16585. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  16586. {
  16587. // Required data
  16588. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  16589. // Optional data
  16590. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  16591. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  16592. else
  16593. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  16594. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  16595. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  16596. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  16597. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  16598. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  16599. {
  16600. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  16601. {
  16602. 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));
  16603. }
  16604. }
  16605. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  16606. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  16607. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  16608. {
  16609. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  16610. 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")));
  16611. else
  16612. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  16613. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  16614. 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")));
  16615. }
  16616. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  16617. {
  16618. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  16619. 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")));
  16620. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  16621. 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")));
  16622. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  16623. 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")));
  16624. }
  16625. }
  16626. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  16627. {
  16628. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  16629. }
  16630. }
  16631. json_object_put(Authorize);
  16632. //Update idTag information to authorization cache if supported
  16633. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  16634. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  16635. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  16636. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  16637. {
  16638. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  16639. }
  16640. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  16641. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  16642. authorizeRetryTimes = 0;
  16643. }
  16644. void handleBootNotificationResponse(char *payload, int gun_index)
  16645. {
  16646. mtrace();
  16647. char statusStr[12]={0};
  16648. char currentTimeStr[30]={0};
  16649. int intervalInt = 0;
  16650. DEBUG_INFO("handleBootNotificationResponse...\n");
  16651. json_object *BootNotification;
  16652. BootNotification = json_tokener_parse(payload);
  16653. if(!is_error(BootNotification))
  16654. {
  16655. // Required data
  16656. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  16657. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  16658. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  16659. }
  16660. json_object_put(BootNotification);
  16661. DEBUG_INFO("statusStr: %s\n", statusStr);
  16662. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  16663. BootNotificationInterval = intervalInt;
  16664. //write back to ShmOCPP20Data->BootNotification
  16665. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  16666. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  16667. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  16668. {
  16669. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  16670. {
  16671. //Do nothing because the value is out of range.
  16672. }
  16673. else
  16674. {
  16675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  16676. HeartBeatWaitTime = intervalInt;
  16677. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  16678. }
  16679. server_sign = TRUE;
  16680. server_pending =FALSE;
  16681. DB_updateBootType(BootReasonEnumType_PowerUp);
  16682. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  16683. }
  16684. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  16685. {
  16686. server_pending = TRUE;
  16687. }
  16688. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  16689. srand(time(NULL));
  16690. refreshStartTimer(&clientTime.Heartbeat);
  16691. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  16692. SetOcppConnStatus(TRUE);
  16693. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  16694. }
  16695. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  16696. {
  16697. mtrace();
  16698. json_object *ClearedChargingLimit;
  16699. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  16700. ClearedChargingLimit = json_tokener_parse(payload);
  16701. if(!is_error(ClearedChargingLimit))
  16702. {
  16703. // Required data
  16704. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  16705. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  16706. }
  16707. json_object_put(ClearedChargingLimit);
  16708. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  16709. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  16710. }
  16711. void handleDataTransferResponse(char *payload, int gun_index)
  16712. {
  16713. mtrace();
  16714. json_object *DataTrans;
  16715. DEBUG_INFO("handleDataTransferResponse...\n");
  16716. DataTrans = json_tokener_parse(payload);
  16717. if(!is_error(DataTrans))
  16718. {
  16719. // Required data
  16720. if(json_object_object_get(DataTrans,"status") != NULL)
  16721. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  16722. // Optional data
  16723. if(json_object_object_get(DataTrans,"data") != NULL)
  16724. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  16725. }
  16726. json_object_put(DataTrans);
  16727. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  16728. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  16729. }
  16730. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  16731. {
  16732. mtrace();
  16733. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  16734. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  16735. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  16736. }
  16737. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  16738. {
  16739. mtrace();
  16740. json_object *Get15118EVCertificate;
  16741. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  16742. Get15118EVCertificate = json_tokener_parse(payload);
  16743. if(!is_error(Get15118EVCertificate))
  16744. {
  16745. // Required data
  16746. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  16747. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  16748. // Optional data
  16749. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  16750. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  16751. }
  16752. json_object_put(Get15118EVCertificate);
  16753. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  16754. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  16755. }
  16756. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  16757. {
  16758. mtrace();
  16759. json_object *GetCertificateStatus;
  16760. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  16761. GetCertificateStatus = json_tokener_parse(payload);
  16762. if(!is_error(GetCertificateStatus))
  16763. {
  16764. // Required data
  16765. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  16766. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  16767. // Optional data
  16768. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  16769. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  16770. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  16771. {
  16772. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  16773. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  16774. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  16775. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  16776. }
  16777. }
  16778. json_object_put(GetCertificateStatus);
  16779. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  16780. {
  16781. /*
  16782. * TODO:
  16783. * 1. If get certificate response accepted process something here
  16784. */
  16785. }
  16786. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  16787. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  16788. }
  16789. void handleHeartbeatResponse(char *payload, int gun_index)
  16790. {
  16791. mtrace();
  16792. DEBUG_INFO("handleHeartbeatResponse...\n");
  16793. json_object *Heartbeat;
  16794. Heartbeat = json_tokener_parse(payload);
  16795. if(!is_error(Heartbeat))
  16796. {
  16797. // Required data
  16798. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  16799. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  16800. }
  16801. json_object_put(Heartbeat);
  16802. if(FirstHeartBeat == OFF)
  16803. {
  16804. FirstHeartBeat = ON;
  16805. DEBUG_INFO("FirstHeartBeat \n");
  16806. }
  16807. HeartBeatWithNOResponse = 0;
  16808. refreshStartTimer(&clientTime.Heartbeat);
  16809. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  16810. }
  16811. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  16812. {
  16813. mtrace();
  16814. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  16815. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  16816. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  16817. }
  16818. void handleMeterValuesResponse(char *payload, int gun_index)
  16819. {
  16820. mtrace();
  16821. DEBUG_INFO("handleMeterValuesResponse...\n");
  16822. isQueueSendable = ON;
  16823. }
  16824. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  16825. {
  16826. mtrace();
  16827. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  16828. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  16829. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  16830. }
  16831. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  16832. {
  16833. mtrace();
  16834. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  16835. }
  16836. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  16837. {
  16838. mtrace();
  16839. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  16840. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  16841. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  16842. }
  16843. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  16844. {
  16845. mtrace();
  16846. json_object *NotifyEVChargingNeeds;
  16847. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  16848. NotifyEVChargingNeeds = json_tokener_parse(payload);
  16849. if(!is_error(NotifyEVChargingNeeds))
  16850. {
  16851. // Required data
  16852. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  16853. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  16854. }
  16855. json_object_put(NotifyEVChargingNeeds);
  16856. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  16857. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  16858. }
  16859. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  16860. {
  16861. mtrace();
  16862. json_object *NotifyEVChargingSchedule;
  16863. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  16864. NotifyEVChargingSchedule = json_tokener_parse(payload);
  16865. if(!is_error(NotifyEVChargingSchedule))
  16866. {
  16867. // Required data
  16868. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  16869. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  16870. }
  16871. json_object_put(NotifyEVChargingSchedule);
  16872. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  16873. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  16874. }
  16875. void handleNotifyEventResponse(char *payload, int gun_index)
  16876. {
  16877. mtrace();
  16878. DEBUG_INFO("handleNotifyEventResponse...\n");
  16879. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  16880. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  16881. }
  16882. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  16883. {
  16884. mtrace();
  16885. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  16886. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  16887. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  16888. }
  16889. void handleNotifyReportResponse(char *payload, int gun_index)
  16890. {
  16891. mtrace();
  16892. DEBUG_INFO("handleNotifyReportResponse...\n");
  16893. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  16894. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  16895. }
  16896. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  16897. {
  16898. mtrace();
  16899. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  16900. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  16901. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  16902. }
  16903. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  16904. {
  16905. mtrace();
  16906. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  16907. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  16908. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  16909. }
  16910. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  16911. {
  16912. mtrace();
  16913. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  16914. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  16915. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  16916. }
  16917. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  16918. {
  16919. mtrace();
  16920. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  16921. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  16922. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  16923. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  16924. }
  16925. void handleSignCertificateResponse(char *payload, int gun_index)
  16926. {
  16927. mtrace();
  16928. json_object *SignCertificate;
  16929. DEBUG_INFO("handleSignCertificateResponse...\n");
  16930. SignCertificate = json_tokener_parse(payload);
  16931. if(!is_error(SignCertificate))
  16932. {
  16933. // Required data
  16934. if(json_object_object_get(SignCertificate,"status") != NULL)
  16935. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  16936. // Optional data
  16937. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  16938. {
  16939. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  16940. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  16941. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  16942. }
  16943. }
  16944. json_object_put(SignCertificate);
  16945. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  16946. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  16947. }
  16948. void handleStatusNotificationResponse(char *payload, int gun_index)
  16949. {
  16950. mtrace();
  16951. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  16952. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  16953. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  16954. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  16955. }
  16956. void handleTransactionEventResponse(char *payload, int gun_index)
  16957. {
  16958. mtrace();
  16959. json_object *TransactionEven;
  16960. DEBUG_INFO("handleTransactionEventResponse...\n");
  16961. TransactionEven = json_tokener_parse(payload);
  16962. if(!is_error(TransactionEven))
  16963. {
  16964. // Required data
  16965. // Optional data
  16966. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  16967. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  16968. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  16969. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  16970. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  16971. {
  16972. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  16973. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  16974. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  16975. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  16976. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  16977. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  16978. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  16979. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  16980. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  16981. {
  16982. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  16983. 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")));
  16984. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  16985. 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")));
  16986. }
  16987. }
  16988. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  16989. {
  16990. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  16991. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  16992. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  16993. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  16994. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  16995. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  16996. }
  16997. }
  16998. json_object_put(TransactionEven);
  16999. isQueueSendable = ON;
  17000. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  17001. }
  17002. //==========================================
  17003. // Handle Error routine
  17004. //==========================================
  17005. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  17006. {
  17007. mtrace();
  17008. #ifdef SystemLogMessage
  17009. DEBUG_INFO("errorCode: %s\n", errorCode);
  17010. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  17011. DEBUG_INFO("errorDetails: %s\n", payload);
  17012. #endif
  17013. }
  17014. //===============================================
  17015. // Common routine
  17016. //===============================================
  17017. int initialConfigurationTable(void)
  17018. {
  17019. DEBUG_INFO("initialConfigurationTable...\n");
  17020. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  17021. DB_variableIsCreate();
  17022. DB_variableLoadFromDb();
  17023. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  17024. {
  17025. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  17026. DB_variableClear();
  17027. DB_variableIsCreate();
  17028. DB_variableLoadFromDb();
  17029. }
  17030. DB_getNetworkProfileFromDb();
  17031. return 0;
  17032. }
  17033. int TransactionMessageAttemptsGet(void)
  17034. {
  17035. return TransactionMessageAttemptsValue;
  17036. }
  17037. int FirstHeartBeatResponse(void)
  17038. {
  17039. return FirstHeartBeat;
  17040. }
  17041. int TransactionMessageRetryIntervalGet(void)
  17042. {
  17043. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17044. }
  17045. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17046. {
  17047. int result = TRUE;
  17048. char rmFileCmd[100]={0};
  17049. char FilePath[100]={0};
  17050. char ftpbuf[200];
  17051. int systemresult;
  17052. sprintf(FilePath,"/mnt/%s",filename);
  17053. system("ping 8.8.8.8 &");
  17054. if((access(FilePath,F_OK))!=-1)
  17055. {
  17056. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17057. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17058. system(rmFileCmd);
  17059. }
  17060. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17061. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17062. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17063. systemresult = system(ftpbuf);
  17064. if(systemresult != 0)
  17065. {
  17066. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  17067. result = FALSE;
  17068. }
  17069. system("pkill ping");
  17070. return result;
  17071. }
  17072. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17073. {
  17074. int result = TRUE;
  17075. char rmFileCmd[100]={0};
  17076. char FilePath[100]={0};
  17077. char ftpbuf[200];
  17078. int systemresult;
  17079. sprintf(FilePath,"/mnt/%s",filename);
  17080. system("ping 8.8.8.8 &");
  17081. if((access(FilePath,F_OK))!=-1)
  17082. {
  17083. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17084. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17085. system(rmFileCmd);
  17086. }
  17087. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17088. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17089. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17090. systemresult = system(ftpbuf);
  17091. if(systemresult != 0)
  17092. {
  17093. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17094. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17095. systemresult = system(ftpbuf);
  17096. if(systemresult != 0)
  17097. {
  17098. DEBUG_WARN("FTP download fail!\n");
  17099. result = FALSE;
  17100. }
  17101. }
  17102. system("pkill ping");
  17103. return result;
  17104. }
  17105. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17106. {
  17107. char rmFileCmd[100]={0};
  17108. char FilePath[100]={0};
  17109. char buf[512];
  17110. int systemresult = 0;
  17111. //DEBUG_INFO("filename=%s\n",filename);
  17112. //DEBUG_INFO("url=%s\n",url);
  17113. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17114. if((access(FilePath,F_OK))!=-1)
  17115. {
  17116. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17117. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17118. system(rmFileCmd);
  17119. }
  17120. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17121. if(fp == NULL)
  17122. {
  17123. DEBUG_INFO("log is NULL\n");
  17124. return FALSE;
  17125. }
  17126. else
  17127. {
  17128. fprintf(fp, "%s\n", url);
  17129. fprintf(fp, "%s\n", filename);
  17130. fclose(fp);
  17131. }
  17132. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17133. if(phpFP == NULL)
  17134. {
  17135. DEBUG_INFO("PHP upload fail.\n");
  17136. return FALSE;
  17137. }
  17138. else
  17139. {
  17140. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17141. {
  17142. if(strstr(buf, "result") != NULL)
  17143. {
  17144. sscanf(buf, "result: %d", &systemresult);
  17145. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17146. }
  17147. }
  17148. pclose(phpFP);
  17149. }
  17150. if(systemresult != 1)
  17151. {
  17152. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17153. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17154. if(phpFP == NULL)
  17155. {
  17156. DEBUG_WARN("PHP PUT upload fail.\n");
  17157. return FALSE;
  17158. }
  17159. else
  17160. {
  17161. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17162. {
  17163. if(strstr(buf, "result") != NULL)
  17164. {
  17165. sscanf(buf, "result: %d", &systemresult);
  17166. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17167. }
  17168. }
  17169. pclose(phpFP);
  17170. }
  17171. }
  17172. if(systemresult != 1)
  17173. {
  17174. DEBUG_WARN("PHP PUT upload fail.\n");
  17175. return FALSE;
  17176. }
  17177. return TRUE;
  17178. }
  17179. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17180. {
  17181. int result = FALSE;
  17182. char ftpbuf[200];
  17183. int systemresult;
  17184. /*
  17185. // Domaind name transfer to IP address
  17186. struct hostent* server;
  17187. char *IPbuffer;
  17188. server = gethostbyname(location);
  17189. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17190. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17191. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17192. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17193. systemresult = system(ftpbuf);
  17194. if(systemresult != 0)
  17195. {
  17196. DEBUG_INFO("ftpput error!\n");
  17197. }
  17198. else
  17199. {
  17200. result = TRUE;
  17201. DEBUG_INFO("ftpput OK!\n");
  17202. }
  17203. return result;
  17204. }
  17205. //=========================================
  17206. // Routine
  17207. //=========================================
  17208. int GetOcppServerURL()
  17209. {
  17210. int result = FALSE;
  17211. struct yuarel url;
  17212. char urlStr[512];
  17213. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17214. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17215. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17216. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  17217. {
  17218. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  17219. if(yuarel_parse(&url, urlStr) != -1)
  17220. {
  17221. sprintf(OcppProtocol, "%s", url.scheme);
  17222. sprintf(OcppHost, "%s", url.host);
  17223. if(url.path == NULL)
  17224. OcppTempPath[0] = '\0';
  17225. else
  17226. sprintf(OcppTempPath, "%s", url.path);
  17227. if(url.port == 0)
  17228. {
  17229. if(strcmp(OcppProtocol, "wss") == 0)
  17230. OcppPort = 443;
  17231. else
  17232. OcppPort = 80;
  17233. }
  17234. else
  17235. OcppPort = url.port;
  17236. result = TRUE;
  17237. }
  17238. }
  17239. else
  17240. {
  17241. strcpy(OcppHost,"");
  17242. }
  17243. return result;
  17244. }
  17245. int GetOcppPath()
  17246. {
  17247. int result = FALSE;
  17248. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17249. {
  17250. if(OcppTempPath == NULL)
  17251. {
  17252. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17253. }
  17254. else
  17255. {
  17256. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17257. }
  17258. result = TRUE;
  17259. }
  17260. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  17261. {
  17262. if(OcppTempPath == NULL)
  17263. {
  17264. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  17265. }
  17266. else
  17267. {
  17268. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  17269. }
  17270. result = TRUE;
  17271. }
  17272. else
  17273. {
  17274. strcpy(OcppPath,"");
  17275. }
  17276. return result;
  17277. }
  17278. int GetOcppPort()
  17279. {
  17280. return OcppPort;
  17281. }
  17282. int GetOcppConnStatus(void)
  17283. {
  17284. return ShmOCPP20Data->OcppConnStatus;
  17285. }
  17286. void SetOcppConnStatus(uint8_t status)
  17287. {
  17288. ShmOCPP20Data->OcppConnStatus = status;
  17289. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17290. }
  17291. int GetHeartBeatWithNOResponse(void)
  17292. {
  17293. return HeartBeatWithNOResponse;
  17294. }
  17295. void SetHeartBeatWithNOResponse(void)
  17296. {
  17297. HeartBeatWithNOResponse = 0;
  17298. }
  17299. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17300. void storeTempStopTransaction(int gun_index)
  17301. {
  17302. char TempStopTransaction[256];
  17303. char message[1024*20]={0};
  17304. char guid[37]={0};
  17305. json_object *TransactionEvent = json_object_new_object();
  17306. json_object *transactionInfo = json_object_new_object();
  17307. json_object *idToken = json_object_new_object();
  17308. json_object *evse = json_object_new_object();
  17309. json_object *meterValues = json_object_new_array();
  17310. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17311. DEBUG_INFO("storeTempStopTransaction...\n");
  17312. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  17313. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  17314. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  17315. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  17316. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  17317. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  17318. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  17319. // Message
  17320. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  17321. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  17322. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  17323. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  17324. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  17325. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  17326. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  17327. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  17328. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  17329. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  17330. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  17331. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  17332. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  17333. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  17334. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  17335. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  17336. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  17337. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  17338. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  17339. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  17340. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  17341. {
  17342. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  17343. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  17344. json_object_object_add(TransactionEvent, "idToken", idToken);
  17345. }
  17346. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  17347. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  17348. json_object_object_add(TransactionEvent, "evse", evse);
  17349. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  17350. {
  17351. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  17352. {
  17353. json_object *meterValue = json_object_new_object();
  17354. json_object *sampledValues = json_object_new_array();
  17355. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  17356. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  17357. {
  17358. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  17359. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  17360. {
  17361. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)
  17362. {
  17363. json_object *sampledValue = json_object_new_object();
  17364. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  17365. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  17366. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  17367. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  17368. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  17369. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  17370. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  17371. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  17372. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  17373. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  17374. {
  17375. json_object *unitOfMeasure = json_object_new_object();
  17376. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  17377. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  17378. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  17379. }
  17380. json_object_array_add(sampledValues, sampledValue);
  17381. }
  17382. }
  17383. }
  17384. json_object_object_add(meterValue, "sampledValue", sampledValues);
  17385. json_object_array_add(meterValues, meterValue);
  17386. }
  17387. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  17388. }
  17389. random_uuid(guid);
  17390. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  17391. , guid
  17392. , "TransactionEvent"
  17393. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  17394. json_object_put(TransactionEvent);
  17395. // open file for writing
  17396. FILE *outfile;
  17397. outfile = fopen (TempStopTransaction, "w+");
  17398. //DEBUG_INFO("data = %s\n", queuedata);
  17399. fputs(message, outfile);
  17400. fputs("\n", outfile);
  17401. fclose (outfile);
  17402. }
  17403. void checkTempStopTransaction(int gun_index)
  17404. {
  17405. FILE *fptr1;
  17406. char ch;
  17407. char str[QUEUE_MESSAGE_LENGTH]={0};
  17408. char guid[37]={0};
  17409. char tempdata[65]={0};
  17410. char TempStopTransaction[256];
  17411. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17412. fptr1 = fopen(TempStopTransaction, "r");
  17413. if (!fptr1)
  17414. {
  17415. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  17416. return ;
  17417. }
  17418. ch=fgetc(fptr1);
  17419. rewind(fptr1);
  17420. if(ch!=EOF)
  17421. {
  17422. // copy all contents to the temporary file except the specific line
  17423. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17424. {
  17425. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17426. if(str[0]=='\0')
  17427. {
  17428. break;
  17429. }
  17430. strncpy(guid, str+4, 36); //copy guid
  17431. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  17432. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17433. {
  17434. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17435. }
  17436. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17437. memset(str,0,ARRAY_SIZE(str));
  17438. }
  17439. }
  17440. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17441. fclose(fptr1);
  17442. remove(TempStopTransaction); // remove the original file
  17443. }
  17444. int GetWebSocketPingInterval(void)
  17445. {
  17446. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  17447. }
  17448. int GetServerSign(void)
  17449. {
  17450. return server_sign;
  17451. }
  17452. uint8_t GetOcppSecurityProfile()
  17453. {
  17454. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  17455. }
  17456. void GetOcppChargerBoxId(uint8_t *data)
  17457. {
  17458. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17459. }
  17460. void GetOcppSecurityPassword(uint8_t *data)
  17461. {
  17462. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  17463. }
  17464. void SetServerSign(int value)
  17465. {
  17466. server_sign = value;
  17467. }
  17468. int GetBootNotificationInterval(void)
  17469. {
  17470. return BootNotificationInterval;
  17471. }
  17472. int GetInternetConn(void)
  17473. {
  17474. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17475. }
  17476. int GetBackendConnectionTimeout(void)
  17477. {
  17478. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17479. }
  17480. int isConnectorInitMode(int gun_index)
  17481. {
  17482. int tempIndex = 0;
  17483. int result = TRUE;
  17484. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17485. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17486. {
  17487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17488. {
  17489. tempIndex = ((gun_index==2) ? 1: 0);
  17490. }
  17491. else
  17492. {
  17493. tempIndex = gun_index;
  17494. }
  17495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17496. {
  17497. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17498. {
  17499. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17500. } //end of the same index
  17501. }//end of for CHAdeMO_QUANTITY
  17502. }
  17503. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17504. {
  17505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17506. {
  17507. tempIndex = ((gun_index==2) ? 1: 0);
  17508. }
  17509. else
  17510. {
  17511. tempIndex = gun_index;
  17512. }
  17513. for (int index = 0; index < CCS_QUANTITY; index++)
  17514. {
  17515. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17516. {
  17517. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17518. } //end of the same index
  17519. } // end of for CCS_QUANTITY
  17520. }
  17521. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17522. {
  17523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17524. {
  17525. tempIndex = ((gun_index==2) ? 1: 0);
  17526. }
  17527. else
  17528. {
  17529. tempIndex = gun_index;
  17530. }
  17531. for (int index = 0; index < GB_QUANTITY; index++)
  17532. {
  17533. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17534. {
  17535. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17536. } //end of the same index
  17537. } // end of for GB_QUANTITY
  17538. }
  17539. else if(gunType[gun_index] == GUN_TYPE_DO)
  17540. {
  17541. tempIndex = gun_index;
  17542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17543. {
  17544. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17545. {
  17546. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17547. } //end of the same index
  17548. }
  17549. }
  17550. else
  17551. {
  17552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17553. {
  17554. tempIndex = 2;
  17555. }
  17556. else
  17557. {
  17558. tempIndex = gun_index;
  17559. }
  17560. for (int index = 0; index < AC_QUANTITY; index++)
  17561. {
  17562. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17563. {
  17564. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17565. }//end of the same index
  17566. }//end of for AC_QUANTITY
  17567. }
  17568. return result;
  17569. }
  17570. void refreshProcDogTimer()
  17571. {
  17572. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  17573. }
  17574. void InitialSystemValue(void)
  17575. {
  17576. localversion=0;
  17577. BootNotificationInterval = 10;
  17578. authorizeRetryTimes = 0;
  17579. GunStatusInterval = 10;
  17580. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  17581. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  17582. //Hear Beat
  17583. HeartBeatWithNOResponse = 0;
  17584. HeartBeatCountPerHour = 0;
  17585. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  17586. FirstHeartBeat = 0;
  17587. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  17588. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  17589. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17590. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17591. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17592. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17593. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17594. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17595. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17596. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17597. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17598. //Status && ConnectorPlugIn Setting
  17599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17600. {
  17601. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17602. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17603. }
  17604. for (int index = 0; index < CCS_QUANTITY; index++)
  17605. {
  17606. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17607. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17608. }
  17609. for (int index = 0; index < GB_QUANTITY; index++)
  17610. {
  17611. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17612. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17613. }
  17614. for (int index = 0; index < AC_QUANTITY; index++)
  17615. {
  17616. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17617. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17618. }
  17619. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17620. {
  17621. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17622. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17623. }
  17624. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17625. {
  17626. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  17627. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  17628. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  17629. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17630. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  17631. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  17632. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  17633. }
  17634. refreshStartTimer(&clientTime.Heartbeat);
  17635. sleep(1);
  17636. }
  17637. void LWS_Send(char *str)
  17638. {
  17639. //=====================================================
  17640. // Check InternetConn 0: disconnected, 1: connected
  17641. //====================================================
  17642. if(GetOcppConnStatus() == 0)
  17643. {
  17644. DEBUG_INFO("offline now !!!\n");
  17645. return;
  17646. }
  17647. // Only disable isWebsocketSendable operation initiated by charger
  17648. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17649. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17650. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  17651. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17652. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17653. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  17654. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  17655. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17656. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17657. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17658. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  17659. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  17660. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  17661. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  17662. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  17663. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  17664. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  17665. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  17666. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  17667. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  17668. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  17669. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17670. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17671. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17672. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  17673. {
  17674. isWebsocketSendable = OFF;
  17675. }
  17676. pthread_mutex_lock(&lock_send);
  17677. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17678. sprintf((char *)SendBuffer, "%s", str);
  17679. SendBufLen = strlen(str);
  17680. pthread_mutex_unlock(&lock_send);
  17681. lws_callback_on_writable(wsi_client);
  17682. //lws_service(context, 0);
  17683. //sleep(1);
  17684. }
  17685. void LWS_SendNow(char *str)
  17686. {
  17687. //=====================================================
  17688. // Check InternetConn 0: disconnected, 1: connected
  17689. //====================================================
  17690. if(GetOcppConnStatus() == 0)
  17691. {
  17692. DEBUG_INFO("offline now !!!\n");
  17693. return;
  17694. }
  17695. // Only disable isWebsocketSendable operation initiated by charger
  17696. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17697. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17698. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  17699. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17700. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17701. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  17702. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  17703. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17704. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17705. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17706. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  17707. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  17708. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  17709. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  17710. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  17711. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  17712. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  17713. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  17714. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  17715. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  17716. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  17717. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17718. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17719. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17720. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  17721. {
  17722. isWebsocketSendable = OFF;
  17723. }
  17724. pthread_mutex_lock(&lock_send);
  17725. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17726. sprintf((char *)SendBuffer, "%s", str);
  17727. SendBufLen = strlen(str);
  17728. pthread_mutex_unlock(&lock_send);
  17729. lws_callback_on_writable(wsi_client);
  17730. lws_service(context, 0);
  17731. //sleep(1);
  17732. }