MessageHandler.c 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315
  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=6;
  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. /* Connector Required item */
  1585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1598. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1605. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1606. /* CustomizationCtrlr Required item */
  1607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1613. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1614. /* DeviceDataCtrlr Required item */
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1622. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1630. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1638. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1646. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1649. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1654. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1657. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1662. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1670. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1678. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1679. /* DisplayMessageCtrlr Required item */
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1686. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1693. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1697. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1701. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1708. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1715. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1716. /* EVSE Required item */
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1723. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1730. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1737. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1744. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1745. /* LocalAuthListCtrlr Required item */
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1752. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1756. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1760. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1767. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  1775. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  1783. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1787. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  1791. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1792. /* MonitoringCtrlr Required item */
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1799. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1806. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1814. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1822. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1830. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1838. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1845. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1846. /* OCPPCommCtrlr Required item */
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1853. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1862. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1869. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1873. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1878. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1885. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1892. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1900. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1907. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1916. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  1925. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1932. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1936. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1941. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1948. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1955. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  1962. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "FALSE");
  1969. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  1973. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  1978. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  1979. /* ReservationCtrlr Required item */
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1986. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1993. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  2000. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2001. /* SampledDataCtrlr Required item */
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  2008. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  2015. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  2022. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2026. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2029. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2031. "Energy.Active.Import.Register,"
  2032. "Energy.Active.Import.Interval,"
  2033. "Power.Active.Import,"
  2034. "Voltage,"
  2035. "SoC");
  2036. else
  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. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2050. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2054. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2058. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2062. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2067. "Energy.Active.Import.Register,"
  2068. "Energy.Active.Import.Interval,"
  2069. "Power.Active.Import,"
  2070. "Voltage,"
  2071. "SoC,"
  2072. "Current.Offered,"
  2073. "Power.Offered");
  2074. else
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2076. "Energy.Active.Import.Register,"
  2077. "Energy.Active.Import.Interval,"
  2078. "Power.Active.Import,"
  2079. "Voltage,"
  2080. "Current.Offered");
  2081. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2086. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2090. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2091. /* SecurityCtrlr Required item */
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2095. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2099. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2103. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2107. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2114. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2118. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2122. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2129. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  2136. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2140. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2144. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2145. /* SmartChargingCtrlr Required item */
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  2152. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  2159. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  2166. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2173. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2180. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2187. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  2194. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  2201. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  2208. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2212. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2216. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2223. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2224. /* TariffCostCtrlr Required item */
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  2232. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  2240. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2244. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2248. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2256. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2264. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2268. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2272. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2276. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2280. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2281. /* TxCtrlr Required item */
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2288. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2296. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2303. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2310. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2317. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2324. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2332. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2339. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2340. }
  2341. else
  2342. {
  2343. // Variable name init
  2344. /* AlignedDataCtrlr Required item */
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2361. /* AuthCtrlrVariable Required item */
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2376. /* AuthCacheCtrlr Variable Required item */
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2387. /* ClockCtrlr Variable Required item */
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2406. /* ChargingStation Required item */
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2419. /* Connector Required item */
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2426. /* CustomizationCtrlr Required item */
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2429. /* DeviceDataCtrlr Required item */
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2452. /* DisplayMessageCtrlr Required item */
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2463. /* EVSE Required item */
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2472. /* LocalAuthListCtrlr Required item */
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2487. /* MonitoringCtrlr Required item */
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2506. /* OCPPCommCtrlr Required item */
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2544. /* ReservationCtrlr Required item */
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2551. /* SampledDataCtrlr Required item */
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2568. /* SecurityCtrlr Required item */
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2583. /* SmartChargingCtrlr Required item */
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2606. /* TariffCostCtrlr Required item */
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2625. /* TxCtrlr Required item */
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2642. }
  2643. return 0;
  2644. }
  2645. void DB_variableIsCreate()
  2646. {
  2647. char sql[512];
  2648. char* errMsg = NULL;
  2649. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2650. /* Execute SQL statement */
  2651. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2652. {
  2653. DEBUG_INFO("SQL error: %s\n", errMsg);
  2654. }
  2655. }
  2656. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2657. {
  2658. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2659. {
  2660. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2661. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2662. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2663. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2664. {
  2665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2667. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2671. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  2672. }
  2673. }
  2674. return 0;
  2675. }
  2676. void DB_variableLoadFromDb()
  2677. {
  2678. char sql[512];
  2679. char* errMsg = NULL;
  2680. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2681. /* Execute SQL statement */
  2682. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2683. {
  2684. DEBUG_INFO("SQL error: %s\n", errMsg);
  2685. }
  2686. }
  2687. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2688. {
  2689. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2690. if(columnCount > 0)
  2691. {
  2692. for(int idx=0;idx<columnCount;idx++)
  2693. {
  2694. json_object *SetNetworkProfile;
  2695. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2696. if(!is_error(SetNetworkProfile))
  2697. {
  2698. // Required data
  2699. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2700. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2701. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2702. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2703. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2704. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2705. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2706. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2707. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2708. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2709. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2710. {
  2711. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2712. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2713. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2714. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2715. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2716. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2717. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2718. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2719. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2720. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2721. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2722. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2723. }
  2724. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2725. {
  2726. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2727. {
  2728. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2729. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2730. }
  2731. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2732. {
  2733. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2734. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2735. }
  2736. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2737. {
  2738. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2739. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2740. }
  2741. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2742. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2743. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2744. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2745. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2746. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2747. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2748. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2749. }
  2750. }
  2751. json_object_put(SetNetworkProfile);
  2752. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2753. }
  2754. }
  2755. return 0;
  2756. }
  2757. void DB_getNetworkProfileFromDb()
  2758. {
  2759. char sql[512];
  2760. char* errMsg = NULL;
  2761. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2762. /* Execute SQL statement */
  2763. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2764. {
  2765. DEBUG_INFO("SQL error: %s\n", errMsg);
  2766. }
  2767. }
  2768. int DB_addNetworkProfile(int slot, char *data)
  2769. {
  2770. int result = PASS;
  2771. char sql[512];
  2772. char* errMsg = NULL;
  2773. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2774. slot,
  2775. data);
  2776. //* Execute SQL statement */
  2777. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2778. {
  2779. DEBUG_INFO("SQL error: %s\n", errMsg);
  2780. result = FAIL;
  2781. }
  2782. return result;
  2783. }
  2784. int DB_deleteNetworkProfile(int slot)
  2785. {
  2786. int result = PASS;
  2787. char sql[512];
  2788. char* errMsg = NULL;
  2789. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2790. //* Execute SQL statement */
  2791. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2792. {
  2793. DEBUG_INFO("SQL error: %s", errMsg);
  2794. result = FAIL;
  2795. }
  2796. return result;
  2797. }
  2798. int getCurrentYear()
  2799. {
  2800. int result = 0;
  2801. time_t CurrentTime;
  2802. struct tm *tm;
  2803. CurrentTime = time(NULL);
  2804. tm=localtime(&CurrentTime);
  2805. result = (tm->tm_year + 1900);
  2806. return result;
  2807. }
  2808. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2809. {
  2810. int result = PASS;
  2811. char* errMsg = NULL;
  2812. char sqlStr[8192];
  2813. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2814. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2815. {
  2816. result = FAIL;
  2817. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  2818. }
  2819. 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));
  2820. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2821. {
  2822. result = FAIL;
  2823. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  2824. }
  2825. return result;
  2826. }
  2827. //==========================================
  2828. // Check time passed since today
  2829. //==========================================
  2830. long long DiffTimebWithNow(struct timeb ST)
  2831. {
  2832. //return milli-second
  2833. struct timeb ET;
  2834. long long StartTime,StopTime;
  2835. ftime(&ET);
  2836. StartTime=(long long)ST.time;
  2837. StopTime=(long long)ET.time;
  2838. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2839. }
  2840. int getTimePassSinceToday(uint8_t gun_index)
  2841. {
  2842. int result = -1;
  2843. static time_t lastTime[4];
  2844. time_t t;
  2845. struct tm *tmStartToday;
  2846. struct timeb tbStartToday;
  2847. t=time(NULL);
  2848. if(difftime(t, lastTime[gun_index])>0)
  2849. {
  2850. tmStartToday=localtime(&t);
  2851. tmStartToday->tm_hour = 0;
  2852. tmStartToday->tm_min = 0;
  2853. tmStartToday->tm_sec = 0;
  2854. tbStartToday.time = mktime(tmStartToday);
  2855. tbStartToday.millitm = 0;
  2856. result = DiffTimebWithNow(tbStartToday)/1000;
  2857. lastTime[gun_index] = t;
  2858. }
  2859. return result;
  2860. }
  2861. int syncDateTimeRTC(uint8_t *data)
  2862. {
  2863. struct ParsingResult
  2864. {
  2865. int result;
  2866. int scanedElement;
  2867. int year;
  2868. int month;
  2869. int mday;
  2870. int hour;
  2871. int min;
  2872. int sec;
  2873. int tz_hour;
  2874. int tz_min;
  2875. float minSec;
  2876. }result;
  2877. struct tm tmOrg;
  2878. struct tm *tmTarget;
  2879. struct timeb tbTarget;
  2880. char buf[128];
  2881. memset(&result, 0x00, sizeof(struct ParsingResult));
  2882. result.result = PASS;
  2883. if(strstr((char*)data, ".") != NULL)
  2884. {
  2885. // Original data with mini second
  2886. if(strstr((char*)data, "Z") != NULL)
  2887. {
  2888. // Original data with Z
  2889. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2890. &result.year,
  2891. &result.month,
  2892. &result.mday,
  2893. &result.hour,
  2894. &result.min,
  2895. &result.sec,
  2896. &result.minSec);
  2897. }
  2898. else
  2899. {
  2900. // Original data without Z
  2901. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2902. &result.year,
  2903. &result.month,
  2904. &result.mday,
  2905. &result.hour,
  2906. &result.min,
  2907. &result.sec,
  2908. &result.minSec,
  2909. &result.tz_hour,
  2910. &result.tz_min);
  2911. }
  2912. }
  2913. else
  2914. {
  2915. // Original data without mini second
  2916. if(strstr((char*)data, "Z") != NULL)
  2917. {
  2918. // Original data with Z
  2919. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2920. &result.year,
  2921. &result.month,
  2922. &result.mday,
  2923. &result.hour,
  2924. &result.min,
  2925. &result.sec);
  2926. }
  2927. else
  2928. {
  2929. // Original data without Z
  2930. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2931. &result.year,
  2932. &result.month,
  2933. &result.mday,
  2934. &result.hour,
  2935. &result.min,
  2936. &result.sec,
  2937. &result.tz_hour,
  2938. &result.tz_min);
  2939. }
  2940. }
  2941. tmOrg.tm_year = result.year - 1900;
  2942. tmOrg.tm_mon = result.month - 1;
  2943. tmOrg.tm_mday = result.mday;
  2944. tmOrg.tm_hour = result.hour;
  2945. tmOrg.tm_min = result.min;
  2946. tmOrg.tm_sec = result.sec;
  2947. tmOrg.tm_gmtoff = 0;
  2948. tbTarget.time = mktime(&tmOrg);
  2949. tbTarget.timezone = 0;
  2950. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2951. tmTarget = gmtime(&tbTarget.time);
  2952. 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);
  2953. //DEBUG_INFO(" org date time: %s\n", data);
  2954. //DEBUG_INFO("parse date time: %s\n", buf);
  2955. system(buf);
  2956. system("/sbin/hwclock -w --systohc");
  2957. if(result.scanedElement < 6)
  2958. result.result = FAIL;
  2959. return result.result;
  2960. }
  2961. //==========================================
  2962. // GetCompositeSchedule logic related function
  2963. //==========================================
  2964. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2965. {
  2966. //return milli-second
  2967. unsigned int StartTime,StopTime;
  2968. StartTime=(unsigned int)ST.time;
  2969. StopTime=(unsigned int)ET.time;
  2970. return (StopTime-StartTime);
  2971. }
  2972. int DiffTimebWithNowSec(struct timeb ST)
  2973. {
  2974. //return milli-second
  2975. struct timeb ET;
  2976. unsigned int StartTime,StopTime;
  2977. ftime(&ET);
  2978. StartTime=(unsigned int)ST.time;
  2979. StopTime=(unsigned int)ET.time;
  2980. return (StopTime-StartTime);
  2981. }
  2982. int getStartStop(uint8_t *start, uint8_t *stop)
  2983. {
  2984. struct ParsingResult
  2985. {
  2986. int result;
  2987. int scanedElement;
  2988. int year;
  2989. int month;
  2990. int mday;
  2991. int hour;
  2992. int min;
  2993. int sec;
  2994. int tz_hour;
  2995. int tz_min;
  2996. float minSec;
  2997. };
  2998. struct ParsingResult parseStart;
  2999. struct ParsingResult parseStop;
  3000. int result = -1;
  3001. struct tm tmStart;
  3002. struct timeb tbStart;
  3003. struct tm tmStop;
  3004. struct timeb tbStop;
  3005. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3006. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3007. // Scan start & stop date time
  3008. if(strstr((char*)start, ".") != NULL)
  3009. {
  3010. // Original data with mini second
  3011. if(strstr((char*)start, "Z") != NULL)
  3012. {
  3013. // Original data with Z
  3014. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3015. &parseStart.year,
  3016. &parseStart.month,
  3017. &parseStart.mday,
  3018. &parseStart.hour,
  3019. &parseStart.min,
  3020. &parseStart.sec,
  3021. &parseStart.minSec);
  3022. }
  3023. else
  3024. {
  3025. // Original data without Z
  3026. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3027. &parseStart.year,
  3028. &parseStart.month,
  3029. &parseStart.mday,
  3030. &parseStart.hour,
  3031. &parseStart.min,
  3032. &parseStart.sec,
  3033. &parseStart.minSec,
  3034. &parseStart.tz_hour,
  3035. &parseStart.tz_min);
  3036. }
  3037. }
  3038. else
  3039. {
  3040. // Original data without mini second
  3041. if(strstr((char*)start, "Z") != NULL)
  3042. {
  3043. // Original data with Z
  3044. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3045. &parseStart.year,
  3046. &parseStart.month,
  3047. &parseStart.mday,
  3048. &parseStart.hour,
  3049. &parseStart.min,
  3050. &parseStart.sec);
  3051. }
  3052. else
  3053. {
  3054. // Original data without Z
  3055. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3056. &parseStart.year,
  3057. &parseStart.month,
  3058. &parseStart.mday,
  3059. &parseStart.hour,
  3060. &parseStart.min,
  3061. &parseStart.sec,
  3062. &parseStart.tz_hour,
  3063. &parseStart.tz_min);
  3064. }
  3065. }
  3066. if(strstr((char*)stop, ".") != NULL)
  3067. {
  3068. // Original data with mini second
  3069. if(strstr((char*)stop, "Z") != NULL)
  3070. {
  3071. // Original data with Z
  3072. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3073. &parseStop.year,
  3074. &parseStop.month,
  3075. &parseStop.mday,
  3076. &parseStop.hour,
  3077. &parseStop.min,
  3078. &parseStop.sec,
  3079. &parseStop.minSec);
  3080. }
  3081. else
  3082. {
  3083. // Original data without Z
  3084. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3085. &parseStop.year,
  3086. &parseStop.month,
  3087. &parseStop.mday,
  3088. &parseStop.hour,
  3089. &parseStop.min,
  3090. &parseStop.sec,
  3091. &parseStop.minSec,
  3092. &parseStop.tz_hour,
  3093. &parseStop.tz_min);
  3094. }
  3095. }
  3096. else
  3097. {
  3098. // Original data without mini second
  3099. if(strstr((char*)stop, "Z") != NULL)
  3100. {
  3101. // Original data with Z
  3102. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3103. &parseStop.year,
  3104. &parseStop.month,
  3105. &parseStop.mday,
  3106. &parseStop.hour,
  3107. &parseStop.min,
  3108. &parseStop.sec);
  3109. }
  3110. else
  3111. {
  3112. // Original data without Z
  3113. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3114. &parseStop.year,
  3115. &parseStop.month,
  3116. &parseStop.mday,
  3117. &parseStop.hour,
  3118. &parseStop.min,
  3119. &parseStop.sec,
  3120. &parseStop.tz_hour,
  3121. &parseStop.tz_min);
  3122. }
  3123. }
  3124. // Calculate date time difference
  3125. if((parseStart.scanedElement >=6) &&
  3126. (parseStop.scanedElement >=6))
  3127. {
  3128. //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);
  3129. //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);
  3130. tmStart.tm_year = parseStart.year - 1900;
  3131. tmStart.tm_mon = parseStart.month - 1;
  3132. tmStart.tm_mday = parseStart.mday;
  3133. tmStart.tm_hour = parseStart.hour;
  3134. tmStart.tm_min = parseStart.min;
  3135. tmStart.tm_sec = parseStart.sec;
  3136. tmStart.tm_gmtoff = 0;
  3137. tbStart.time = mktime(&tmStart);
  3138. tbStart.timezone = 0;
  3139. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3140. tmStop.tm_year = parseStop.year - 1900;
  3141. tmStop.tm_mon = parseStop.month - 1;
  3142. tmStop.tm_mday = parseStop.mday;
  3143. tmStop.tm_hour = parseStop.hour;
  3144. tmStop.tm_min = parseStop.min;
  3145. tmStop.tm_sec = parseStop.sec;
  3146. tmStop.tm_gmtoff = 0;
  3147. tbStop.time = mktime(&tmStop);
  3148. tbStop.timezone = 0;
  3149. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3150. result = DiffTimebSec(tbStart, tbStop);
  3151. //DEBUG_INFO("getStartStop(): %d\n", result);
  3152. }
  3153. else
  3154. {
  3155. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3156. }
  3157. return result;
  3158. }
  3159. int isOvertNow(uint8_t *start)
  3160. {
  3161. int result = NO;
  3162. struct ParsingResult
  3163. {
  3164. int result;
  3165. int scanedElement;
  3166. int year;
  3167. int month;
  3168. int mday;
  3169. int hour;
  3170. int min;
  3171. int sec;
  3172. int tz_hour;
  3173. int tz_min;
  3174. float minSec;
  3175. }parsingResult;
  3176. struct tm tmStart;
  3177. struct timeb tbStart;
  3178. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3179. if(strstr((char*)start, ".") != NULL)
  3180. {
  3181. // Original data with mini second
  3182. if(strstr((char*)start, "Z") != NULL)
  3183. {
  3184. // Original data with Z
  3185. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3186. &parsingResult.year,
  3187. &parsingResult.month,
  3188. &parsingResult.mday,
  3189. &parsingResult.hour,
  3190. &parsingResult.min,
  3191. &parsingResult.sec,
  3192. &parsingResult.minSec);
  3193. }
  3194. else
  3195. {
  3196. // Original data without Z
  3197. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3198. &parsingResult.year,
  3199. &parsingResult.month,
  3200. &parsingResult.mday,
  3201. &parsingResult.hour,
  3202. &parsingResult.min,
  3203. &parsingResult.sec,
  3204. &parsingResult.minSec,
  3205. &parsingResult.tz_hour,
  3206. &parsingResult.tz_min);
  3207. }
  3208. }
  3209. else
  3210. {
  3211. // Original data without mini second
  3212. if(strstr((char*)start, "Z") != NULL)
  3213. {
  3214. // Original data with Z
  3215. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3216. &parsingResult.year,
  3217. &parsingResult.month,
  3218. &parsingResult.mday,
  3219. &parsingResult.hour,
  3220. &parsingResult.min,
  3221. &parsingResult.sec);
  3222. }
  3223. else
  3224. {
  3225. // Original data without Z
  3226. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3227. &parsingResult.year,
  3228. &parsingResult.month,
  3229. &parsingResult.mday,
  3230. &parsingResult.hour,
  3231. &parsingResult.min,
  3232. &parsingResult.sec,
  3233. &parsingResult.tz_hour,
  3234. &parsingResult.tz_min);
  3235. }
  3236. }
  3237. if(parsingResult.scanedElement >= 6)
  3238. {
  3239. tmStart.tm_year = parsingResult.year - 1900;
  3240. tmStart.tm_mon = parsingResult.month - 1;
  3241. tmStart.tm_mday = parsingResult.mday;
  3242. tmStart.tm_hour = parsingResult.hour;
  3243. tmStart.tm_min = parsingResult.min;
  3244. tmStart.tm_sec = parsingResult.sec;
  3245. tmStart.tm_gmtoff = 0;
  3246. tbStart.time = mktime(&tmStart);
  3247. tbStart.timezone = 0;
  3248. tbStart.millitm = 0;
  3249. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3250. if(DiffTimebWithNowSec(tbStart) <= 0)
  3251. result = NO;
  3252. else
  3253. result = YES;
  3254. }
  3255. else
  3256. {
  3257. DEBUG_WARN("Start date parsing error.\n");
  3258. }
  3259. return result;
  3260. }
  3261. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3262. {
  3263. struct ParsingResult
  3264. {
  3265. int result;
  3266. int scanedElement;
  3267. int year;
  3268. int month;
  3269. int mday;
  3270. int hour;
  3271. int min;
  3272. int sec;
  3273. int tz_hour;
  3274. int tz_min;
  3275. float minSec;
  3276. };
  3277. struct ParsingResult parseStart;
  3278. struct ParsingResult parseStop;
  3279. int result = -1;
  3280. struct tm tmStart;
  3281. struct timeb tbStart;
  3282. struct tm tmStop;
  3283. struct timeb tbStop;
  3284. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3285. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3286. // Scan start & stop date time
  3287. if(strstr((char*)start, ".") != NULL)
  3288. {
  3289. // Original data with mini second
  3290. if(strstr((char*)start, "Z") != NULL)
  3291. {
  3292. // Original data with Z
  3293. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3294. &parseStart.year,
  3295. &parseStart.month,
  3296. &parseStart.mday,
  3297. &parseStart.hour,
  3298. &parseStart.min,
  3299. &parseStart.sec,
  3300. &parseStart.minSec);
  3301. }
  3302. else
  3303. {
  3304. // Original data without Z
  3305. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3306. &parseStart.year,
  3307. &parseStart.month,
  3308. &parseStart.mday,
  3309. &parseStart.hour,
  3310. &parseStart.min,
  3311. &parseStart.sec,
  3312. &parseStart.minSec,
  3313. &parseStart.tz_hour,
  3314. &parseStart.tz_min);
  3315. }
  3316. }
  3317. else
  3318. {
  3319. // Original data without mini second
  3320. if(strstr((char*)start, "Z") != NULL)
  3321. {
  3322. // Original data with Z
  3323. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3324. &parseStart.year,
  3325. &parseStart.month,
  3326. &parseStart.mday,
  3327. &parseStart.hour,
  3328. &parseStart.min,
  3329. &parseStart.sec);
  3330. }
  3331. else
  3332. {
  3333. // Original data without Z
  3334. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3335. &parseStart.year,
  3336. &parseStart.month,
  3337. &parseStart.mday,
  3338. &parseStart.hour,
  3339. &parseStart.min,
  3340. &parseStart.sec,
  3341. &parseStart.tz_hour,
  3342. &parseStart.tz_min);
  3343. }
  3344. }
  3345. if(strstr((char*)stop, ".") != NULL)
  3346. {
  3347. // Original data with mini second
  3348. if(strstr((char*)stop, "Z") != NULL)
  3349. {
  3350. // Original data with Z
  3351. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3352. &parseStop.year,
  3353. &parseStop.month,
  3354. &parseStop.mday,
  3355. &parseStop.hour,
  3356. &parseStop.min,
  3357. &parseStop.sec,
  3358. &parseStop.minSec);
  3359. }
  3360. else
  3361. {
  3362. // Original data without Z
  3363. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3364. &parseStop.year,
  3365. &parseStop.month,
  3366. &parseStop.mday,
  3367. &parseStop.hour,
  3368. &parseStop.min,
  3369. &parseStop.sec,
  3370. &parseStop.minSec,
  3371. &parseStop.tz_hour,
  3372. &parseStop.tz_min);
  3373. }
  3374. }
  3375. else
  3376. {
  3377. // Original data without mini second
  3378. if(strstr((char*)stop, "Z") != NULL)
  3379. {
  3380. // Original data with Z
  3381. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3382. &parseStop.year,
  3383. &parseStop.month,
  3384. &parseStop.mday,
  3385. &parseStop.hour,
  3386. &parseStop.min,
  3387. &parseStop.sec);
  3388. }
  3389. else
  3390. {
  3391. // Original data without Z
  3392. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3393. &parseStop.year,
  3394. &parseStop.month,
  3395. &parseStop.mday,
  3396. &parseStop.hour,
  3397. &parseStop.min,
  3398. &parseStop.sec,
  3399. &parseStop.tz_hour,
  3400. &parseStop.tz_min);
  3401. }
  3402. }
  3403. // Calculate date time difference
  3404. if((parseStart.scanedElement >=6) &&
  3405. (parseStop.scanedElement >=6))
  3406. {
  3407. //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);
  3408. //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);
  3409. tmStart.tm_year = parseStart.year - 1900;
  3410. tmStart.tm_mon = parseStart.month - 1;
  3411. tmStart.tm_mday = parseStart.mday;
  3412. tmStart.tm_hour = parseStart.hour;
  3413. tmStart.tm_min = parseStart.min;
  3414. tmStart.tm_sec = parseStart.sec;
  3415. tmStart.tm_gmtoff = 0;
  3416. tbStart.time = mktime(&tmStart);
  3417. tbStart.timezone = 0;
  3418. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3419. tmStop.tm_year = parseStop.year - 1900;
  3420. tmStop.tm_mon = parseStop.month - 1;
  3421. tmStop.tm_mday = parseStop.mday;
  3422. tmStop.tm_hour = parseStop.hour;
  3423. tmStop.tm_min = parseStop.min;
  3424. tmStop.tm_sec = parseStop.sec;
  3425. tmStop.tm_gmtoff = 0;
  3426. tbStop.time = mktime(&tmStop);
  3427. tbStop.timezone = 0;
  3428. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3429. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  3430. //DEBUG_INFO("getStartStop(): %d\n", result);
  3431. }
  3432. else
  3433. {
  3434. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3435. }
  3436. return result;
  3437. }
  3438. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3439. {
  3440. FILE *fp;
  3441. char profileFileName[128];
  3442. char *line = NULL;
  3443. size_t len = 0;
  3444. time_t CurrentTime;
  3445. struct tm *tmComposite;
  3446. struct ChargingProfileType maxProfile;
  3447. struct ChargingProfileType compositeProfile;
  3448. uint8_t limitMax=0;
  3449. int compositePeriodIdx = 0;
  3450. CurrentTime = time(NULL);
  3451. tmComposite=localtime(&CurrentTime);
  3452. 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);
  3453. if(isUnitA)
  3454. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3455. else
  3456. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3457. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3458. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3459. {
  3460. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3461. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3462. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3463. }
  3464. compositeProfile.id = 0;
  3465. compositeProfile.stackLevel = 99 ;
  3466. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  3467. maxProfile.id = -1;
  3468. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3469. system("rm -f /tmp/*.json");
  3470. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3471. // Search max profile
  3472. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  3473. if((access(profileFileName, F_OK))!=-1)
  3474. {
  3475. fp = fopen(profileFileName, "r");
  3476. while(getline(&line, &len, fp) != -1)
  3477. {
  3478. json_object *obj = NULL;
  3479. obj = json_tokener_parse(line);
  3480. if(is_error(obj))
  3481. {
  3482. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3483. }
  3484. else
  3485. {
  3486. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  3487. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  3488. )
  3489. {
  3490. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3491. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3492. )
  3493. {
  3494. struct tm tmFrom, tmTo;
  3495. struct timeb tbFrom, tbTo;
  3496. 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) &&
  3497. (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))
  3498. {
  3499. tmFrom.tm_year -= 1900;
  3500. tmFrom.tm_mon -= 1;
  3501. tbFrom.time = mktime(&tmFrom);
  3502. tmTo.tm_year -= 1900;
  3503. tmTo.tm_mon -= 1;
  3504. tbTo.time = mktime(&tmTo);
  3505. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3506. {
  3507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3508. {
  3509. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3510. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3511. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3512. }
  3513. if(maxProfile.id == -1)
  3514. DEBUG_INFO("MaxProfile found.\n");
  3515. else
  3516. DEBUG_INFO("MaxProfile updated.\n");
  3517. // Required item
  3518. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3519. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3520. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3521. if(isUnitA)
  3522. {
  3523. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3524. 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++)
  3525. {
  3526. 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"));
  3527. 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?
  3528. 3:
  3529. 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")));
  3530. 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")));
  3531. }
  3532. }
  3533. else
  3534. {
  3535. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3536. 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++)
  3537. {
  3538. 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"));
  3539. 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?
  3540. 3:
  3541. 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")));
  3542. 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));
  3543. }
  3544. }
  3545. // Optional item
  3546. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3547. {
  3548. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3549. }
  3550. else
  3551. {
  3552. sprintf((char*)maxProfile.validFrom, " ");
  3553. }
  3554. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3555. {
  3556. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3557. }
  3558. else
  3559. {
  3560. sprintf((char*)maxProfile.validTo, " ");
  3561. }
  3562. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3563. {
  3564. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3565. }
  3566. else
  3567. {
  3568. sprintf((char*)maxProfile.recurrencyKind, " ");
  3569. }
  3570. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3571. {
  3572. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3573. }
  3574. else
  3575. {
  3576. sprintf((char*)maxProfile.transactionId, " ");
  3577. }
  3578. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3579. {
  3580. 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"));
  3581. }
  3582. else
  3583. {
  3584. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3585. }
  3586. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3587. {
  3588. 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")));
  3589. }
  3590. else
  3591. {
  3592. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3593. }
  3594. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3595. {
  3596. 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"));
  3597. }
  3598. else
  3599. {
  3600. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3601. }
  3602. }
  3603. }
  3604. }
  3605. else
  3606. {
  3607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3608. {
  3609. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3610. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3611. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3612. }
  3613. if(maxProfile.id == -1)
  3614. DEBUG_INFO("MaxProfile found.\n");
  3615. else
  3616. DEBUG_INFO("MaxProfile updated.\n");
  3617. // Required item
  3618. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3619. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3620. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3621. if(isUnitA)
  3622. {
  3623. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3624. 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++)
  3625. {
  3626. 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"));
  3627. 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?
  3628. 3:
  3629. 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")));
  3630. 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")));
  3631. }
  3632. }
  3633. else
  3634. {
  3635. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3636. 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++)
  3637. {
  3638. 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"));
  3639. 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?
  3640. 3:
  3641. 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")));
  3642. 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));
  3643. }
  3644. }
  3645. // Optional item
  3646. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3647. {
  3648. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3649. }
  3650. else
  3651. {
  3652. sprintf((char*)maxProfile.validFrom, " ");
  3653. }
  3654. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3655. {
  3656. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3657. }
  3658. else
  3659. {
  3660. sprintf((char*)maxProfile.validTo, " ");
  3661. }
  3662. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3663. {
  3664. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3665. }
  3666. else
  3667. {
  3668. sprintf((char*)maxProfile.recurrencyKind, " ");
  3669. }
  3670. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3671. {
  3672. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3673. }
  3674. else
  3675. {
  3676. sprintf((char*)maxProfile.transactionId, " ");
  3677. }
  3678. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3679. {
  3680. 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"));
  3681. }
  3682. else
  3683. {
  3684. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3685. }
  3686. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3687. {
  3688. 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")));
  3689. }
  3690. else
  3691. {
  3692. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3693. }
  3694. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3695. {
  3696. 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"));
  3697. }
  3698. else
  3699. {
  3700. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3701. }
  3702. }
  3703. }
  3704. }
  3705. json_object_put(obj);
  3706. }
  3707. fclose(fp);
  3708. /*
  3709. if(maxProfile.id !=-1)
  3710. {
  3711. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3712. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3713. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3714. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3715. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3716. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3717. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3718. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3719. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3720. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3721. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3722. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3723. {
  3724. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3725. {
  3726. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3727. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3728. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3729. }
  3730. }
  3731. }
  3732. else
  3733. DEBUG_INFO("MaxProfile not found.\n");
  3734. DEBUG_INFO("------------------------------------\n");*/
  3735. }
  3736. if(maxProfile.id != -1)
  3737. {
  3738. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3739. {
  3740. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3741. {
  3742. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3743. 0:
  3744. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3745. }
  3746. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3747. {
  3748. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3749. {
  3750. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3751. 0:
  3752. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3753. if(idxPeriod > 0)
  3754. {
  3755. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3756. {
  3757. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3758. }
  3759. }
  3760. }
  3761. }
  3762. }
  3763. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3764. {
  3765. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3766. {
  3767. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3768. }
  3769. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3770. {
  3771. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3772. {
  3773. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3774. if(idxPeriod > 0)
  3775. {
  3776. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3777. {
  3778. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3779. }
  3780. }
  3781. }
  3782. }
  3783. }
  3784. else
  3785. {
  3786. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3787. {
  3788. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3789. {
  3790. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3791. 0:
  3792. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3793. }
  3794. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3795. {
  3796. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3797. {
  3798. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3799. 0:
  3800. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3801. if(idxPeriod > 0)
  3802. {
  3803. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3804. {
  3805. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3806. }
  3807. }
  3808. }
  3809. }
  3810. }
  3811. else
  3812. {
  3813. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3814. {
  3815. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3816. 0:
  3817. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3818. }
  3819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3820. {
  3821. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3822. {
  3823. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3824. 0:
  3825. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3826. if(idxPeriod > 0)
  3827. {
  3828. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3829. {
  3830. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3831. }
  3832. }
  3833. }
  3834. }
  3835. }
  3836. }
  3837. /*
  3838. DEBUG_INFO("MaxProfile after align.\n");
  3839. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3840. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3841. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3842. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3843. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3844. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3845. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3846. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3847. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3848. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3849. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3850. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3851. {
  3852. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3853. {
  3854. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3855. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3856. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3857. }
  3858. }
  3859. DEBUG_INFO("------------------------------------\n");*/
  3860. }
  3861. // Find each profile period quantity
  3862. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  3863. {
  3864. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  3865. limitMax = idx+1;
  3866. }
  3867. if(maxProfile.id != -1)
  3868. {
  3869. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3870. {
  3871. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3872. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3873. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  3874. {
  3875. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3876. {
  3877. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3878. compositePeriodIdx++;
  3879. }
  3880. else
  3881. {
  3882. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3883. }
  3884. }
  3885. }
  3886. }
  3887. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  3888. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3889. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  3890. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  3891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3892. {
  3893. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  3894. {
  3895. compositeProfile.id = 1;
  3896. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3897. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  3898. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  3899. }
  3900. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  3901. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  3902. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  3903. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  3904. }
  3905. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3906. if(line)
  3907. free(line);
  3908. }
  3909. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3910. {
  3911. FILE *fp;
  3912. char profileFileName[128];
  3913. char *line = NULL;
  3914. size_t len = 0;
  3915. time_t CurrentTime;
  3916. struct tm *tmComposite;
  3917. struct ChargingProfileType maxProfile;
  3918. struct ChargingProfileType defaultTxProfile;
  3919. struct ChargingProfileType txProfile;
  3920. struct ChargingProfileType compositeProfile;
  3921. struct ChargingSchedulePeriodType tmpPeriod;
  3922. uint8_t limitMax=0;
  3923. uint8_t limitDef=0;
  3924. uint8_t limitTx=0;
  3925. int compositePeriodIdx = 0;
  3926. CurrentTime = time(NULL);
  3927. tmComposite=localtime(&CurrentTime);
  3928. 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);
  3929. if(isUnitA)
  3930. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3931. else
  3932. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3933. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3934. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3935. {
  3936. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3937. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3938. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3939. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  3940. }
  3941. compositeProfile.id = 0;
  3942. compositeProfile.stackLevel = 99 ;
  3943. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  3944. maxProfile.id = -1;
  3945. defaultTxProfile.id = -1;
  3946. txProfile.id = -1;
  3947. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3948. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  3949. txProfile.chargingSchedule[idxSchedule].duration = -1;
  3950. system("rm -f /tmp/*.json");
  3951. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3952. /*
  3953. * Search valid charging profile
  3954. */
  3955. //DEBUG_INFO("====================================\n");
  3956. // Search tx profile
  3957. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", connectorId);
  3958. if((access(profileFileName, F_OK))!=-1)
  3959. {
  3960. fp = fopen(profileFileName, "r");
  3961. while(getline(&line, &len, fp) != -1)
  3962. {
  3963. json_object *obj = NULL;
  3964. obj = json_tokener_parse(line);
  3965. if(is_error(obj))
  3966. {
  3967. DEBUG_ERROR("Parse txProfile from file error.\n");
  3968. }
  3969. else
  3970. {
  3971. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  3972. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  3973. )
  3974. {
  3975. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3976. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3977. )
  3978. {
  3979. struct tm tmFrom, tmTo;
  3980. struct timeb tbFrom, tbTo;
  3981. 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) &&
  3982. (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))
  3983. {
  3984. tmFrom.tm_year -= 1900;
  3985. tmFrom.tm_mon -= 1;
  3986. tbFrom.time = mktime(&tmFrom);
  3987. tmTo.tm_year -= 1900;
  3988. tmTo.tm_mon -= 1;
  3989. tbTo.time = mktime(&tmTo);
  3990. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3991. {
  3992. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3993. {
  3994. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3995. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3996. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3997. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3998. }
  3999. if(txProfile.id == -1)
  4000. DEBUG_INFO("TxProfile found.\n");
  4001. else
  4002. DEBUG_INFO("TxProfile updated.\n");
  4003. // Required item
  4004. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4005. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4006. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4007. if(isUnitA)
  4008. {
  4009. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4010. 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++)
  4011. {
  4012. 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"));
  4013. 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?
  4014. 3:
  4015. 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")));
  4016. 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")));
  4017. }
  4018. }
  4019. else
  4020. {
  4021. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4022. 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++)
  4023. {
  4024. 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"));
  4025. 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?
  4026. 3:
  4027. 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")));
  4028. 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));
  4029. }
  4030. }
  4031. // Optional item
  4032. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4033. {
  4034. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4035. }
  4036. else
  4037. {
  4038. sprintf((char*)txProfile.validFrom, " ");
  4039. }
  4040. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4041. {
  4042. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4043. }
  4044. else
  4045. {
  4046. sprintf((char*)txProfile.validTo, " ");
  4047. }
  4048. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4049. {
  4050. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4051. }
  4052. else
  4053. {
  4054. sprintf((char*)txProfile.recurrencyKind, " ");
  4055. }
  4056. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4057. {
  4058. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4059. }
  4060. else
  4061. {
  4062. sprintf((char*)txProfile.transactionId, " ");
  4063. }
  4064. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4065. {
  4066. 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"));
  4067. }
  4068. else
  4069. {
  4070. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4071. }
  4072. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4073. {
  4074. 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")));
  4075. }
  4076. else
  4077. {
  4078. 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));
  4079. }
  4080. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4081. {
  4082. 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"));
  4083. }
  4084. else
  4085. {
  4086. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4087. }
  4088. }
  4089. }
  4090. }
  4091. else
  4092. {
  4093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4094. {
  4095. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4096. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4097. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4098. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4099. }
  4100. if(txProfile.id == -1)
  4101. DEBUG_INFO("TxProfile found.\n");
  4102. else
  4103. DEBUG_INFO("TxProfile updated.\n");
  4104. // Required item
  4105. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4106. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4107. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4108. if(isUnitA)
  4109. {
  4110. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4111. 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++)
  4112. {
  4113. 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"));
  4114. 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?
  4115. 3:
  4116. 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")));
  4117. 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")));
  4118. }
  4119. }
  4120. else
  4121. {
  4122. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4123. 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++)
  4124. {
  4125. 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"));
  4126. 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?
  4127. 3:
  4128. 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")));
  4129. 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));
  4130. }
  4131. }
  4132. // Optional item
  4133. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4134. {
  4135. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4136. }
  4137. else
  4138. {
  4139. sprintf((char*)txProfile.validFrom, " ");
  4140. }
  4141. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4142. {
  4143. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4144. }
  4145. else
  4146. {
  4147. sprintf((char*)txProfile.validTo, " ");
  4148. }
  4149. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4150. {
  4151. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4152. }
  4153. else
  4154. {
  4155. sprintf((char*)txProfile.recurrencyKind, " ");
  4156. }
  4157. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4158. {
  4159. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4160. }
  4161. else
  4162. {
  4163. sprintf((char*)txProfile.transactionId, " ");
  4164. }
  4165. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4166. {
  4167. 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"));
  4168. }
  4169. else
  4170. {
  4171. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4172. }
  4173. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4174. {
  4175. 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")));
  4176. }
  4177. else
  4178. {
  4179. 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));
  4180. }
  4181. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4182. {
  4183. 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"));
  4184. }
  4185. else
  4186. {
  4187. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4188. }
  4189. }
  4190. }
  4191. }
  4192. json_object_put(obj);
  4193. }
  4194. fclose(fp);
  4195. /*
  4196. if(txProfile.id != -1)
  4197. {
  4198. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4199. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4200. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4201. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4202. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4203. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4204. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4205. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4206. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4207. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4208. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4209. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4210. {
  4211. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4212. {
  4213. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4214. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4215. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4216. }
  4217. }
  4218. }
  4219. else
  4220. DEBUG_INFO("TxProfile not found.\n");*/
  4221. }
  4222. // Search default tx profile
  4223. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", connectorId);
  4224. if((access(profileFileName, F_OK))==-1)
  4225. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4226. if((access(profileFileName, F_OK))!=-1)
  4227. {
  4228. fp = fopen(profileFileName, "r");
  4229. while(getline(&line, &len, fp) != -1)
  4230. {
  4231. json_object *obj = NULL;
  4232. obj = json_tokener_parse(line);
  4233. if(is_error(obj))
  4234. {
  4235. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4236. }
  4237. else
  4238. {
  4239. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  4240. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  4241. )
  4242. {
  4243. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4244. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4245. )
  4246. {
  4247. struct tm tmFrom, tmTo;
  4248. struct timeb tbFrom, tbTo;
  4249. 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) &&
  4250. (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))
  4251. {
  4252. tmFrom.tm_year -= 1900;
  4253. tmFrom.tm_mon -= 1;
  4254. tbFrom.time = mktime(&tmFrom);
  4255. tmTo.tm_year -= 1900;
  4256. tmTo.tm_mon -= 1;
  4257. tbTo.time = mktime(&tmTo);
  4258. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4259. {
  4260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4261. {
  4262. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4263. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4264. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4265. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4266. }
  4267. if(defaultTxProfile.id == -1)
  4268. DEBUG_INFO("TxDefaultProfile found.\n");
  4269. else
  4270. DEBUG_INFO("TxDefaultProfile updated.\n");
  4271. // Required item
  4272. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4273. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4274. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4275. if(isUnitA)
  4276. {
  4277. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4278. 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++)
  4279. {
  4280. 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"));
  4281. 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?
  4282. 3:
  4283. 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")));
  4284. 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")));
  4285. }
  4286. }
  4287. else
  4288. {
  4289. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4290. 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++)
  4291. {
  4292. 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"));
  4293. 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?
  4294. 3:
  4295. 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")));
  4296. 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));
  4297. }
  4298. }
  4299. // Optional item
  4300. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4301. {
  4302. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4303. }
  4304. else
  4305. {
  4306. sprintf((char*)defaultTxProfile.validFrom, " ");
  4307. }
  4308. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4309. {
  4310. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4311. }
  4312. else
  4313. {
  4314. sprintf((char*)defaultTxProfile.validTo, " ");
  4315. }
  4316. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4317. {
  4318. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4319. }
  4320. else
  4321. {
  4322. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4323. }
  4324. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4325. {
  4326. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4327. }
  4328. else
  4329. {
  4330. sprintf((char*)defaultTxProfile.transactionId, " ");
  4331. }
  4332. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4333. {
  4334. 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"));
  4335. }
  4336. else
  4337. {
  4338. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4339. }
  4340. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4341. {
  4342. 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")));
  4343. }
  4344. else
  4345. {
  4346. 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));
  4347. }
  4348. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4349. {
  4350. 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"));
  4351. }
  4352. else
  4353. {
  4354. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4355. }
  4356. }
  4357. }
  4358. }
  4359. else
  4360. {
  4361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4362. {
  4363. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4364. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4365. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4366. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4367. }
  4368. if(defaultTxProfile.id == -1)
  4369. DEBUG_INFO("TxDefaultProfile found.\n");
  4370. else
  4371. DEBUG_INFO("TxDefaultProfile updated.\n");
  4372. // Required item
  4373. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4374. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4375. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4376. if(isUnitA)
  4377. {
  4378. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4379. 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++)
  4380. {
  4381. 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"));
  4382. 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?
  4383. 3:
  4384. 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")));
  4385. 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")));
  4386. }
  4387. }
  4388. else
  4389. {
  4390. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4391. 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++)
  4392. {
  4393. 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"));
  4394. 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?
  4395. 3:
  4396. 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")));
  4397. 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));
  4398. }
  4399. }
  4400. // Optional item
  4401. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4402. {
  4403. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4404. }
  4405. else
  4406. {
  4407. sprintf((char*)defaultTxProfile.validFrom, " ");
  4408. }
  4409. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4410. {
  4411. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4412. }
  4413. else
  4414. {
  4415. sprintf((char*)defaultTxProfile.validTo, " ");
  4416. }
  4417. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4418. {
  4419. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4420. }
  4421. else
  4422. {
  4423. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4424. }
  4425. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4426. {
  4427. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4428. }
  4429. else
  4430. {
  4431. sprintf((char*)defaultTxProfile.transactionId, " ");
  4432. }
  4433. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4434. {
  4435. 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"));
  4436. }
  4437. else
  4438. {
  4439. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4440. }
  4441. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4442. {
  4443. 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")));
  4444. }
  4445. else
  4446. {
  4447. 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));
  4448. }
  4449. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4450. {
  4451. 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"));
  4452. }
  4453. else
  4454. {
  4455. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4456. }
  4457. }
  4458. }
  4459. }
  4460. json_object_put(obj);
  4461. }
  4462. fclose(fp);
  4463. /*
  4464. if(defaultTxProfile.id != -1)
  4465. {
  4466. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  4467. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4468. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4469. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4470. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4471. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4472. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  4473. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4474. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4475. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4476. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4478. {
  4479. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4480. {
  4481. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4482. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4483. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4484. }
  4485. }
  4486. }
  4487. else
  4488. DEBUG_INFO("TxDefaultProfile not found.\n");
  4489. DEBUG_INFO("------------------------------------\n");*/
  4490. }
  4491. // Search max profile
  4492. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4493. if((access(profileFileName, F_OK))!=-1)
  4494. {
  4495. fp = fopen(profileFileName, "r");
  4496. while(getline(&line, &len, fp) != -1)
  4497. {
  4498. json_object *obj = NULL;
  4499. obj = json_tokener_parse(line);
  4500. if(is_error(obj))
  4501. {
  4502. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4503. }
  4504. else
  4505. {
  4506. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4507. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4508. )
  4509. {
  4510. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4511. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4512. )
  4513. {
  4514. struct tm tmFrom, tmTo;
  4515. struct timeb tbFrom, tbTo;
  4516. 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) &&
  4517. (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))
  4518. {
  4519. tmFrom.tm_year -= 1900;
  4520. tmFrom.tm_mon -= 1;
  4521. tbFrom.time = mktime(&tmFrom);
  4522. tmTo.tm_year -= 1900;
  4523. tmTo.tm_mon -= 1;
  4524. tbTo.time = mktime(&tmTo);
  4525. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4526. {
  4527. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4528. {
  4529. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4530. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4531. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4532. }
  4533. if(maxProfile.id == -1)
  4534. DEBUG_INFO("MaxProfile found.\n");
  4535. else
  4536. DEBUG_INFO("MaxProfile updated.\n");
  4537. // Required item
  4538. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4539. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4540. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4541. if(isUnitA)
  4542. {
  4543. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4544. 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++)
  4545. {
  4546. 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"));
  4547. 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?
  4548. 3:
  4549. 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")));
  4550. 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")));
  4551. }
  4552. }
  4553. else
  4554. {
  4555. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4556. 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++)
  4557. {
  4558. 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"));
  4559. 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?
  4560. 3:
  4561. 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")));
  4562. 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));
  4563. }
  4564. }
  4565. // Optional item
  4566. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4567. {
  4568. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4569. }
  4570. else
  4571. {
  4572. sprintf((char*)maxProfile.validFrom, " ");
  4573. }
  4574. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4575. {
  4576. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4577. }
  4578. else
  4579. {
  4580. sprintf((char*)maxProfile.validTo, " ");
  4581. }
  4582. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4583. {
  4584. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4585. }
  4586. else
  4587. {
  4588. sprintf((char*)maxProfile.recurrencyKind, " ");
  4589. }
  4590. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4591. {
  4592. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4593. }
  4594. else
  4595. {
  4596. sprintf((char*)maxProfile.transactionId, " ");
  4597. }
  4598. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4599. {
  4600. 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"));
  4601. }
  4602. else
  4603. {
  4604. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4605. }
  4606. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4607. {
  4608. 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")));
  4609. }
  4610. else
  4611. {
  4612. 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));
  4613. }
  4614. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4615. {
  4616. 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"));
  4617. }
  4618. else
  4619. {
  4620. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4621. }
  4622. }
  4623. }
  4624. }
  4625. else
  4626. {
  4627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4628. {
  4629. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4630. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4631. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4632. }
  4633. if(maxProfile.id == -1)
  4634. DEBUG_INFO("MaxProfile found.\n");
  4635. else
  4636. DEBUG_INFO("MaxProfile updated.\n");
  4637. // Required item
  4638. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4639. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4640. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4641. if(isUnitA)
  4642. {
  4643. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4644. 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++)
  4645. {
  4646. 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"));
  4647. 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?
  4648. 3:
  4649. 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")));
  4650. 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")));
  4651. }
  4652. }
  4653. else
  4654. {
  4655. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4656. 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++)
  4657. {
  4658. 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"));
  4659. 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?
  4660. 3:
  4661. 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")));
  4662. 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));
  4663. }
  4664. }
  4665. // Optional item
  4666. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4667. {
  4668. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4669. }
  4670. else
  4671. {
  4672. sprintf((char*)maxProfile.validFrom, " ");
  4673. }
  4674. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4675. {
  4676. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4677. }
  4678. else
  4679. {
  4680. sprintf((char*)maxProfile.validTo, " ");
  4681. }
  4682. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4683. {
  4684. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4685. }
  4686. else
  4687. {
  4688. sprintf((char*)maxProfile.recurrencyKind, " ");
  4689. }
  4690. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4691. {
  4692. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4693. }
  4694. else
  4695. {
  4696. sprintf((char*)maxProfile.transactionId, " ");
  4697. }
  4698. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4699. {
  4700. 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"));
  4701. }
  4702. else
  4703. {
  4704. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4705. }
  4706. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4707. {
  4708. 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")));
  4709. }
  4710. else
  4711. {
  4712. 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));
  4713. }
  4714. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4715. {
  4716. 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"));
  4717. }
  4718. else
  4719. {
  4720. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4721. }
  4722. }
  4723. }
  4724. }
  4725. json_object_put(obj);
  4726. }
  4727. fclose(fp);
  4728. /*
  4729. if(maxProfile.id !=-1)
  4730. {
  4731. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4732. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4733. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4734. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4735. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4736. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4737. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4738. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4739. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4740. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4741. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4742. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4743. {
  4744. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4745. {
  4746. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4747. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4748. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4749. }
  4750. }
  4751. }
  4752. else
  4753. DEBUG_INFO("MaxProfile not found.\n");
  4754. DEBUG_INFO("------------------------------------\n");*/
  4755. }
  4756. /*
  4757. * Align found profile start schedule & periods
  4758. */
  4759. //DEBUG_INFO("====================================\n");
  4760. /*
  4761. // For local test usage, force modify found profile start schedule info
  4762. 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);
  4763. 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);
  4764. 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);
  4765. */
  4766. if(txProfile.id != -1)
  4767. {
  4768. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4769. {
  4770. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4771. {
  4772. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4773. 0:
  4774. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4775. }
  4776. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4777. {
  4778. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4779. {
  4780. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4781. 0:
  4782. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4783. if(idxPeriod > 0)
  4784. {
  4785. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4786. {
  4787. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4788. }
  4789. }
  4790. }
  4791. }
  4792. }
  4793. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4794. {
  4795. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4796. {
  4797. 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?
  4798. 0:
  4799. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4800. }
  4801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4802. {
  4803. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4804. {
  4805. 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?
  4806. 0:
  4807. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4808. if(idxPeriod > 0)
  4809. {
  4810. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4811. {
  4812. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4813. }
  4814. }
  4815. }
  4816. }
  4817. }
  4818. else
  4819. {
  4820. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4821. {
  4822. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4823. {
  4824. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4825. 0:
  4826. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4827. }
  4828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4829. {
  4830. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4831. {
  4832. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4833. 0:
  4834. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4835. if(idxPeriod > 0)
  4836. {
  4837. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4838. {
  4839. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4840. }
  4841. }
  4842. }
  4843. }
  4844. }
  4845. else
  4846. {
  4847. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4848. {
  4849. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4850. 0:
  4851. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4852. }
  4853. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4854. {
  4855. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4856. {
  4857. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4858. 0:
  4859. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4860. if(idxPeriod > 0)
  4861. {
  4862. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4863. {
  4864. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4865. }
  4866. }
  4867. }
  4868. }
  4869. }
  4870. }
  4871. /*
  4872. DEBUG_INFO("txProfile after align.\n");
  4873. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4874. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4875. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4876. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4877. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4878. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4879. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4880. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4881. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4882. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4883. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4884. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4885. {
  4886. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4887. {
  4888. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4889. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4890. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4891. }
  4892. }*/
  4893. }
  4894. if(defaultTxProfile.id != -1)
  4895. {
  4896. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4897. {
  4898. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4899. {
  4900. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4901. 0:
  4902. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4903. }
  4904. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4905. {
  4906. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4907. {
  4908. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4909. 0:
  4910. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4911. if(idxPeriod > 0)
  4912. {
  4913. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4914. {
  4915. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4916. }
  4917. }
  4918. }
  4919. }
  4920. }
  4921. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4922. {
  4923. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4924. {
  4925. 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?
  4926. 0:
  4927. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4928. }
  4929. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4930. {
  4931. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4932. {
  4933. 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?
  4934. 0:
  4935. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4936. if(idxPeriod > 0)
  4937. {
  4938. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4939. {
  4940. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4941. }
  4942. }
  4943. }
  4944. }
  4945. }
  4946. else
  4947. {
  4948. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4949. {
  4950. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4951. {
  4952. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4953. 0:
  4954. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4955. }
  4956. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4957. {
  4958. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4959. {
  4960. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4961. 0:
  4962. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4963. if(idxPeriod > 0)
  4964. {
  4965. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4966. {
  4967. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4968. }
  4969. }
  4970. }
  4971. }
  4972. }
  4973. else
  4974. {
  4975. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4976. {
  4977. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4978. 0:
  4979. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4980. }
  4981. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4982. {
  4983. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4984. {
  4985. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4986. 0:
  4987. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4988. if(idxPeriod > 0)
  4989. {
  4990. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4991. {
  4992. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4993. }
  4994. }
  4995. }
  4996. }
  4997. }
  4998. }
  4999. /*
  5000. DEBUG_INFO("defaultTxProfile after align.\n");
  5001. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5002. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5003. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5004. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5005. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5006. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5007. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5008. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5009. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5010. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5011. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5012. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5013. {
  5014. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5015. {
  5016. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5017. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5018. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5019. }
  5020. }
  5021. DEBUG_INFO("------------------------------------\n");*/
  5022. }
  5023. if(maxProfile.id != -1)
  5024. {
  5025. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5026. {
  5027. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5028. {
  5029. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5030. 0:
  5031. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5032. }
  5033. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5034. {
  5035. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5036. {
  5037. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5038. 0:
  5039. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5040. if(idxPeriod > 0)
  5041. {
  5042. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5043. {
  5044. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5045. }
  5046. }
  5047. }
  5048. }
  5049. }
  5050. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5051. {
  5052. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5053. {
  5054. 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?
  5055. 0:
  5056. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5057. }
  5058. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5059. {
  5060. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5061. {
  5062. 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?
  5063. 0:
  5064. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5065. if(idxPeriod > 0)
  5066. {
  5067. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5068. {
  5069. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5070. }
  5071. }
  5072. }
  5073. }
  5074. }
  5075. else
  5076. {
  5077. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5078. {
  5079. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5080. {
  5081. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5082. 0:
  5083. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5084. }
  5085. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5086. {
  5087. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5088. {
  5089. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5090. 0:
  5091. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5092. if(idxPeriod > 0)
  5093. {
  5094. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5095. {
  5096. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5097. }
  5098. }
  5099. }
  5100. }
  5101. }
  5102. else
  5103. {
  5104. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5105. {
  5106. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5107. 0:
  5108. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5109. }
  5110. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5111. {
  5112. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5113. {
  5114. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5115. 0:
  5116. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5117. if(idxPeriod > 0)
  5118. {
  5119. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5120. {
  5121. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5122. }
  5123. }
  5124. }
  5125. }
  5126. }
  5127. }
  5128. /*
  5129. DEBUG_INFO("MaxProfile after align.\n");
  5130. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5131. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5132. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5133. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5134. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5135. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5136. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5137. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5138. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5139. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5140. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5141. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5142. {
  5143. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5144. {
  5145. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5146. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5147. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5148. }
  5149. }
  5150. DEBUG_INFO("------------------------------------\n");*/
  5151. }
  5152. /*
  5153. * Merge to conposite schedule
  5154. */
  5155. //DEBUG_INFO("====================================\n");
  5156. // Find each profile period quantity
  5157. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5158. {
  5159. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5160. limitMax = idx+1;
  5161. }
  5162. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5163. {
  5164. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5165. limitDef = idx+1;
  5166. }
  5167. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5168. {
  5169. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5170. limitTx = idx+1;
  5171. }
  5172. // TxProfile found, composite schedule based on it
  5173. if(txProfile.id != -1)
  5174. {
  5175. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  5176. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  5177. {
  5178. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  5179. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  5180. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  5181. {
  5182. if(maxProfile.id != -1)
  5183. {
  5184. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5185. {
  5186. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  5187. {
  5188. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5189. {
  5190. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5191. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5192. 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);
  5193. }
  5194. else
  5195. {
  5196. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5197. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5198. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  5199. }
  5200. }
  5201. if(idxMaxPeriod == (limitMax-1))
  5202. {
  5203. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5204. {
  5205. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5206. {
  5207. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5208. compositePeriodIdx++;
  5209. }
  5210. else
  5211. {
  5212. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5213. }
  5214. }
  5215. }
  5216. }
  5217. }
  5218. else
  5219. {
  5220. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5221. {
  5222. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5223. compositePeriodIdx++;
  5224. }
  5225. else
  5226. {
  5227. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5228. }
  5229. }
  5230. }
  5231. if(idxTxPeriod == (limitTx-1))
  5232. {
  5233. if(defaultTxProfile.id != -1)
  5234. {
  5235. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  5236. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5237. {
  5238. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  5239. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5240. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  5241. {
  5242. if(maxProfile.id != -1)
  5243. {
  5244. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5245. {
  5246. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5247. {
  5248. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5249. {
  5250. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5251. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5252. 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);
  5253. }
  5254. else
  5255. {
  5256. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5257. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5258. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5259. }
  5260. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5261. {
  5262. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5263. {
  5264. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5265. compositePeriodIdx++;
  5266. }
  5267. else
  5268. {
  5269. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5270. }
  5271. }
  5272. // Delete duplicate period
  5273. if(compositePeriodIdx > 1)
  5274. {
  5275. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5276. {
  5277. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5278. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5279. compositePeriodIdx -= 1;
  5280. }
  5281. }
  5282. }
  5283. else
  5284. {
  5285. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5286. {
  5287. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5288. compositePeriodIdx++;
  5289. }
  5290. else
  5291. {
  5292. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5293. }
  5294. break;
  5295. }
  5296. }
  5297. }
  5298. else
  5299. {
  5300. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5301. {
  5302. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5303. compositePeriodIdx++;
  5304. }
  5305. else
  5306. {
  5307. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5308. }
  5309. }
  5310. }
  5311. }
  5312. }
  5313. }
  5314. }
  5315. }
  5316. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  5317. else if(defaultTxProfile.id != -1)
  5318. {
  5319. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  5320. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5321. {
  5322. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  5323. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5324. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  5325. {
  5326. if(maxProfile.id != -1)
  5327. {
  5328. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5329. {
  5330. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5331. {
  5332. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5333. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5334. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5335. {
  5336. 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);
  5337. }
  5338. else
  5339. {
  5340. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5341. }
  5342. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5343. {
  5344. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5345. {
  5346. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5347. compositePeriodIdx++;
  5348. }
  5349. else
  5350. {
  5351. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5352. }
  5353. }
  5354. // Delete duplicate period
  5355. if(compositePeriodIdx > 1)
  5356. {
  5357. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5358. {
  5359. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5360. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5361. compositePeriodIdx -= 1;
  5362. }
  5363. }
  5364. }
  5365. else
  5366. {
  5367. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5368. {
  5369. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5370. compositePeriodIdx++;
  5371. }
  5372. else
  5373. {
  5374. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5375. }
  5376. break;
  5377. }
  5378. }
  5379. }
  5380. else
  5381. {
  5382. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5383. {
  5384. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5385. compositePeriodIdx++;
  5386. }
  5387. else
  5388. {
  5389. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5390. }
  5391. }
  5392. }
  5393. }
  5394. }
  5395. // Fill other period by MaxProfile
  5396. if(maxProfile.id != -1)
  5397. {
  5398. if(compositePeriodIdx==0)
  5399. {
  5400. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  5401. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  5402. {
  5403. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5404. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5405. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5406. {
  5407. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5408. {
  5409. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5410. compositePeriodIdx++;
  5411. }
  5412. else
  5413. {
  5414. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5415. }
  5416. }
  5417. }
  5418. }
  5419. else
  5420. {
  5421. int lastCompositePeriodIdx = compositePeriodIdx;
  5422. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5423. {
  5424. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5425. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5426. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5427. {
  5428. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  5429. {
  5430. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  5431. {
  5432. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5433. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5434. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  5435. }
  5436. else
  5437. {
  5438. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5439. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5440. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  5441. }
  5442. }
  5443. if(tmpPeriod.limit != -1)
  5444. {
  5445. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  5446. {
  5447. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  5448. {
  5449. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5450. compositePeriodIdx++;
  5451. }
  5452. else
  5453. {
  5454. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5455. }
  5456. }
  5457. // Delete duplicate period
  5458. if(compositePeriodIdx > 1)
  5459. {
  5460. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5461. {
  5462. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5463. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5464. compositePeriodIdx -= 1;
  5465. }
  5466. }
  5467. }
  5468. }
  5469. }
  5470. }
  5471. }
  5472. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  5473. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  5474. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  5475. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  5476. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  5477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5478. {
  5479. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  5480. {
  5481. compositeProfile.id = 1;
  5482. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  5483. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  5484. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  5485. }
  5486. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  5487. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  5488. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  5489. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  5490. }
  5491. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  5492. if(line)
  5493. free(line);
  5494. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  5495. }
  5496. //==========================================
  5497. // Init all share memory
  5498. //==========================================
  5499. int InitShareMemory()
  5500. {
  5501. int result = PASS;
  5502. int MeterSMId;
  5503. //creat ShmSysConfigAndInfo
  5504. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  5505. {
  5506. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  5507. result = FAIL;
  5508. }
  5509. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5510. {
  5511. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  5512. result = FAIL;
  5513. }
  5514. else
  5515. {}
  5516. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  5517. {
  5518. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  5519. result = FAIL;
  5520. }
  5521. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5522. {
  5523. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  5524. result = FAIL;
  5525. }
  5526. else
  5527. {}
  5528. //creat ShmPsuData
  5529. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  5530. {
  5531. DEBUG_ERROR("shmget ShmPsuData NG\n");
  5532. result = FAIL;
  5533. }
  5534. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5535. {
  5536. DEBUG_ERROR("shmat ShmPsuData NG\n");
  5537. result = FAIL;
  5538. }
  5539. else
  5540. {}
  5541. //creat ShmOCPP20Data
  5542. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  5543. {
  5544. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  5545. result = FAIL;
  5546. }
  5547. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5548. {
  5549. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  5550. result = FAIL;
  5551. }
  5552. else
  5553. {}
  5554. /****************************** For Initial Settings************************************************/
  5555. /*
  5556. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  5557. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  5558. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  5559. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  5560. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  5561. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  5562. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  5563. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  5564. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  5565. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  5566. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  5567. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  5568. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  5569. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  5570. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  5571. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  5572. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  5573. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  5574. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  5575. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  5576. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  5577. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  5578. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  5579. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  5580. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  5581. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  5582. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  5583. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  5584. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  5585. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  5586. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  5587. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  5588. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  5589. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  5590. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  5591. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  5592. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  5593. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  5594. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  5595. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  5596. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  5597. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  5598. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  5599. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  5600. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  5601. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  5602. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  5603. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  5604. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  5605. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  5606. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  5607. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  5608. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  5609. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  5610. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  5611. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  5612. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  5613. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  5614. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  5615. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  5616. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  5617. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  5618. */
  5619. return result;
  5620. }
  5621. int ProcessShareMemory()
  5622. {
  5623. int result = PASS;
  5624. if(InitShareMemory() == FAIL)
  5625. {
  5626. DEBUG_ERROR("InitShareMemory NG\n");
  5627. if(ShmStatusCodeData!=NULL)
  5628. {
  5629. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5630. }
  5631. result = FAIL;
  5632. }
  5633. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  5634. {
  5635. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  5636. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  5637. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  5638. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  5639. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  5640. ) // 'D' means DC
  5641. {
  5642. // DO series
  5643. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  5644. {
  5645. gunTotalNumber += 1;
  5646. gunType[gun_index] = GUN_TYPE_DO;
  5647. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5648. {
  5649. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  5650. {
  5651. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5652. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5653. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  5654. }
  5655. }
  5656. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5657. {
  5658. case Gun_Type_Chademo:
  5659. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  5660. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  5661. {
  5662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5663. {
  5664. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5665. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5666. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  5667. }
  5668. }
  5669. break;
  5670. case Gun_Type_CCS_2:
  5671. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  5672. for (int index = 0; index < CCS_QUANTITY; index++)
  5673. {
  5674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5675. {
  5676. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5677. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5678. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  5679. }
  5680. }
  5681. break;
  5682. case Gun_Type_GB:
  5683. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  5684. for (int index = 0; index < GB_QUANTITY; index++)
  5685. {
  5686. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5687. {
  5688. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5689. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5690. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  5691. }
  5692. }
  5693. break;
  5694. case Gun_Type_AC:
  5695. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  5696. for (int index = 0; index < AC_QUANTITY; index++)
  5697. {
  5698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  5699. {
  5700. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5701. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5702. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  5703. }
  5704. }
  5705. break;
  5706. default:
  5707. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  5708. break;
  5709. }
  5710. }
  5711. }
  5712. else
  5713. {
  5714. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  5715. {
  5716. gunTotalNumber += 1;
  5717. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5718. {
  5719. case Gun_Type_Chademo:
  5720. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  5721. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  5722. break;
  5723. case Gun_Type_CCS_2:
  5724. gunType[gun_index] = GUN_TYPE_CCS;
  5725. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  5726. break;
  5727. case Gun_Type_GB:
  5728. gunType[gun_index] = GUN_TYPE_GBT;
  5729. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  5730. break;
  5731. case Gun_Type_AC:
  5732. gunType[gun_index] = GUN_TYPE_AC;
  5733. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  5734. break;
  5735. default:
  5736. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  5737. break;
  5738. }
  5739. }
  5740. }
  5741. }
  5742. else
  5743. {
  5744. DEBUG_ERROR("Model name parsing fail.\n");
  5745. result = FAIL;
  5746. }
  5747. if(result != PASS)sleep(5);
  5748. return result;
  5749. }
  5750. //---------------------common routine---------------------------//
  5751. void checkNetworkProfile(void)
  5752. {
  5753. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  5754. json_object *priority;
  5755. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  5756. if(!is_error(priority))
  5757. {
  5758. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  5759. {
  5760. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  5761. {
  5762. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  5763. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  5764. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  5765. {
  5766. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  5767. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  5768. break;
  5769. }
  5770. }
  5771. }
  5772. }
  5773. json_object_put(priority);
  5774. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  5775. }
  5776. void checkRemoteStart(uint8_t connectorIdx)
  5777. {
  5778. uint8_t tempIndex;
  5779. int isAllowStart = TRUE;
  5780. char cmdBuf[512];
  5781. //check Transaction active
  5782. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  5783. {
  5784. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5785. {
  5786. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5787. }
  5788. else
  5789. {
  5790. tempIndex = (connectorIdx-1);
  5791. }
  5792. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5793. {
  5794. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  5795. {
  5796. 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))
  5797. {
  5798. //Reserved
  5799. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  5800. }
  5801. 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))
  5802. {
  5803. //Reserved
  5804. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  5805. isAllowStart = FALSE;
  5806. }
  5807. else
  5808. {
  5809. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5810. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  5811. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  5812. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  5813. {
  5814. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  5815. isAllowStart = FALSE;
  5816. }
  5817. }//END FOR ELSE
  5818. }
  5819. }// END FOR CHAdeMO_QUANTITY
  5820. }
  5821. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  5822. {
  5823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5824. {
  5825. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5826. }
  5827. else
  5828. {
  5829. tempIndex = (connectorIdx-1);
  5830. }
  5831. for (int index = 0; index < CCS_QUANTITY; index++)
  5832. {
  5833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5834. {
  5835. 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))
  5836. {
  5837. //Reserved
  5838. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  5839. }
  5840. 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))
  5841. {
  5842. //Reserved
  5843. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  5844. isAllowStart = FALSE;
  5845. }
  5846. else
  5847. {
  5848. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5849. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5850. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5851. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5852. {
  5853. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  5854. isAllowStart = FALSE;
  5855. }
  5856. }// END FOR ELSE
  5857. }
  5858. }// END FOR CCS_QUANTITY
  5859. }
  5860. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5863. {
  5864. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5865. }
  5866. else
  5867. {
  5868. tempIndex = (connectorIdx-1);
  5869. }
  5870. for (int index = 0; index < GB_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  5873. {
  5874. 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))
  5875. {
  5876. //Reserved
  5877. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  5878. }
  5879. 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))
  5880. {
  5881. //Reserved
  5882. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  5883. isAllowStart = FALSE;
  5884. }
  5885. else
  5886. {
  5887. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5888. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5889. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5890. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5891. {
  5892. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  5893. isAllowStart = FALSE;
  5894. }
  5895. }// END FOR ELSE
  5896. }
  5897. } // END FOR GB_QUANTITY
  5898. }
  5899. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  5900. {
  5901. tempIndex = (connectorIdx-1);
  5902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5903. {
  5904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  5905. {
  5906. 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))
  5907. {
  5908. //Reserved
  5909. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  5910. }
  5911. 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))
  5912. {
  5913. //Reserved
  5914. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  5915. isAllowStart = FALSE;
  5916. }
  5917. else
  5918. {
  5919. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5920. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5921. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5922. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5923. {
  5924. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  5925. isAllowStart = FALSE;
  5926. }
  5927. }// END FOR ELSE
  5928. }
  5929. } // END FOR GB_QUANTITY
  5930. }
  5931. else
  5932. {
  5933. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5934. {
  5935. tempIndex = 2;
  5936. }
  5937. else
  5938. {
  5939. tempIndex = (connectorIdx-1);
  5940. }
  5941. for (int index = 0; index < AC_QUANTITY; index++)
  5942. {
  5943. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  5944. {
  5945. 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))
  5946. {
  5947. //Reserved
  5948. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  5949. }
  5950. 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))
  5951. {
  5952. //Reserved
  5953. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  5954. isAllowStart = FALSE;
  5955. }
  5956. else
  5957. {
  5958. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5959. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5960. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5961. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5962. {
  5963. DEBUG_WARN("AC connector not allow start cause busy.\n");
  5964. isAllowStart = FALSE;
  5965. }
  5966. }//END FOR ELSE
  5967. }
  5968. }// END FOR AC_QUANTITY
  5969. }
  5970. if(isAllowStart == TRUE)
  5971. {
  5972. if(ShmOCPP20Data->RequestStartTransaction[connectorIdx -1].chargingProfile.id > 0)
  5973. {
  5974. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  5975. {
  5976. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  5977. system(cmdBuf);
  5978. }
  5979. }
  5980. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  5981. }
  5982. }
  5983. void CheckSystemValue(void)
  5984. {
  5985. char filenmae[100]={0};
  5986. char str[100]={0};
  5987. int tempIndex = 0;
  5988. //===============================
  5989. // EVSE operation check
  5990. //===============================
  5991. //===============================
  5992. // Heartbeat check
  5993. //===============================
  5994. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  5995. {
  5996. //parameter for test
  5997. sendHeartbeatRequest(0);
  5998. //==============================================
  5999. // Reset Waiting Time
  6000. //==============================================
  6001. HeartBeatWithNOResponse += 1;
  6002. }
  6003. //===============================
  6004. // CSU Trigger Authorize Request
  6005. //===============================
  6006. if(isWebsocketSendable &&
  6007. (server_sign == TRUE) &&
  6008. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6009. (authorizeRetryTimes < 3))
  6010. {
  6011. sendAuthorizeRequest(0);
  6012. authorizeRetryTimes = authorizeRetryTimes + 1;
  6013. if(authorizeRetryTimes < 3)
  6014. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6015. }
  6016. else if((server_sign == TRUE) &&
  6017. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6018. (authorizeRetryTimes >= 3))
  6019. {
  6020. authorizeRetryTimes = 0;
  6021. SetOcppConnStatus(FALSE);
  6022. server_sign = FALSE;
  6023. }
  6024. else if((server_sign == FALSE) &&
  6025. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  6026. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  6027. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6028. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6029. {
  6030. sendAuthorizeRequest(0);
  6031. }
  6032. if(isWebsocketSendable &&
  6033. (server_sign == TRUE) &&
  6034. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6035. {
  6036. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6037. {
  6038. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6039. {
  6040. /*
  6041. * TODO:
  6042. * 1. Report component that are ThresholdMonitoring
  6043. */
  6044. }
  6045. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6046. {
  6047. /*
  6048. * TODO:
  6049. * 1. Report component that are DeltaMonitoring
  6050. */
  6051. }
  6052. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6053. {
  6054. /*
  6055. * TODO:
  6056. * 1. Report component that are PeriodicMonitoring
  6057. */
  6058. }
  6059. else
  6060. {
  6061. /*
  6062. * TODO:
  6063. * 1. Process unknown criteria condition
  6064. */
  6065. }
  6066. }
  6067. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6068. }
  6069. if(isWebsocketSendable &&
  6070. (server_sign == TRUE) &&
  6071. (ShmOCPP20Data->GetReport.requestId > 0))
  6072. {
  6073. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6074. {
  6075. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6076. {
  6077. /*
  6078. * TODO:
  6079. * 1. Report component that are active
  6080. */
  6081. }
  6082. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6083. {
  6084. /*
  6085. * TODO:
  6086. * 1. Report component that are available
  6087. */
  6088. }
  6089. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6090. {
  6091. /*
  6092. * TODO:
  6093. * 1. Report component that are enable
  6094. */
  6095. }
  6096. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6097. {
  6098. /*
  6099. * TODO:
  6100. * 1. Report component that are problem
  6101. */
  6102. }
  6103. else
  6104. {
  6105. /*
  6106. * TODO:
  6107. * 1. Process unknown criteria condition
  6108. */
  6109. }
  6110. }
  6111. ShmOCPP20Data->GetReport.requestId = 0;
  6112. }
  6113. if(isWebsocketSendable &&
  6114. (server_sign == TRUE) &&
  6115. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6116. {
  6117. uint8_t reportIdx = 0;
  6118. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6119. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6120. {
  6121. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6122. {
  6123. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6124. {
  6125. 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))
  6126. {
  6127. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6128. reportIdx++;
  6129. }
  6130. }
  6131. else
  6132. {
  6133. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6134. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6135. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6136. else
  6137. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6138. sendNotifyReportRequest();
  6139. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6140. reportIdx = 0;
  6141. }
  6142. }
  6143. }
  6144. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6145. {
  6146. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6147. {
  6148. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6149. {
  6150. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6151. reportIdx++;
  6152. }
  6153. else
  6154. {
  6155. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6156. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6157. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6158. else
  6159. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6160. sendNotifyReportRequest();
  6161. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6162. reportIdx = 0;
  6163. }
  6164. }
  6165. }
  6166. else
  6167. {
  6168. /*
  6169. * TODO:
  6170. * 1. Fill out summary inventory to response message, currently not support
  6171. */
  6172. }
  6173. if(reportIdx > 0)
  6174. {
  6175. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6176. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6177. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6178. else
  6179. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6180. sendNotifyReportRequest();
  6181. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6182. reportIdx = 0;
  6183. }
  6184. ShmOCPP20Data->GetBaseReport.requestId = 0;
  6185. }
  6186. if(isWebsocketSendable &&
  6187. (server_sign == TRUE) &&
  6188. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  6189. {
  6190. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  6191. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  6192. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  6193. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  6194. else
  6195. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  6196. sendNotifyEventRequest();
  6197. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  6198. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  6199. }
  6200. if(isWebsocketSendable &&
  6201. (server_sign == TRUE) &&
  6202. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  6203. {
  6204. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  6205. {
  6206. /*
  6207. * TODO:
  6208. * 1.
  6209. */
  6210. }
  6211. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  6212. {
  6213. /*
  6214. * TODO:
  6215. * 1.
  6216. */
  6217. }
  6218. else
  6219. {
  6220. /*
  6221. * TODO:
  6222. * 1.
  6223. */
  6224. }
  6225. sendGet15118EVCertificateRequest();
  6226. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  6227. }
  6228. if(isWebsocketSendable &&
  6229. (server_sign == TRUE) &&
  6230. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  6231. {
  6232. sendSecurityEventNotificationRequest();
  6233. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  6234. }
  6235. if(isWebsocketSendable &&
  6236. (server_sign == TRUE) &&
  6237. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  6238. {
  6239. sendNotifyCustomerInformationRequest();
  6240. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  6241. }
  6242. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6243. {
  6244. // ClockAlign MeterValue
  6245. 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))
  6246. {
  6247. //check Transaction active
  6248. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6249. {
  6250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6251. {
  6252. tempIndex = ((gun_index==2) ? 1: 0);
  6253. }
  6254. else
  6255. {
  6256. tempIndex = gun_index;
  6257. }
  6258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6259. {
  6260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6261. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6262. {
  6263. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6264. }
  6265. }// End for CHAdeMO
  6266. }
  6267. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6268. {
  6269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6270. {
  6271. tempIndex = ((gun_index==2) ? 1: 0);
  6272. }
  6273. else
  6274. {
  6275. tempIndex = gun_index;
  6276. }
  6277. for (int index = 0; index < CCS_QUANTITY; index++)
  6278. {
  6279. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6280. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6281. {
  6282. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6283. }
  6284. } // End for CCS
  6285. }
  6286. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6287. {
  6288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6289. {
  6290. tempIndex = ((gun_index==2) ? 1: 0);
  6291. }
  6292. else
  6293. {
  6294. tempIndex = gun_index;
  6295. }
  6296. for (int index = 0; index < GB_QUANTITY; index++)
  6297. {
  6298. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6299. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6300. {
  6301. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6302. }
  6303. }// End for GB
  6304. }
  6305. else if(gunType[gun_index] == GUN_TYPE_DO)
  6306. {
  6307. tempIndex = gun_index;
  6308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6309. {
  6310. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6311. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6312. {
  6313. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6314. }
  6315. }
  6316. }
  6317. else
  6318. {
  6319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6320. {
  6321. tempIndex = 2;
  6322. }
  6323. else
  6324. {
  6325. tempIndex = gun_index;
  6326. }
  6327. for (int index = 0; index < AC_QUANTITY; index++)
  6328. {
  6329. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6330. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6331. {
  6332. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6333. }
  6334. }//End for AC
  6335. }
  6336. }
  6337. }
  6338. //===============================
  6339. // Each connector operation check
  6340. //===============================
  6341. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  6342. {
  6343. //==========================================
  6344. // Check remote start without connector id
  6345. //==========================================
  6346. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  6347. {
  6348. int connectorIdInt = -1;
  6349. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  6350. {
  6351. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  6352. {
  6353. connectorIdInt = (gun_index+1);
  6354. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  6355. checkRemoteStart(connectorIdInt);
  6356. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6357. break;
  6358. }
  6359. }
  6360. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  6361. {
  6362. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  6363. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6364. }
  6365. }
  6366. //==========================================
  6367. // csu trigger DataTransferReq
  6368. //==========================================
  6369. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  6370. {
  6371. sendDataTransferRequest(gun_index);
  6372. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  6373. }
  6374. //==============================================
  6375. // Charger status notification & Transaction event report
  6376. //==============================================
  6377. //--- Check Mode Change ---//
  6378. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6380. {
  6381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6382. {
  6383. tempIndex = ((gun_index==2) ? 1: 0);
  6384. }
  6385. else
  6386. {
  6387. tempIndex = gun_index;
  6388. }
  6389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6392. {
  6393. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  6394. {
  6395. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  6396. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  6397. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6398. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6399. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6400. {
  6401. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6402. }
  6403. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6404. {
  6405. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6406. if((access(filenmae,F_OK))!=-1)
  6407. {
  6408. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6409. sprintf(str,"rm -f %s",filenmae);
  6410. system(str);
  6411. }
  6412. }
  6413. }
  6414. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6415. #if 1 // for TempStopTransaction
  6416. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6417. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6418. {
  6419. checkTempStopTransaction(gun_index);
  6420. }
  6421. #endif
  6422. }
  6423. }
  6424. }
  6425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6426. {
  6427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6428. {
  6429. tempIndex = ((gun_index==2) ? 1: 0);
  6430. }
  6431. else
  6432. {
  6433. tempIndex = gun_index;
  6434. }
  6435. for (int index = 0; index < CCS_QUANTITY; index++)
  6436. {
  6437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6438. {
  6439. 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]*/ )
  6440. {
  6441. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  6442. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  6443. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6444. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6445. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6446. {
  6447. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6448. }
  6449. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6450. {
  6451. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6452. if((access(filenmae,F_OK))!=-1)
  6453. {
  6454. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6455. sprintf(str,"rm -f %s",filenmae);
  6456. system(str);
  6457. }
  6458. }
  6459. }
  6460. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6461. #if 1 // for TempStopTransaction
  6462. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6463. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6464. {
  6465. checkTempStopTransaction(gun_index);
  6466. }
  6467. #endif
  6468. }
  6469. }
  6470. }
  6471. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6472. {
  6473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6474. {
  6475. tempIndex = ((gun_index==2) ? 1: 0);
  6476. }
  6477. else
  6478. {
  6479. tempIndex = gun_index;
  6480. }
  6481. for (int index = 0; index < GB_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6484. {
  6485. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  6486. {
  6487. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  6488. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  6489. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6490. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6491. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6492. {
  6493. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6494. }
  6495. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6496. {
  6497. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6498. if((access(filenmae,F_OK))!=-1)
  6499. {
  6500. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6501. sprintf(str,"rm -f %s",filenmae);
  6502. system(str);
  6503. }
  6504. }
  6505. }
  6506. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6507. #if 1 // for TempStopTransaction
  6508. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6509. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6510. {
  6511. checkTempStopTransaction(gun_index);
  6512. }
  6513. #endif
  6514. }
  6515. }
  6516. }
  6517. else if(gunType[gun_index] == GUN_TYPE_DO)
  6518. {
  6519. tempIndex = gun_index;
  6520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6523. {
  6524. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  6525. {
  6526. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  6527. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  6528. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6529. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  6530. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  6531. {
  6532. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6533. }
  6534. 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
  6535. {
  6536. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6537. if((access(filenmae,F_OK))!=-1)
  6538. {
  6539. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6540. sprintf(str,"rm -f %s",filenmae);
  6541. system(str);
  6542. }
  6543. }
  6544. }
  6545. 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);
  6546. #if 1 // for TempStopTransaction
  6547. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  6548. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6549. {
  6550. checkTempStopTransaction(gun_index);
  6551. }
  6552. #endif
  6553. }
  6554. }
  6555. }
  6556. else
  6557. {
  6558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6559. {
  6560. tempIndex = 2;
  6561. }
  6562. else
  6563. {
  6564. tempIndex = gun_index;
  6565. }
  6566. for (int index = 0; index < AC_QUANTITY; index++)
  6567. {
  6568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6569. {
  6570. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  6571. {
  6572. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  6573. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  6574. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  6575. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6576. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6577. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6578. {
  6579. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6580. }
  6581. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6582. {
  6583. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6584. if((access(filenmae,F_OK))!=-1)
  6585. {
  6586. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6587. sprintf(str,"rm -f %s",filenmae);
  6588. system(str);
  6589. }
  6590. }
  6591. }
  6592. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6593. #if 1 // for TempStopTransaction
  6594. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6595. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6596. {
  6597. checkTempStopTransaction(gun_index);
  6598. }
  6599. #endif
  6600. }
  6601. }// END
  6602. }
  6603. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  6604. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  6605. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "TRUE") == 0) &&
  6606. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  6607. {
  6608. sendStatusNotificationRequest(gun_index);
  6609. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  6610. }
  6611. //==============================================
  6612. // CSU Trigger Smart Charging Profile
  6613. //==============================================
  6614. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  6615. {
  6616. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  6617. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  6618. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  6619. }
  6620. //==============================================
  6621. // CSU transaction event
  6622. //==============================================
  6623. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON)
  6624. {
  6625. sendTransactionEventRequest(gun_index);
  6626. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  6627. //storeTempStopTransaction(gun_index);
  6628. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  6629. }
  6630. //==============================================
  6631. // Meter report
  6632. //==============================================
  6633. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  6634. {
  6635. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  6636. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  6637. }
  6638. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  6639. {
  6640. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  6641. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  6642. }
  6643. // Sample period MeterValue
  6644. 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))
  6645. {
  6646. //check Transaction active
  6647. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6648. {
  6649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6650. {
  6651. tempIndex = ((gun_index==2) ? 1: 0);
  6652. }
  6653. else
  6654. {
  6655. tempIndex = gun_index;
  6656. }
  6657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6658. {
  6659. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6660. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6661. {
  6662. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6663. {
  6664. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6665. }
  6666. }
  6667. }// End for CHAdeMO
  6668. }
  6669. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6670. {
  6671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6672. {
  6673. tempIndex = ((gun_index==2) ? 1: 0);
  6674. }
  6675. else
  6676. {
  6677. tempIndex = gun_index;
  6678. }
  6679. for (int index = 0; index < CCS_QUANTITY; index++)
  6680. {
  6681. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6682. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6683. {
  6684. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6685. {
  6686. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6687. }
  6688. }
  6689. } // End for CCS
  6690. }
  6691. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6692. {
  6693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6694. {
  6695. tempIndex = ((gun_index==2) ? 1: 0);
  6696. }
  6697. else
  6698. {
  6699. tempIndex = gun_index;
  6700. }
  6701. for (int index = 0; index < GB_QUANTITY; index++)
  6702. {
  6703. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6704. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6705. {
  6706. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6707. {
  6708. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6709. }
  6710. }
  6711. }// End for GB
  6712. }
  6713. else if(gunType[gun_index] == GUN_TYPE_DO)
  6714. {
  6715. tempIndex = gun_index;
  6716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6717. {
  6718. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6719. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6720. {
  6721. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  6722. {
  6723. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6724. }
  6725. }
  6726. }
  6727. }
  6728. else
  6729. {
  6730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6731. {
  6732. tempIndex = 2;
  6733. }
  6734. else
  6735. {
  6736. tempIndex = gun_index;
  6737. }
  6738. for (int index = 0; index < AC_QUANTITY; index++)
  6739. {
  6740. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6741. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6742. {
  6743. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6744. {
  6745. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6746. }
  6747. }
  6748. }//End for AC
  6749. }
  6750. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  6751. {
  6752. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  6753. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  6754. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  6755. }
  6756. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6757. }
  6758. //==============================================
  6759. // Check Connector reserved
  6760. //==============================================
  6761. //===============================
  6762. // Check if Reserve is expired
  6763. //===============================
  6764. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  6765. {
  6766. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  6767. {
  6768. DEBUG_INFO("reserve expired.\n");
  6769. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  6770. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  6771. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  6772. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  6773. }
  6774. }//END OF Check if Reserve is expired
  6775. //==========================================
  6776. // csu trigger FirmwareStatusNotificationReq
  6777. //==========================================
  6778. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  6779. {
  6780. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  6781. }
  6782. //==========================================
  6783. // csu cleared charging limit request
  6784. //==========================================
  6785. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  6786. {
  6787. sendClearedChargingLimitRequest(gun_index);
  6788. }
  6789. //==========================================
  6790. // csu trigger CancelReservationConf
  6791. //==========================================
  6792. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  6793. {
  6794. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  6795. }
  6796. //==========================================
  6797. // csu notify EV charging need request
  6798. //==========================================
  6799. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  6800. {
  6801. sendNotifyEVChargingNeedsRequest(gun_index);
  6802. }
  6803. //==========================================
  6804. // csu trigger ChangeAvailabilityConf
  6805. //==========================================
  6806. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  6807. {
  6808. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  6809. }
  6810. //==========================================
  6811. // csu trigger UnlockConnectorConf
  6812. //==========================================
  6813. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  6814. {
  6815. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  6816. }
  6817. //==========================================
  6818. // csu trigger ReserveNowConf
  6819. //==========================================
  6820. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  6821. {
  6822. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  6823. }
  6824. //==========================================
  6825. // csu trigger ReserveNowConf
  6826. //==========================================
  6827. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  6828. {
  6829. sendReservationStatusUpdateRequest(gun_index);
  6830. }
  6831. //==========================================
  6832. // csu trigger LogStatusNotificationReq
  6833. //==========================================
  6834. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  6835. {
  6836. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  6837. }
  6838. //==========================================
  6839. // csu trigger SignCertificateReq
  6840. //==========================================
  6841. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  6842. {
  6843. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  6844. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  6845. {
  6846. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  6847. }
  6848. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  6849. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  6850. {
  6851. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  6852. }
  6853. }
  6854. }
  6855. }
  6856. //==========================================
  6857. // send request routine
  6858. //==========================================
  6859. int sendAuthorizeRequest(int gun_index)
  6860. {
  6861. mtrace();
  6862. int result = FAIL;
  6863. char message[4096]={0};
  6864. char guid[37];
  6865. char tempdata[128]={0};
  6866. json_object *Authorize = json_object_new_object();
  6867. json_object *idToken = json_object_new_object();
  6868. DEBUG_INFO("sendAuthorizeRequest...\n");
  6869. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  6870. //Local Authorize
  6871. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  6872. {
  6873. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  6874. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6875. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  6876. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  6877. result = PASS;
  6878. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6879. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6880. authorizeRetryTimes = 0;
  6881. return result;
  6882. }
  6883. 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)) ||
  6884. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  6885. {
  6886. // Query idtag from cache
  6887. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  6888. // Query idtag from list
  6889. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6890. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  6891. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6892. {
  6893. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  6894. {
  6895. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6896. }
  6897. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  6898. {
  6899. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6900. }
  6901. // Return authorize result if does not connect to server
  6902. if(!ShmOCPP20Data->OcppConnStatus)
  6903. {
  6904. DEBUG_INFO("Local Authorization Fail.\n");
  6905. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6906. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6907. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  6908. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6909. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6910. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6911. authorizeRetryTimes = 0;
  6912. return result;
  6913. }
  6914. }
  6915. else
  6916. {
  6917. DEBUG_INFO("Local Authorization get result.\n");
  6918. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  6919. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6920. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  6921. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  6922. else
  6923. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  6924. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6925. result = PASS;
  6926. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6927. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6928. authorizeRetryTimes = 0;
  6929. return result;
  6930. }
  6931. }
  6932. //get data from shared memory
  6933. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6934. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  6935. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  6936. json_object_object_add(Authorize, "idToken", idToken);
  6937. random_uuid(guid);
  6938. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  6939. json_object_put(Authorize);
  6940. LWS_Send(message);
  6941. sprintf(tempdata, "Authorize,%d", gun_index);
  6942. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6943. {
  6944. result = PASS;
  6945. }
  6946. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6947. return result;
  6948. }
  6949. int sendBootNotificationRequest()
  6950. {
  6951. mtrace();
  6952. int result = FAIL;
  6953. char message[4096]={0};
  6954. char guid[37]={0};
  6955. char tempdata[128]={0};
  6956. json_object *BootNotification = json_object_new_object();
  6957. json_object *chargingStation = json_object_new_object();
  6958. json_object *modem = json_object_new_object();
  6959. DEBUG_INFO("sendBootNotificationRequest...\n");
  6960. // Fill BootNotification fields
  6961. DB_getBooType();
  6962. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  6963. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6964. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  6965. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  6966. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  6967. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  6968. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  6969. {
  6970. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  6971. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  6972. json_object_object_add(chargingStation, "modem", modem);
  6973. }
  6974. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  6975. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  6976. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  6977. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  6978. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  6979. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  6980. random_uuid(guid);
  6981. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  6982. json_object_put(BootNotification);
  6983. LWS_Send(message);
  6984. sprintf(tempdata, "BootNotification,0");
  6985. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6986. {
  6987. result = PASS;
  6988. }
  6989. return result;
  6990. }
  6991. int sendClearedChargingLimitRequest(int gun_index)
  6992. {
  6993. mtrace();
  6994. int result = FAIL;
  6995. char message[4096]={0};
  6996. char guid[37]={0};
  6997. char tempdata[128]={0};
  6998. json_object *ClearedChargingLimit = json_object_new_object();
  6999. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  7000. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  7001. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  7002. random_uuid(guid);
  7003. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  7004. json_object_put(ClearedChargingLimit);
  7005. LWS_Send(message);
  7006. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  7007. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7008. {
  7009. result = PASS;
  7010. }
  7011. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  7012. return result;
  7013. }
  7014. int sendDataTransferRequest(int gun_index)
  7015. {
  7016. mtrace();
  7017. char message[1000]={0};
  7018. char guid[37]={0};
  7019. char tempdata[65]={0};
  7020. int result = FAIL;
  7021. DEBUG_INFO("sendDataTransferRequest...\n");
  7022. random_uuid(guid);
  7023. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  7024. MESSAGE_TYPE_CALL,
  7025. guid,
  7026. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  7027. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  7028. ShmOCPP20Data->DataTransfer[gun_index].data);
  7029. LWS_Send(message);
  7030. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  7031. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7032. {
  7033. result = PASS;
  7034. }
  7035. return result;
  7036. }
  7037. int sendFirmwareStatusNotificationRequest(char *status)
  7038. {
  7039. mtrace();
  7040. int result = FAIL;
  7041. char message[110]={0};
  7042. char guid[37]={0};
  7043. char tempdata[65]={0};
  7044. json_object *FirmwareStatusNotification = json_object_new_object();
  7045. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  7046. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  7047. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  7048. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  7049. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  7050. random_uuid(guid);
  7051. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7052. json_object_put(FirmwareStatusNotification);
  7053. LWS_SendNow(message);
  7054. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7055. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7056. {
  7057. result = PASS;
  7058. }
  7059. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  7060. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  7061. //record status
  7062. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  7063. {
  7064. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  7065. }
  7066. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  7067. {
  7068. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  7069. }
  7070. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  7071. {
  7072. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  7073. }
  7074. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  7075. {
  7076. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  7077. }
  7078. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  7079. {
  7080. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  7081. }
  7082. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  7083. {
  7084. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  7085. }
  7086. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  7087. {
  7088. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  7089. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7090. }
  7091. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  7092. {
  7093. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  7094. }
  7095. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  7096. {
  7097. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  7098. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7099. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7100. }
  7101. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  7102. {
  7103. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  7104. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7105. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7106. }
  7107. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  7108. {
  7109. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  7110. }
  7111. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  7112. {
  7113. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  7114. }
  7115. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  7116. {
  7117. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  7118. }
  7119. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  7120. {
  7121. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  7122. }
  7123. return result;
  7124. }
  7125. int sendGet15118EVCertificateRequest()
  7126. {
  7127. mtrace();
  7128. int result = FAIL;
  7129. char message[4096]={0};
  7130. char guid[37]={0};
  7131. char tempdata[128]={0};
  7132. json_object *Get15118EVCertificate = json_object_new_object();
  7133. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  7134. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  7135. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  7136. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  7137. random_uuid(guid);
  7138. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  7139. json_object_put(Get15118EVCertificate);
  7140. LWS_Send(message);
  7141. sprintf(tempdata, "Get15118EVCertificate,0");
  7142. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7143. {
  7144. result = PASS;
  7145. }
  7146. return result;
  7147. }
  7148. int sendGetCertificateStatusRequest()
  7149. {
  7150. mtrace();
  7151. int result = FAIL;
  7152. char message[4096]={0};
  7153. char guid[37]={0};
  7154. char tempdata[128]={0};
  7155. json_object *GetCertificateStatus = json_object_new_object();
  7156. json_object *ocspRequestData = json_object_new_object();
  7157. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  7158. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  7159. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  7160. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  7161. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  7162. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  7163. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  7164. random_uuid(guid);
  7165. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  7166. json_object_put(GetCertificateStatus);
  7167. LWS_Send(message);
  7168. sprintf(tempdata, "GetCertificateStatus,0");
  7169. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7170. {
  7171. result = PASS;
  7172. }
  7173. return result;
  7174. }
  7175. int sendHeartbeatRequest()
  7176. {
  7177. mtrace();
  7178. int result = FAIL;
  7179. char message[40096]={0};
  7180. char guid[37]={0};
  7181. char tempdata[128]={0};
  7182. DEBUG_INFO("sendHeartbeatRequest...\n");
  7183. random_uuid(guid);
  7184. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  7185. , MESSAGE_TYPE_CALL
  7186. , guid );
  7187. LWS_Send(message);
  7188. sprintf(tempdata, "Heartbeat,%d", 0);
  7189. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7190. {
  7191. result = PASS;
  7192. }
  7193. return result;
  7194. }
  7195. int sendLogStatusNotificationRequest(char *status)
  7196. {
  7197. mtrace();
  7198. int result = FAIL;
  7199. char message[4096]={0};
  7200. char guid[37]={0};
  7201. char tempdata[128]={0};
  7202. json_object *LogStatusNotification = json_object_new_object();
  7203. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7204. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  7205. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  7206. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  7207. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  7208. random_uuid(guid);
  7209. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7210. json_object_put(LogStatusNotification);
  7211. LWS_SendNow(message);
  7212. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7213. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7214. {
  7215. result = PASS;
  7216. }
  7217. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7218. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  7219. //record status
  7220. if(strcmp(status,"BadMessage")==0)
  7221. {
  7222. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  7223. }
  7224. else if(strcmp(status,"Idle")==0)
  7225. {
  7226. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  7227. }
  7228. else if(strcmp(status,"NotSupportedOperation")==0)
  7229. {
  7230. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  7231. }
  7232. else if(strcmp(status,"PermissionDenied")==0)
  7233. {
  7234. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  7235. }
  7236. else if(strcmp(status,"Uploaded")==0)
  7237. {
  7238. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  7239. }
  7240. else if(strcmp(status,"UploadFailure")==0)
  7241. {
  7242. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  7243. }
  7244. else if(strcmp(status,"Uploading")==0)
  7245. {
  7246. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  7247. }
  7248. return result;
  7249. }
  7250. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  7251. {
  7252. mtrace();
  7253. int result = FAIL;
  7254. char guid[37]={0};
  7255. char tempdata[65]={0};
  7256. int tempIndex = 0;
  7257. json_object *MeterValueReq = json_object_new_object();
  7258. json_object *meterValues = json_object_new_array();
  7259. json_object *sampledValues = json_object_new_array();
  7260. DEBUG_INFO("sendMeterValuesRequest...\n");
  7261. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7262. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  7263. //set value
  7264. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  7265. //UTC Date time
  7266. struct timeval tmnow;
  7267. struct tm *tm;
  7268. char buf[28];//, usec_buf[6];
  7269. gettimeofday(&tmnow, NULL);
  7270. time_t t;
  7271. t = time(NULL);
  7272. /*UTC time and date*/
  7273. tm = gmtime(&t);
  7274. if(dataType == ReadingContextEnumType_Sample_Clock)
  7275. {
  7276. struct tm *tmTarget;
  7277. struct timeb tbTarget;
  7278. tbTarget.time = mktime(tm);
  7279. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  7280. tmTarget = gmtime(&tbTarget.time);
  7281. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7282. }
  7283. else
  7284. {
  7285. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7286. }
  7287. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  7288. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7289. //idx_sample=0;
  7290. //********************************(1)Current.Import L1************************************************/
  7291. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7292. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7293. (dataType == ReadingContextEnumType_Trigger))
  7294. {
  7295. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7296. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7297. {
  7298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7299. {
  7300. tempIndex = ((gun_index==2) ? 1: 0);
  7301. }
  7302. else
  7303. {
  7304. tempIndex = gun_index;
  7305. }
  7306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7309. {
  7310. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent*100))/100.0;
  7311. }
  7312. }
  7313. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7314. }
  7315. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7316. {
  7317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7318. {
  7319. tempIndex = ((gun_index==2) ? 1: 0);
  7320. }
  7321. else
  7322. {
  7323. tempIndex = gun_index;
  7324. }
  7325. for (int index = 0; index < CCS_QUANTITY; index++)
  7326. {
  7327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7328. {
  7329. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent*100))/100.0;
  7330. }
  7331. }
  7332. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7333. }
  7334. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7335. {
  7336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7337. {
  7338. tempIndex = ((gun_index==2) ? 1: 0);
  7339. }
  7340. else
  7341. {
  7342. tempIndex = gun_index;
  7343. }
  7344. for (int index = 0; index < GB_QUANTITY; index++)
  7345. {
  7346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7347. {
  7348. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent*100))/100.0;
  7349. }
  7350. }
  7351. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7352. }
  7353. else if(gunType[gun_index] == GUN_TYPE_DO)
  7354. {
  7355. tempIndex = gun_index;
  7356. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7357. {
  7358. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7359. {
  7360. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent*100))/100.0;
  7361. }
  7362. }
  7363. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7364. }
  7365. else
  7366. {
  7367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7368. {
  7369. tempIndex = 2;
  7370. }
  7371. else
  7372. {
  7373. tempIndex = gun_index;
  7374. }
  7375. for (int index = 0; index < AC_QUANTITY; index++)
  7376. {
  7377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7378. {
  7379. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent*100))/100.0;
  7380. }
  7381. }
  7382. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7383. }
  7384. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  7385. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7386. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7387. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  7388. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  7389. }
  7390. //idx_sample=1;
  7391. //********************************(2)Energy.Active.Import.Register ************************************************/
  7392. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7393. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7394. (dataType == ReadingContextEnumType_Trigger))
  7395. {
  7396. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7397. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7398. {
  7399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7400. {
  7401. tempIndex = ((gun_index==2) ? 1: 0);
  7402. }
  7403. else
  7404. {
  7405. tempIndex = gun_index;
  7406. }
  7407. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7408. {
  7409. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7410. {
  7411. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*100))/100.0;
  7412. }
  7413. }
  7414. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7415. }
  7416. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7417. {
  7418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7419. {
  7420. tempIndex = ((gun_index==2) ? 1: 0);
  7421. }
  7422. else
  7423. {
  7424. tempIndex = gun_index;
  7425. }
  7426. for (int index = 0; index < CCS_QUANTITY; index++)
  7427. {
  7428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7429. {
  7430. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*100))/100.0;
  7431. }
  7432. }
  7433. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7434. }
  7435. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7436. {
  7437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7438. {
  7439. tempIndex = ((gun_index==2) ? 1: 0);
  7440. }
  7441. else
  7442. {
  7443. tempIndex = gun_index;
  7444. }
  7445. for (int index = 0; index < GB_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7448. {
  7449. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*100))/100.0;
  7450. }
  7451. }
  7452. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7453. }
  7454. else if(gunType[gun_index] == GUN_TYPE_DO)
  7455. {
  7456. tempIndex = gun_index;
  7457. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7458. {
  7459. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7460. {
  7461. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*100))/100.0;
  7462. }
  7463. }
  7464. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7465. }
  7466. else
  7467. {
  7468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7469. {
  7470. tempIndex = 2;
  7471. }
  7472. else
  7473. {
  7474. tempIndex = gun_index;
  7475. }
  7476. for (int index = 0; index < AC_QUANTITY; index++)
  7477. {
  7478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7479. {
  7480. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*100))/100.0;
  7481. }
  7482. }
  7483. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7484. }
  7485. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  7486. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  7487. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7488. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  7489. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7490. }
  7491. //idx_sample=2;
  7492. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7493. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7494. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7495. (dataType == ReadingContextEnumType_Trigger))
  7496. {
  7497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7499. {
  7500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7501. {
  7502. tempIndex = ((gun_index==2) ? 1: 0);
  7503. }
  7504. else
  7505. {
  7506. tempIndex = gun_index;
  7507. }
  7508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7509. {
  7510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7511. {
  7512. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*100))/100.0;
  7513. if(dataType == ReadingContextEnumType_Sample_Clock)
  7514. {
  7515. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7516. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7517. }
  7518. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7519. {
  7520. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7521. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7522. }
  7523. else
  7524. {
  7525. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7526. }
  7527. }
  7528. } // END OF FOR CHAdeMO_QUANTITY
  7529. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7530. }
  7531. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7534. {
  7535. tempIndex = ((gun_index==2) ? 1: 0);
  7536. }
  7537. else
  7538. {
  7539. tempIndex = gun_index;
  7540. }
  7541. for (int index = 0; index < CCS_QUANTITY; index++)
  7542. {
  7543. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7544. {
  7545. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*100))/100.0;
  7546. if(dataType == ReadingContextEnumType_Sample_Clock)
  7547. {
  7548. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7549. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7550. }
  7551. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7552. {
  7553. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7554. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7555. }
  7556. else
  7557. {
  7558. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7559. }
  7560. }
  7561. } // END OF CCS_QUANTITY
  7562. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7563. }
  7564. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7565. {
  7566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7567. {
  7568. tempIndex = ((gun_index==2) ? 1: 0);
  7569. }
  7570. else
  7571. {
  7572. tempIndex = gun_index;
  7573. }
  7574. for (int index = 0; index < GB_QUANTITY; index++)
  7575. {
  7576. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7577. {
  7578. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*100))/100.0;
  7579. if(dataType == ReadingContextEnumType_Sample_Clock)
  7580. {
  7581. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7582. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7583. }
  7584. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7585. {
  7586. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7587. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7588. }
  7589. else
  7590. {
  7591. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7592. }
  7593. }
  7594. } // END OF GB_QUANTITY
  7595. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7596. }
  7597. else if(gunType[gun_index] == GUN_TYPE_DO)
  7598. {
  7599. tempIndex = gun_index;
  7600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7601. {
  7602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7603. {
  7604. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*100))/100.0;
  7605. if(dataType == ReadingContextEnumType_Sample_Clock)
  7606. {
  7607. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]);
  7608. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7609. }
  7610. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7611. {
  7612. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7613. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7614. }
  7615. else
  7616. {
  7617. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7618. }
  7619. }
  7620. }
  7621. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7622. }
  7623. else
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7626. {
  7627. tempIndex = 2;
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < AC_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7636. {
  7637. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*100))/100.0;
  7638. if(dataType == ReadingContextEnumType_Sample_Clock)
  7639. {
  7640. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7641. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7642. }
  7643. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7644. {
  7645. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7646. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7647. }
  7648. else
  7649. {
  7650. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7651. }
  7652. }
  7653. }
  7654. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7655. }
  7656. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  7657. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  7658. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7659. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  7660. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7661. }
  7662. //idx_sample=3;
  7663. //********************************(4)Power.Active.Import************************************************/
  7664. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7665. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7666. (dataType == ReadingContextEnumType_Trigger))
  7667. {
  7668. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7669. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7670. {
  7671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7672. {
  7673. tempIndex = ((gun_index==2) ? 1: 0);
  7674. }
  7675. else
  7676. {
  7677. tempIndex = gun_index;
  7678. }
  7679. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7682. {
  7683. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower*100))/100.0;
  7684. }
  7685. } // END OF FOR
  7686. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7687. }
  7688. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7689. {
  7690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7691. {
  7692. tempIndex = ((gun_index==2) ? 1: 0);
  7693. }
  7694. else
  7695. {
  7696. tempIndex = gun_index;
  7697. }
  7698. for (int index = 0; index < CCS_QUANTITY; index++)
  7699. {
  7700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7701. {
  7702. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower*100))/100.0;
  7703. }
  7704. }
  7705. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7706. }
  7707. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7708. {
  7709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7710. {
  7711. tempIndex = ((gun_index==2) ? 1: 0);
  7712. }
  7713. else
  7714. {
  7715. tempIndex = gun_index;
  7716. }
  7717. for (int index = 0; index < GB_QUANTITY; index++)
  7718. {
  7719. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7720. {
  7721. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7722. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower*100))/100.0;
  7723. }
  7724. }
  7725. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7726. }
  7727. else if(gunType[gun_index] == GUN_TYPE_DO)
  7728. {
  7729. tempIndex = gun_index;
  7730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7731. {
  7732. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7733. {
  7734. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7735. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower*100))/100.0;
  7736. }
  7737. }
  7738. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7739. }
  7740. else
  7741. {
  7742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7743. {
  7744. tempIndex = 2;
  7745. }
  7746. else
  7747. {
  7748. tempIndex = gun_index;
  7749. }
  7750. for (int index = 0; index < AC_QUANTITY; index++)
  7751. {
  7752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7753. {
  7754. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower*100))/100.0;
  7755. }
  7756. }
  7757. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7758. }
  7759. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  7760. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  7761. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7762. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  7763. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  7764. }
  7765. //idx_sample=4;
  7766. //***********************************************(5)VOLTAGE L1******************************************************/
  7767. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7768. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7769. (dataType == ReadingContextEnumType_Trigger))
  7770. {
  7771. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7772. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7773. {
  7774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7775. {
  7776. tempIndex = ((gun_index==2) ? 1: 0);
  7777. }
  7778. else
  7779. {
  7780. tempIndex = gun_index;
  7781. }
  7782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7783. {
  7784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7785. {
  7786. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage*100))/100.0;
  7787. }
  7788. }
  7789. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7790. }
  7791. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7792. {
  7793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7794. {
  7795. tempIndex = ((gun_index==2) ? 1: 0);
  7796. }
  7797. else
  7798. {
  7799. tempIndex = gun_index;
  7800. }
  7801. for (int index = 0; index < CCS_QUANTITY; index++)
  7802. {
  7803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7804. {
  7805. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage*100))/100.0;
  7806. }
  7807. }
  7808. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7809. }
  7810. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7811. {
  7812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7813. {
  7814. tempIndex = ((gun_index==2) ? 1: 0);
  7815. }
  7816. else
  7817. {
  7818. tempIndex = gun_index;
  7819. }
  7820. for (int index = 0; index < GB_QUANTITY; index++)
  7821. {
  7822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7823. {
  7824. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage*100))/100.0;
  7825. }
  7826. }
  7827. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7828. }
  7829. else if(gunType[gun_index] == GUN_TYPE_DO)
  7830. {
  7831. tempIndex = gun_index;
  7832. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7833. {
  7834. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7835. {
  7836. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage*100))/100.0;
  7837. }
  7838. }
  7839. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7840. }
  7841. else
  7842. {
  7843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7844. {
  7845. tempIndex = 2;
  7846. }
  7847. else
  7848. {
  7849. tempIndex = gun_index;
  7850. }
  7851. for (int index = 0; index < AC_QUANTITY; index++)
  7852. {
  7853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7854. {
  7855. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage*100))/100.0;
  7856. }
  7857. }
  7858. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7859. }
  7860. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  7861. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7862. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7863. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  7864. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  7865. }
  7866. //***********************************************(6)SOC******************************************************/
  7867. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  7868. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  7869. (dataType == ReadingContextEnumType_Trigger))
  7870. {
  7871. 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))
  7872. {
  7873. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7874. {
  7875. tempIndex = ((gun_index==2) ? 1: 0);
  7876. }
  7877. else
  7878. {
  7879. tempIndex = gun_index;
  7880. }
  7881. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7882. {
  7883. //tempIndex = ((gun_index==2) ? 1: 0);
  7884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7885. {
  7886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7887. {
  7888. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  7889. }
  7890. }
  7891. }
  7892. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7893. {
  7894. //tempIndex = ((gun_index==2) ? 1: 0);
  7895. for (int index = 0; index < CCS_QUANTITY; index++)
  7896. {
  7897. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7898. {
  7899. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  7900. }
  7901. }
  7902. }
  7903. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7904. {
  7905. //tempIndex = ((gun_index==2) ? 1: 0);
  7906. for (int index = 0; index < GB_QUANTITY; index++)
  7907. {
  7908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7909. {
  7910. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  7911. }
  7912. }
  7913. }
  7914. else if(gunType[gun_index] == GUN_TYPE_DO)
  7915. {
  7916. //tempIndex = ((gun_index==2) ? 1: 0);
  7917. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7918. {
  7919. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7920. {
  7921. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  7922. }
  7923. }
  7924. }
  7925. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  7926. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  7927. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7928. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  7929. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  7930. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  7931. }
  7932. }
  7933. //********************************(7)Current.Import L2************************************************/
  7934. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7935. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7936. (dataType == ReadingContextEnumType_Trigger))
  7937. {
  7938. // Only for AC 3 phase
  7939. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7940. {
  7941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7942. {
  7943. tempIndex = 2;
  7944. }
  7945. else
  7946. {
  7947. tempIndex = gun_index;
  7948. }
  7949. for (int index = 0; index < AC_QUANTITY; index++)
  7950. {
  7951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7952. {
  7953. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2*100))/100.0;
  7954. }
  7955. }
  7956. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  7957. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  7958. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7959. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7960. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  7961. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  7962. }
  7963. }
  7964. //********************************(8)Current.Import L3************************************************/
  7965. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7966. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7967. (dataType == ReadingContextEnumType_Trigger))
  7968. {
  7969. // Only for AC 3 phase
  7970. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7971. {
  7972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7973. {
  7974. tempIndex = 2;
  7975. }
  7976. else
  7977. {
  7978. tempIndex = gun_index;
  7979. }
  7980. for (int index = 0; index < AC_QUANTITY; index++)
  7981. {
  7982. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7983. {
  7984. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3*100))/100.0;
  7985. }
  7986. }
  7987. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7988. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  7989. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7990. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7991. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  7992. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  7993. }
  7994. }
  7995. //***********************************************(9)VOLTAGE L2******************************************************/
  7996. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7997. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7998. (dataType == ReadingContextEnumType_Trigger))
  7999. {
  8000. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8001. {
  8002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8003. {
  8004. tempIndex = 2;
  8005. }
  8006. else
  8007. {
  8008. tempIndex = gun_index;
  8009. }
  8010. for (int index = 0; index < AC_QUANTITY; index++)
  8011. {
  8012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8013. {
  8014. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2*100))/100.0;
  8015. }
  8016. }
  8017. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8018. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8019. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8020. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8021. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8022. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8023. }
  8024. }
  8025. //***********************************************(10)VOLTAGE L3******************************************************/
  8026. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8027. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8028. (dataType == ReadingContextEnumType_Trigger))
  8029. {
  8030. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8031. {
  8032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8033. {
  8034. tempIndex = 2;
  8035. }
  8036. else
  8037. {
  8038. tempIndex = gun_index;
  8039. }
  8040. for (int index = 0; index < AC_QUANTITY; index++)
  8041. {
  8042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8043. {
  8044. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3*100))/100.0;
  8045. }
  8046. }
  8047. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8048. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8049. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8050. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8051. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8052. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8053. }
  8054. }
  8055. //***********************************************(11)Current.Offered******************************************************/
  8056. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8057. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8058. (dataType == ReadingContextEnumType_Trigger))
  8059. {
  8060. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8061. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8062. {
  8063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8064. {
  8065. tempIndex = ((gun_index==2) ? 1: 0);
  8066. }
  8067. else
  8068. {
  8069. tempIndex = gun_index;
  8070. }
  8071. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8072. {
  8073. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8074. {
  8075. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10);
  8076. }
  8077. } // END OF FOR
  8078. }
  8079. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8080. {
  8081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8082. {
  8083. tempIndex = ((gun_index==2) ? 1: 0);
  8084. }
  8085. else
  8086. {
  8087. tempIndex = gun_index;
  8088. }
  8089. for (int index = 0; index < CCS_QUANTITY; index++)
  8090. {
  8091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8092. {
  8093. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10);
  8094. }
  8095. }
  8096. }
  8097. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8098. {
  8099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8100. {
  8101. tempIndex = ((gun_index==2) ? 1: 0);
  8102. }
  8103. else
  8104. {
  8105. tempIndex = gun_index;
  8106. }
  8107. for (int index = 0; index < GB_QUANTITY; index++)
  8108. {
  8109. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8110. {
  8111. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8112. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10);;
  8113. }
  8114. }
  8115. }
  8116. else if(gunType[gun_index] == GUN_TYPE_DO)
  8117. {
  8118. tempIndex = gun_index;
  8119. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8120. {
  8121. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8122. {
  8123. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8124. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10);;
  8125. }
  8126. }
  8127. }
  8128. else
  8129. {
  8130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8131. {
  8132. tempIndex = 2;
  8133. }
  8134. else
  8135. {
  8136. tempIndex = gun_index;
  8137. }
  8138. for (int index = 0; index < AC_QUANTITY; index++)
  8139. {
  8140. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8141. {
  8142. uint16_t currentOffer;
  8143. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8144. {
  8145. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8146. }
  8147. else
  8148. {
  8149. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8150. }
  8151. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8152. }
  8153. }
  8154. }
  8155. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8156. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8157. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8158. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8159. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8160. }
  8161. //***********************************************(12)Power.Offered******************************************************/
  8162. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8163. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8164. (dataType == ReadingContextEnumType_Trigger))
  8165. {
  8166. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8167. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8168. {
  8169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8170. {
  8171. tempIndex = ((gun_index==2) ? 1: 0);
  8172. }
  8173. else
  8174. {
  8175. tempIndex = gun_index;
  8176. }
  8177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8178. {
  8179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8180. {
  8181. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100);
  8182. }
  8183. } // END OF FOR
  8184. }
  8185. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8186. {
  8187. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8188. {
  8189. tempIndex = ((gun_index==2) ? 1: 0);
  8190. }
  8191. else
  8192. {
  8193. tempIndex = gun_index;
  8194. }
  8195. for (int index = 0; index < CCS_QUANTITY; index++)
  8196. {
  8197. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8198. {
  8199. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100);
  8200. }
  8201. }
  8202. }
  8203. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8204. {
  8205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8206. {
  8207. tempIndex = ((gun_index==2) ? 1: 0);
  8208. }
  8209. else
  8210. {
  8211. tempIndex = gun_index;
  8212. }
  8213. for (int index = 0; index < GB_QUANTITY; index++)
  8214. {
  8215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8216. {
  8217. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8218. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100);
  8219. }
  8220. }
  8221. }
  8222. else if(gunType[gun_index] == GUN_TYPE_DO)
  8223. {
  8224. tempIndex = gun_index;
  8225. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8226. {
  8227. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8228. {
  8229. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8230. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100);
  8231. }
  8232. }
  8233. }
  8234. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8235. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8236. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8237. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8238. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8239. }
  8240. // Message create ====================================================================================================
  8241. random_uuid(guid);
  8242. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8243. {
  8244. json_object *meterValue = json_object_new_object();
  8245. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8246. {
  8247. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8248. {
  8249. json_object *sampledValue = json_object_new_object();
  8250. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8251. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8252. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8253. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8254. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8255. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8256. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8257. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8258. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8259. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8260. {
  8261. json_object *unitOfMeasure = json_object_new_object();
  8262. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8263. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8264. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8265. }
  8266. json_object_array_add(sampledValues, sampledValue);
  8267. }
  8268. }
  8269. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8270. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8271. json_object_array_add(meterValues, meterValue);
  8272. idxMeter++;
  8273. }
  8274. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8275. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8276. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8277. ,MESSAGE_TYPE_CALL
  8278. ,guid
  8279. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8280. json_object_put(MeterValueReq);
  8281. if((dataType != ReadingContextEnumType_Trigger) &&
  8282. (dataType != ReadingContextEnumType_Sample_Clock))
  8283. {
  8284. // Transaction meter value send by TransactionEvent message
  8285. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8286. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8287. result = PASS;
  8288. }
  8289. else
  8290. {
  8291. // Put request guid to hash map
  8292. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8293. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8294. {
  8295. result = PASS;
  8296. }
  8297. if((dataType != ReadingContextEnumType_Trigger) &&
  8298. (dataType != ReadingContextEnumType_Sample_Clock))
  8299. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8300. else
  8301. {
  8302. if(FirstHeartBeat)
  8303. LWS_Send(queuedata);
  8304. }
  8305. }
  8306. return result;
  8307. }
  8308. int sendNotifyChargingLimitRequest(int gun_index)
  8309. {
  8310. mtrace();
  8311. int result = FAIL;
  8312. char message[4096]={0};
  8313. char guid[37]={0};
  8314. char tempdata[128]={0};
  8315. json_object *NotifyChargingLimit = json_object_new_object();
  8316. json_object *chargingLimit = json_object_new_object();
  8317. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8318. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8319. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8320. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8321. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8322. random_uuid(guid);
  8323. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8324. json_object_put(NotifyChargingLimit);
  8325. LWS_Send(message);
  8326. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8327. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8328. {
  8329. result = PASS;
  8330. }
  8331. return result;
  8332. }
  8333. int sendNotifyCustomerInformationRequest()
  8334. {
  8335. mtrace();
  8336. int result = FAIL;
  8337. char message[4096]={0};
  8338. char guid[37]={0};
  8339. char tempdata[128]={0};
  8340. json_object *NotifyCustomerInformation = json_object_new_object();
  8341. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8342. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8343. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8344. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8345. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8346. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8347. random_uuid(guid);
  8348. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8349. json_object_put(NotifyCustomerInformation);
  8350. LWS_Send(message);
  8351. sprintf(tempdata, "NotifyCustomerInformation,0");
  8352. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8353. {
  8354. result = PASS;
  8355. }
  8356. return result;
  8357. }
  8358. int sendNotifyDisplayMessagesRequest()
  8359. {
  8360. mtrace();
  8361. int result = FAIL;
  8362. char message[4096]={0};
  8363. char guid[37]={0};
  8364. char tempdata[128]={0};
  8365. json_object *NotifyDisplayMessages = json_object_new_object();
  8366. json_object *messageInfos = json_object_new_array();
  8367. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8368. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8369. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8370. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8371. {
  8372. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8373. {
  8374. json_object *messageInfo = json_object_new_object();
  8375. json_object *message = json_object_new_object();
  8376. json_object *display = json_object_new_object();
  8377. json_object *evse = json_object_new_object();
  8378. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8379. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8380. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8381. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8382. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8383. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8384. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8385. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8386. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8387. json_object_object_add(messageInfo, "message", message);
  8388. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8389. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8390. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8391. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8392. json_object_object_add(display, "evse",evse);
  8393. json_object_object_add(messageInfo, "evse", display);
  8394. json_object_array_add(messageInfos, messageInfo);
  8395. }
  8396. }
  8397. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8398. random_uuid(guid);
  8399. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8400. json_object_put(NotifyDisplayMessages);
  8401. LWS_Send(message);
  8402. sprintf(tempdata, "NotifyDisplayMessages,0");
  8403. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8404. {
  8405. result = PASS;
  8406. }
  8407. return result;
  8408. }
  8409. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8410. {
  8411. mtrace();
  8412. int result = FAIL;
  8413. char message[4096]={0};
  8414. char guid[37]={0};
  8415. char tempdata[128]={0};
  8416. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8417. json_object *chargingNeeds = json_object_new_object();
  8418. json_object *acChargingParameters = json_object_new_object();
  8419. json_object *dcChargingParameters = json_object_new_object();
  8420. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8421. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8422. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8423. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8424. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8425. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8426. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8427. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8428. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8429. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8430. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8431. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8432. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8433. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8434. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8435. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8436. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8437. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8438. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8439. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8440. random_uuid(guid);
  8441. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8442. json_object_put(NotifyEVChargingNeeds);
  8443. LWS_Send(message);
  8444. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8445. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8446. {
  8447. result = PASS;
  8448. }
  8449. return result;
  8450. }
  8451. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8452. {
  8453. mtrace();
  8454. int result = FAIL;
  8455. char message[4096]={0};
  8456. char guid[37]={0};
  8457. char tempdata[128]={0};
  8458. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8459. json_object *chargingSchedule = json_object_new_object();
  8460. json_object *periods = json_object_new_array();
  8461. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8462. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8463. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8464. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8465. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8466. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8467. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8468. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8470. {
  8471. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8472. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8473. {
  8474. json_object *Period = json_object_new_object();
  8475. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8476. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8477. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8478. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8479. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8480. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8481. json_object_array_add(periods, Period);
  8482. }
  8483. }
  8484. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8485. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8486. random_uuid(guid);
  8487. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8488. json_object_put(NotifyEVChargingSchedule);
  8489. LWS_Send(message);
  8490. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8491. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8492. {
  8493. result = PASS;
  8494. }
  8495. return result;
  8496. }
  8497. int sendNotifyEventRequest()
  8498. {
  8499. mtrace();
  8500. int result = FAIL;
  8501. char message[4096]={0};
  8502. char guid[37]={0};
  8503. char tempdata[128]={0};
  8504. json_object *NotifyEvent = json_object_new_object();
  8505. json_object *eventDatas = json_object_new_array();
  8506. DEBUG_INFO("sendNotifyEventRequest...\n");
  8507. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8508. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8509. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8510. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8511. {
  8512. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8513. {
  8514. json_object *eventData = json_object_new_object();
  8515. json_object *component = json_object_new_object();
  8516. json_object *evse = json_object_new_object();
  8517. json_object *variable = json_object_new_object();
  8518. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8519. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8520. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8521. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8522. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8523. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8524. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8525. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8526. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8527. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8528. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8529. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8530. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8531. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8532. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8533. json_object_object_add(component, "evse",evse);
  8534. json_object_object_add(eventData, "component", component);
  8535. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8536. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8537. json_object_object_add(eventData, "variable", variable);
  8538. json_object_array_add(eventDatas, eventData);
  8539. }
  8540. }
  8541. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8542. random_uuid(guid);
  8543. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8544. json_object_put(NotifyEvent);
  8545. LWS_Send(message);
  8546. sprintf(tempdata, "NotifyEvent,0");
  8547. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8548. {
  8549. result = PASS;
  8550. }
  8551. return result;
  8552. }
  8553. int sendNotifyMonitoringReportRequest()
  8554. {
  8555. mtrace();
  8556. int result = FAIL;
  8557. char message[4096]={0};
  8558. char guid[37]={0};
  8559. char tempdata[128]={0};
  8560. json_object *NotifyMonitoringReport = json_object_new_object();
  8561. json_object *monitors = json_object_new_array();
  8562. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8563. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8564. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8565. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8566. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8567. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8568. {
  8569. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8570. {
  8571. json_object *monitor = json_object_new_object();
  8572. json_object *component = json_object_new_object();
  8573. json_object *evse = json_object_new_object();
  8574. json_object *variable = json_object_new_object();
  8575. json_object *variableMonitorings = json_object_new_array();
  8576. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8577. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8578. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8579. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8580. json_object_object_add(component, "evse",evse);
  8581. json_object_object_add(monitor, "component", component);
  8582. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8583. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8584. json_object_object_add(monitor, "variable", variable);
  8585. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8586. {
  8587. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8588. {
  8589. json_object *variableMonitoring = json_object_new_object();
  8590. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8591. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8592. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8593. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8594. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8595. json_object_array_add(variableMonitorings, variableMonitoring);
  8596. }
  8597. }
  8598. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8599. json_object_array_add(monitors, monitor);
  8600. }
  8601. }
  8602. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8603. random_uuid(guid);
  8604. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8605. json_object_put(NotifyMonitoringReport);
  8606. LWS_Send(message);
  8607. sprintf(tempdata, "NotifyMonitoringReport,0");
  8608. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8609. {
  8610. result = PASS;
  8611. }
  8612. return result;
  8613. }
  8614. int sendNotifyReportRequest()
  8615. {
  8616. mtrace();
  8617. int result = FAIL;
  8618. char message[4096]={0};
  8619. char guid[37]={0};
  8620. char tempdata[128]={0};
  8621. json_object *NotifyReport = json_object_new_object();
  8622. json_object *reportDatas = json_object_new_array();
  8623. DEBUG_INFO("sendNotifyReportRequest...\n");
  8624. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8625. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8626. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8627. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8628. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8629. {
  8630. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8631. {
  8632. json_object *reportData = json_object_new_object();
  8633. json_object *component = json_object_new_object();
  8634. json_object *evse = json_object_new_object();
  8635. json_object *variable = json_object_new_object();
  8636. json_object *variableAttributes = json_object_new_array();
  8637. json_object *variableCharacteristics = json_object_new_object();
  8638. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8639. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8640. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8641. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8642. json_object_object_add(component, "evse",evse);
  8643. json_object_object_add(reportData, "component", component);
  8644. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8645. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8646. json_object_object_add(reportData, "variable",variable);
  8647. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  8648. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  8649. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  8650. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  8651. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  8652. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  8653. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  8654. {
  8655. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  8656. {
  8657. json_object *variableAttribute = json_object_new_object();
  8658. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  8659. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  8660. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  8661. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  8662. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  8663. json_object_array_add(variableAttributes, variableAttribute);
  8664. }
  8665. }
  8666. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  8667. json_object_array_add(reportDatas, reportData);
  8668. }
  8669. }
  8670. json_object_object_add(NotifyReport, "reportData", reportDatas);
  8671. random_uuid(guid);
  8672. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  8673. json_object_put(NotifyReport);
  8674. LWS_SendNow(message);
  8675. sprintf(tempdata, "NotifyReport,0");
  8676. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8677. {
  8678. result = PASS;
  8679. }
  8680. return result;
  8681. }
  8682. int sendPublishFirmwareStatusNotificationRequest()
  8683. {
  8684. mtrace();
  8685. int result = FAIL;
  8686. char message[4096]={0};
  8687. char guid[37]={0};
  8688. char tempdata[128]={0};
  8689. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  8690. json_object *locations = json_object_new_array();
  8691. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  8692. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  8693. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  8694. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  8695. {
  8696. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  8697. }
  8698. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  8699. random_uuid(guid);
  8700. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8701. json_object_put(PublishFirmwareStatusNotification);
  8702. LWS_Send(message);
  8703. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  8704. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8705. {
  8706. result = PASS;
  8707. }
  8708. return result;
  8709. }
  8710. int sendReportChargingProfilesRequest(int gun_index)
  8711. {
  8712. mtrace();
  8713. int result = FAIL;
  8714. char message[4096]={0};
  8715. char guid[37]={0};
  8716. char tempdata[128]={0};
  8717. json_object *ReportChargingProfiles = json_object_new_object();
  8718. json_object *chargingProfiles = json_object_new_array();
  8719. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  8720. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  8721. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  8722. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  8723. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  8724. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  8725. {
  8726. json_object *chargingProfile = json_object_new_object();
  8727. json_object *chargingSchedules = json_object_new_array();
  8728. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  8729. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  8730. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  8731. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  8732. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  8733. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  8734. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  8735. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  8736. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  8737. {
  8738. json_object *chargingSchedule = json_object_new_object();
  8739. json_object *chargingSchedulePeriods = json_object_new_array();
  8740. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  8741. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  8742. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  8743. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  8744. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  8745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  8746. {
  8747. json_object *chargingSchedulePeriod = json_object_new_object();
  8748. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  8749. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  8750. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  8751. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  8752. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  8753. }
  8754. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  8755. json_object_array_add(chargingSchedules, chargingSchedule);
  8756. }
  8757. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  8758. json_object_array_add(chargingProfiles, chargingProfile);
  8759. }
  8760. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  8761. random_uuid(guid);
  8762. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8763. json_object_put(ReportChargingProfiles);
  8764. LWS_Send(message);
  8765. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  8766. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8767. {
  8768. result = PASS;
  8769. }
  8770. return result;
  8771. }
  8772. int sendReservationStatusUpdateRequest(int gun_index)
  8773. {
  8774. mtrace();
  8775. int result = FAIL;
  8776. char message[4096]={0};
  8777. char guid[37]={0};
  8778. char tempdata[128]={0};
  8779. json_object *ReservationStatusUpdate = json_object_new_object();
  8780. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  8781. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  8782. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  8783. random_uuid(guid);
  8784. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  8785. json_object_put(ReservationStatusUpdate);
  8786. LWS_Send(message);
  8787. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  8788. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8789. {
  8790. result = PASS;
  8791. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  8792. }
  8793. return result;
  8794. }
  8795. int sendSecurityEventNotificationRequest()
  8796. {
  8797. mtrace();
  8798. int result = FAIL;
  8799. char message[4096]={0};
  8800. char guid[37]={0};
  8801. char tempdata[128]={0};
  8802. struct timeval tmnow;
  8803. struct tm *tm;
  8804. char buf[28];//, usec_buf[6];
  8805. json_object *SecurityEventNotification = json_object_new_object();
  8806. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8807. DB_getSecurityEventType();
  8808. gettimeofday(&tmnow, NULL);
  8809. time_t t;
  8810. t = time(NULL);
  8811. /*UTC time and date*/
  8812. tm = gmtime(&t);
  8813. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8814. #if 0 // remove temporally
  8815. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  8816. strcat(buf,".");
  8817. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  8818. strcat(buf,usec_buf);
  8819. #endif
  8820. printf("%s",buf);
  8821. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  8822. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  8823. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  8824. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  8825. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  8826. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  8827. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  8828. random_uuid(guid);
  8829. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8830. json_object_put(SecurityEventNotification);
  8831. LWS_Send(message);
  8832. sprintf(tempdata, "SecurityEventNotification,0");
  8833. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8834. {
  8835. result = PASS;
  8836. }
  8837. return result;
  8838. }
  8839. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  8840. {
  8841. mtrace();
  8842. int result = FAIL;
  8843. char message[4096]={0};
  8844. char guid[37]={0};
  8845. char tempdata[128]={0};
  8846. json_object *SignCertificate = json_object_new_object();
  8847. DEBUG_INFO("sendSignCertificateRequest...\n");
  8848. // Read csr file content
  8849. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  8850. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  8851. char *line = NULL;
  8852. size_t len = 0;
  8853. while(getline(&line, &len, fp) != -1)
  8854. {
  8855. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8856. {
  8857. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  8858. }
  8859. }
  8860. fclose(fp);
  8861. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  8862. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  8863. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  8864. random_uuid(guid);
  8865. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8866. json_object_put(SignCertificate);
  8867. LWS_Send(message);
  8868. sprintf(tempdata, "SignCertificate,0");
  8869. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8870. {
  8871. result = PASS;
  8872. }
  8873. return result;
  8874. }
  8875. int sendStatusNotificationRequest(int gun_index)
  8876. {
  8877. mtrace();
  8878. int result = FAIL;
  8879. char message[600]={0};
  8880. char guid[37];
  8881. int currentStatus = 0;
  8882. struct timeval tmnow;
  8883. struct tm *tm;
  8884. char buf[28];//, usec_buf[6];
  8885. char tempdata[65]={0};
  8886. int tempIndex = 0;
  8887. uint8_t isStateChanged = TRUE;
  8888. DEBUG_INFO("sendStatusNotificationRequest...\n");
  8889. gettimeofday(&tmnow, NULL);
  8890. time_t t;
  8891. t = time(NULL);
  8892. /*UTC time and date*/
  8893. tm = gmtime(&t);
  8894. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8895. #if 0 // remove temporally
  8896. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  8897. strcat(buf,".");
  8898. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  8899. strcat(buf,usec_buf);
  8900. #endif
  8901. printf("%s",buf);
  8902. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  8903. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  8904. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  8905. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  8906. /*
  8907. enum _SYSTEM_STATUS
  8908. {
  8909. S_BOOTING = 0,
  8910. S_IDLE, = 1
  8911. S_AUTHORIZING, =2
  8912. S_REASSIGN_CHECK, =3
  8913. S_REASSIGN, =4
  8914. S_PRECHARGE, =5
  8915. S_PREPARING_FOR_EV, =6
  8916. S_PREPARING_FOR_EVSE, =7
  8917. S_CHARGING, =8
  8918. S_TERMINATING, =9
  8919. S_COMPLETE, =10
  8920. S_ALARM, =11
  8921. S_FAULT =12
  8922. }
  8923. */
  8924. //check Transaction active
  8925. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  8926. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8927. {
  8928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8929. {
  8930. tempIndex = ((gun_index==2) ? 1: 0);
  8931. }
  8932. else
  8933. {
  8934. tempIndex = gun_index;
  8935. }
  8936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8937. {
  8938. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  8939. {
  8940. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  8941. {
  8942. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8943. {
  8944. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8945. }
  8946. else
  8947. {
  8948. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8949. }
  8950. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8951. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8952. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8953. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8954. }
  8955. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8956. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8957. ) //S_PRECHARGE
  8958. {
  8959. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8960. }
  8961. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8962. {
  8963. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8964. }
  8965. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8966. {
  8967. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8968. }
  8969. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8970. {
  8971. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8972. }
  8973. 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
  8974. {
  8975. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8976. }
  8977. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8978. {
  8979. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8980. }
  8981. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8982. {
  8983. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8984. }
  8985. } //end of the same index
  8986. }//end of for CHAdeMO_QUANTITY
  8987. }
  8988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8989. {
  8990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8991. {
  8992. tempIndex = ((gun_index==2) ? 1: 0);
  8993. }
  8994. else
  8995. {
  8996. tempIndex = gun_index;
  8997. }
  8998. for (int index = 0; index < CCS_QUANTITY; index++)
  8999. {
  9000. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9001. {
  9002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9003. {
  9004. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9005. {
  9006. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9007. }
  9008. else
  9009. {
  9010. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9011. }
  9012. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9013. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9014. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9015. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9016. }
  9017. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9018. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9019. ) //S_PRECHARGE
  9020. {
  9021. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9022. }
  9023. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9024. {
  9025. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9026. }
  9027. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9028. {
  9029. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9030. }
  9031. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9032. {
  9033. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9034. }
  9035. 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
  9036. {
  9037. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9038. }
  9039. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9040. {
  9041. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9042. }
  9043. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9044. {
  9045. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9046. }
  9047. } //end of the same index
  9048. } // end of for CCS_QUANTITY
  9049. }
  9050. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9051. {
  9052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9053. {
  9054. tempIndex = ((gun_index==2) ? 1: 0);
  9055. }
  9056. else
  9057. {
  9058. tempIndex = gun_index;
  9059. }
  9060. for (int index = 0; index < GB_QUANTITY; index++)
  9061. {
  9062. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9063. {
  9064. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9065. {
  9066. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9067. {
  9068. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9069. }
  9070. else
  9071. {
  9072. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9073. }
  9074. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9075. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9076. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9077. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9078. }
  9079. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9080. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9081. ) //S_PRECHARGE
  9082. {
  9083. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9084. }
  9085. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9086. {
  9087. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9088. }
  9089. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9090. {
  9091. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9092. }
  9093. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9094. {
  9095. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9096. }
  9097. 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
  9098. {
  9099. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9100. }
  9101. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9102. {
  9103. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9104. }
  9105. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9106. {
  9107. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9108. }
  9109. } //end of the same index
  9110. } // end of for GB_QUANTITY
  9111. }
  9112. else if(gunType[gun_index] == GUN_TYPE_DO)
  9113. {
  9114. tempIndex = gun_index;
  9115. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9116. {
  9117. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9118. {
  9119. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9120. {
  9121. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9122. {
  9123. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9124. }
  9125. else
  9126. {
  9127. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9128. }
  9129. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9130. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9131. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9132. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9133. }
  9134. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9135. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9136. ) //S_PRECHARGE
  9137. {
  9138. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9139. }
  9140. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9141. {
  9142. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9143. }
  9144. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9145. {
  9146. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9147. }
  9148. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9149. {
  9150. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9151. }
  9152. 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
  9153. {
  9154. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9155. }
  9156. 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
  9157. {
  9158. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9159. }
  9160. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9161. {
  9162. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9163. }
  9164. } //end of the same index
  9165. }
  9166. }
  9167. else
  9168. {
  9169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9170. {
  9171. tempIndex = 2;
  9172. }
  9173. else
  9174. {
  9175. tempIndex = gun_index;
  9176. }
  9177. for (int index = 0; index < AC_QUANTITY; index++)
  9178. {
  9179. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9180. {
  9181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9182. {
  9183. 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))
  9184. {
  9185. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9186. }
  9187. else
  9188. {
  9189. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9190. }
  9191. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9192. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9193. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9194. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9195. }
  9196. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9197. {
  9198. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9199. }
  9200. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9201. {
  9202. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9203. }
  9204. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9205. {
  9206. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9207. }
  9208. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9209. {
  9210. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9211. }
  9212. 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
  9213. {
  9214. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9215. }
  9216. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9217. {
  9218. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9219. }
  9220. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9221. {
  9222. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9223. }
  9224. }//end of the same index
  9225. }//end of for AC_QUANTITY
  9226. }
  9227. //it's option
  9228. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9229. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9230. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "TRUE") != 0))
  9231. {
  9232. isStateChanged = FALSE;
  9233. }
  9234. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9235. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9236. random_uuid(guid);
  9237. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9238. , MESSAGE_TYPE_CALL
  9239. , guid
  9240. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9241. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9242. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9243. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9244. if((server_sign == TRUE) && isStateChanged)
  9245. {
  9246. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9247. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9248. LWS_Send(message);
  9249. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9250. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9251. {
  9252. result = PASS;
  9253. }
  9254. }
  9255. else
  9256. {
  9257. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9258. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9259. result = PASS;
  9260. }
  9261. return result;
  9262. }
  9263. int sendTransactionEventRequest(int gun_index)
  9264. {
  9265. mtrace();
  9266. int result = FAIL;
  9267. char message[1024*20]={0};
  9268. char guid[37]={0};
  9269. char tempdata[128]={0};
  9270. uint8_t tempIndex;
  9271. json_object *TransactionEvent = json_object_new_object();
  9272. json_object *transactionInfo = json_object_new_object();
  9273. json_object *idToken = json_object_new_object();
  9274. json_object *evse = json_object_new_object();
  9275. json_object *meterValues = json_object_new_array();
  9276. char TempStopTransaction[256];
  9277. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9278. DEBUG_INFO("sendTransactionEventRequest...\n");
  9279. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9280. {
  9281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9282. {
  9283. tempIndex = ((gun_index==2) ? 1: 0);
  9284. }
  9285. else
  9286. {
  9287. tempIndex = gun_index;
  9288. }
  9289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9290. {
  9291. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9292. {
  9293. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9294. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9295. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9296. else
  9297. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9298. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9299. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9300. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9301. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9302. {
  9303. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9304. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9305. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9306. {
  9307. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9308. }
  9309. else
  9310. {
  9311. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9312. }
  9313. }
  9314. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9315. {
  9316. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9317. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9318. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9319. }
  9320. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9321. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9322. ) //S_PRECHARGE
  9323. {
  9324. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9325. {
  9326. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9327. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9328. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9329. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9330. }
  9331. else
  9332. {
  9333. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9334. }
  9335. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9336. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9337. }
  9338. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9339. {
  9340. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9341. {
  9342. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9343. {
  9344. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9345. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9346. }
  9347. else
  9348. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9349. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9350. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9351. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9352. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9353. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9354. }
  9355. else
  9356. {
  9357. storeTempStopTransaction(gun_index);
  9358. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9359. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9360. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9361. }
  9362. }
  9363. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9364. {
  9365. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9366. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9367. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9368. if((access(TempStopTransaction,F_OK))!=-1)
  9369. {
  9370. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9371. }
  9372. }
  9373. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9374. {
  9375. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9376. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9377. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9378. }
  9379. 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
  9380. {
  9381. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9382. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9383. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9384. }
  9385. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9386. {
  9387. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9388. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9389. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9390. }
  9391. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9392. {
  9393. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9394. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9395. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9396. }
  9397. } //end of the same index
  9398. }//end of for CHAdeMO_QUANTITY
  9399. }
  9400. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9401. {
  9402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9403. {
  9404. tempIndex = ((gun_index==2) ? 1: 0);
  9405. }
  9406. else
  9407. {
  9408. tempIndex = gun_index;
  9409. }
  9410. for (int index = 0; index < CCS_QUANTITY; index++)
  9411. {
  9412. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9413. {
  9414. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9415. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9416. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9417. else
  9418. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9419. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9420. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9421. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9423. {
  9424. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9425. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9426. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9427. {
  9428. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9429. }
  9430. else
  9431. {
  9432. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9433. }
  9434. }
  9435. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9436. {
  9437. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9438. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9439. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9440. }
  9441. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9442. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9443. ) //S_PRECHARGE
  9444. {
  9445. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9446. {
  9447. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9448. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9449. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9450. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9451. }
  9452. else
  9453. {
  9454. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9455. }
  9456. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9457. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9458. }
  9459. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9460. {
  9461. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9462. {
  9463. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9464. {
  9465. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9466. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9467. }
  9468. else
  9469. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9470. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9471. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9472. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9473. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9474. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9475. }
  9476. else
  9477. {
  9478. storeTempStopTransaction(gun_index);
  9479. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9480. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9481. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9482. }
  9483. }
  9484. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9485. {
  9486. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9487. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9488. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9489. if((access(TempStopTransaction,F_OK))!=-1)
  9490. {
  9491. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9492. }
  9493. }
  9494. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9495. {
  9496. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9497. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9498. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9499. }
  9500. 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
  9501. {
  9502. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9503. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9504. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9505. }
  9506. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9507. {
  9508. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9509. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9510. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9511. }
  9512. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9513. {
  9514. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9515. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9516. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9517. }
  9518. } //end of the same index
  9519. } // end of for CCS_QUANTITY
  9520. }
  9521. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9522. {
  9523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9524. {
  9525. tempIndex = ((gun_index==2) ? 1: 0);
  9526. }
  9527. else
  9528. {
  9529. tempIndex = gun_index;
  9530. }
  9531. for (int index = 0; index < GB_QUANTITY; index++)
  9532. {
  9533. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9534. {
  9535. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9536. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9537. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9538. else
  9539. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9540. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9541. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9542. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9544. {
  9545. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9546. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9548. {
  9549. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9550. }
  9551. else
  9552. {
  9553. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9554. }
  9555. }
  9556. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9557. {
  9558. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9559. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9560. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9561. }
  9562. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9563. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9564. ) //S_PRECHARGE
  9565. {
  9566. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9567. {
  9568. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9569. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9570. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9571. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9572. }
  9573. else
  9574. {
  9575. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9576. }
  9577. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9578. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9579. }
  9580. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9581. {
  9582. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9583. {
  9584. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  9585. {
  9586. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9587. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9588. }
  9589. else
  9590. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9591. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9592. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9593. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9594. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9595. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9596. }
  9597. else
  9598. {
  9599. storeTempStopTransaction(gun_index);
  9600. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9601. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9602. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9603. }
  9604. }
  9605. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9606. {
  9607. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9608. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9609. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9610. if((access(TempStopTransaction,F_OK))!=-1)
  9611. {
  9612. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9613. }
  9614. }
  9615. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9616. {
  9617. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9618. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9619. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9620. }
  9621. 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
  9622. {
  9623. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9624. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9625. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9626. }
  9627. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  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_SuspendedEVSE]);
  9631. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9632. }
  9633. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9634. {
  9635. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  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. } //end of the same index
  9640. } // end of for GB_QUANTITY
  9641. }
  9642. else if(gunType[gun_index] == GUN_TYPE_DO)
  9643. {
  9644. tempIndex = gun_index;
  9645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9646. {
  9647. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9648. {
  9649. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9650. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9651. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9652. else
  9653. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9654. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9655. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9656. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9658. {
  9659. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9660. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9661. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9662. {
  9663. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9664. }
  9665. else
  9666. {
  9667. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9668. }
  9669. }
  9670. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9671. {
  9672. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9673. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9674. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9675. }
  9676. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9677. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9678. ) //S_PRECHARGE
  9679. {
  9680. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9681. {
  9682. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9683. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9684. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9685. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9686. }
  9687. else
  9688. {
  9689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9690. }
  9691. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9692. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9693. }
  9694. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9695. {
  9696. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9697. {
  9698. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  9699. {
  9700. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9701. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9702. }
  9703. else
  9704. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9705. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9706. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9707. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9708. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9709. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9710. }
  9711. else
  9712. {
  9713. storeTempStopTransaction(gun_index);
  9714. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9715. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9716. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9717. }
  9718. }
  9719. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9720. {
  9721. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9722. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9723. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9724. if((access(TempStopTransaction,F_OK))!=-1)
  9725. {
  9726. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9727. }
  9728. }
  9729. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9730. {
  9731. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9732. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9733. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9734. }
  9735. 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
  9736. {
  9737. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9738. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9739. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9740. }
  9741. 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
  9742. {
  9743. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9744. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9745. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9746. }
  9747. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9748. {
  9749. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9750. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9751. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9752. }
  9753. } //end of the same index
  9754. }
  9755. }
  9756. else
  9757. {
  9758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9759. {
  9760. tempIndex = 2;
  9761. }
  9762. else
  9763. {
  9764. tempIndex = gun_index;
  9765. }
  9766. for (int index = 0; index < AC_QUANTITY; index++)
  9767. {
  9768. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9769. {
  9770. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9771. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9772. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9773. else
  9774. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9775. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9776. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9777. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9779. {
  9780. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9781. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9782. 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))
  9783. {
  9784. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9785. }
  9786. else
  9787. {
  9788. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9789. }
  9790. }
  9791. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_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. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9796. }
  9797. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9798. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9799. ) //S_PRECHARGE
  9800. {
  9801. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9802. {
  9803. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9804. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9805. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9807. }
  9808. else
  9809. {
  9810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9811. }
  9812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9813. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9814. }
  9815. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9816. {
  9817. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9818. {
  9819. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  9820. {
  9821. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9822. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9823. }
  9824. else
  9825. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9826. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9827. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9829. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9830. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9831. }
  9832. else
  9833. {
  9834. storeTempStopTransaction(gun_index);
  9835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9836. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9837. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9838. }
  9839. }
  9840. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9841. {
  9842. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9843. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9844. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9845. if((access(TempStopTransaction,F_OK))!=-1)
  9846. {
  9847. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9848. }
  9849. }
  9850. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9851. {
  9852. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9853. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9854. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9855. }
  9856. 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
  9857. {
  9858. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9859. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9860. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9861. }
  9862. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9863. {
  9864. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9865. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9866. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9867. }
  9868. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9869. {
  9870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9871. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9872. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9873. }
  9874. }//end of the same index
  9875. }//end of for AC_QUANTITY
  9876. }
  9877. // Message
  9878. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9879. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  9880. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  9881. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  9882. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  9883. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  9884. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  9885. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  9886. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  9887. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  9888. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  9889. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  9890. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  9891. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  9892. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  9893. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  9894. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  9895. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  9896. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  9897. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  9898. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  9899. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  9900. {
  9901. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  9902. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  9903. json_object_object_add(TransactionEvent, "idToken", idToken);
  9904. }
  9905. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  9906. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  9907. json_object_object_add(TransactionEvent, "evse", evse);
  9908. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  9909. {
  9910. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  9911. {
  9912. json_object *meterValue = json_object_new_object();
  9913. json_object *sampledValues = json_object_new_array();
  9914. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  9915. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  9916. {
  9917. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  9918. ((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)))
  9919. {
  9920. 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)) ||
  9921. (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  9922. {
  9923. json_object *sampledValue = json_object_new_object();
  9924. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  9925. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  9926. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  9927. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  9928. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  9929. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  9930. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  9931. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  9932. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  9933. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  9934. {
  9935. json_object *unitOfMeasure = json_object_new_object();
  9936. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  9937. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  9938. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  9939. }
  9940. json_object_array_add(sampledValues, sampledValue);
  9941. }
  9942. }
  9943. }
  9944. json_object_object_add(meterValue, "sampledValue", sampledValues);
  9945. json_object_array_add(meterValues, meterValue);
  9946. }
  9947. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  9948. }
  9949. random_uuid(guid);
  9950. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  9951. json_object_put(TransactionEvent);
  9952. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  9953. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9954. {
  9955. result = PASS;
  9956. }
  9957. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  9958. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  9959. OCPP_insert_transaction_msg(YES, message);
  9960. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  9961. {
  9962. OCPP_insert_transaction_msg(NO, message);
  9963. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  9964. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9965. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9966. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9967. }
  9968. return result;
  9969. }
  9970. //==========================================
  9971. // send confirm routine
  9972. //==========================================
  9973. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  9974. {
  9975. mtrace();
  9976. int result = FAIL;
  9977. char message[4096]={0};
  9978. json_object *CancelReservation = json_object_new_object();
  9979. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  9980. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  9981. sprintf(message,"[%d,\"%s\",%s]"
  9982. ,MESSAGE_TYPE_CALLRESULT
  9983. ,uuid
  9984. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  9985. json_object_put(CancelReservation);
  9986. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  9987. LWS_Send(message);
  9988. result = TRUE;
  9989. return result;
  9990. }
  9991. int sendCertificateSignedConfirmation(char *uuid)
  9992. {
  9993. mtrace();
  9994. int result = FAIL;
  9995. char message[4096]={0};
  9996. json_object *CertificateSigned = json_object_new_object();
  9997. json_object *statusInfo = json_object_new_object();
  9998. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  9999. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10000. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10001. {
  10002. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10003. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10004. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10005. }
  10006. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10007. sprintf(message,"[%d,\"%s\",%s]"
  10008. ,MESSAGE_TYPE_CALLRESULT
  10009. ,uuid
  10010. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10011. json_object_put(CertificateSigned);
  10012. LWS_Send(message);
  10013. result = TRUE;
  10014. return result;
  10015. }
  10016. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10017. {
  10018. mtrace();
  10019. int result = FAIL;
  10020. char message[4096]={0};
  10021. json_object *ChangeAvailability = json_object_new_object();
  10022. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10023. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10024. sprintf(message,"[%d,\"%s\",%s]"
  10025. ,MESSAGE_TYPE_CALLRESULT
  10026. ,uuid
  10027. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10028. json_object_put(ChangeAvailability);
  10029. LWS_Send(message);
  10030. result = TRUE;
  10031. return result;
  10032. }
  10033. int sendClearCacheConfirmation(char *uuid)
  10034. {
  10035. mtrace();
  10036. int result = FAIL;
  10037. char message[4096]={0};
  10038. json_object *ClearCache = json_object_new_object();
  10039. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10040. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10041. sprintf(message,"[%d,\"%s\",%s]"
  10042. ,MESSAGE_TYPE_CALLRESULT
  10043. ,uuid
  10044. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10045. json_object_put(ClearCache);
  10046. LWS_Send(message);
  10047. result = TRUE;
  10048. return result;
  10049. }
  10050. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10051. {
  10052. mtrace();
  10053. int result = FAIL;
  10054. char message[500]={0};
  10055. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10056. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10057. LWS_Send(message);
  10058. return result;
  10059. }
  10060. int sendClearDisplayMessageConfirmation(char *uuid)
  10061. {
  10062. mtrace();
  10063. int result = FAIL;
  10064. char message[4096]={0};
  10065. json_object *ClearDisplayMessage = json_object_new_object();
  10066. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10067. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10068. sprintf(message,"[%d,\"%s\",%s]"
  10069. ,MESSAGE_TYPE_CALLRESULT
  10070. ,uuid
  10071. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10072. json_object_put(ClearDisplayMessage);
  10073. LWS_Send(message);
  10074. result = TRUE;
  10075. return result;
  10076. }
  10077. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10078. {
  10079. mtrace();
  10080. int result = FAIL;
  10081. char message[4096]={0};
  10082. json_object *ClearVariableMonitoring = json_object_new_object();
  10083. json_object *clearMonitoringResults = json_object_new_array();
  10084. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10085. for(int idx=0;idx<variableQuantity;idx++)
  10086. {
  10087. json_object *clearMonitoringResult = json_object_new_object();
  10088. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10089. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10090. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10091. }
  10092. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10093. sprintf(message,"[%d,\"%s\",%s]"
  10094. ,MESSAGE_TYPE_CALLRESULT
  10095. ,uuid
  10096. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10097. json_object_put(ClearVariableMonitoring);
  10098. LWS_Send(message);
  10099. result = TRUE;
  10100. return result;
  10101. }
  10102. int sendCostUpdatedConfirmation(char *uuid)
  10103. {
  10104. mtrace();
  10105. int result = FAIL;
  10106. char message[4096]={0};
  10107. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10108. sprintf(message,"[%d,\"%s\",{}]"
  10109. ,MESSAGE_TYPE_CALLRESULT
  10110. ,uuid);
  10111. LWS_Send(message);
  10112. result = TRUE;
  10113. return result;
  10114. }
  10115. int sendCustomerInformationConfirmation(char *uuid)
  10116. {
  10117. mtrace();
  10118. int result = FAIL;
  10119. char message[4096]={0};
  10120. json_object *CustomerInformation = json_object_new_object();
  10121. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10122. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10123. sprintf(message,"[%d,\"%s\",%s]"
  10124. ,MESSAGE_TYPE_CALLRESULT
  10125. ,uuid
  10126. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10127. json_object_put(CustomerInformation);
  10128. LWS_Send(message);
  10129. result = TRUE;
  10130. return result;
  10131. }
  10132. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10133. {
  10134. mtrace();
  10135. int result = FAIL;
  10136. char message[4096]={0};
  10137. json_object *DataTransfer = json_object_new_object();
  10138. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10139. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10140. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10141. sprintf(message,"[%d,\"%s\",%s]"
  10142. ,MESSAGE_TYPE_CALLRESULT
  10143. ,uuid
  10144. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10145. json_object_put(DataTransfer);
  10146. LWS_Send(message);
  10147. result = TRUE;
  10148. return result;
  10149. }
  10150. int sendDeleteCertificateConfirmation(char *uuid)
  10151. {
  10152. mtrace();
  10153. int result = FAIL;
  10154. char message[4096]={0};
  10155. json_object *DeleteCertificate = json_object_new_object();
  10156. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10157. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10158. sprintf(message,"[%d,\"%s\",%s]"
  10159. ,MESSAGE_TYPE_CALLRESULT
  10160. ,uuid
  10161. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10162. json_object_put(DeleteCertificate);
  10163. LWS_Send(message);
  10164. result = TRUE;
  10165. return result;
  10166. }
  10167. int sendGetBaseReportConfirmation(char *uuid)
  10168. {
  10169. mtrace();
  10170. int result = FAIL;
  10171. char message[4096]={0};
  10172. json_object *GetBaseReport = json_object_new_object();
  10173. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10174. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10175. sprintf(message,"[%d,\"%s\",%s]"
  10176. ,MESSAGE_TYPE_CALLRESULT
  10177. ,uuid
  10178. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10179. json_object_put(GetBaseReport);
  10180. LWS_Send(message);
  10181. result = TRUE;
  10182. return result;
  10183. }
  10184. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10185. {
  10186. mtrace();
  10187. int result = FAIL;
  10188. char message[4096]={0};
  10189. json_object *GetChargingProfiles = json_object_new_object();
  10190. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10191. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10192. sprintf(message,"[%d,\"%s\",%s]"
  10193. ,MESSAGE_TYPE_CALLRESULT
  10194. ,uuid
  10195. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10196. json_object_put(GetChargingProfiles);
  10197. LWS_Send(message);
  10198. result = TRUE;
  10199. return result;
  10200. }
  10201. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  10202. {
  10203. mtrace();
  10204. int result = FAIL;
  10205. char message[4096]={0};
  10206. int CompositeScheduleIndex = 0;
  10207. json_object *GetCompositeSchedule = json_object_new_object();
  10208. json_object *schedule = json_object_new_object();
  10209. json_object *chargingSchedule = json_object_new_object();
  10210. json_object *chargingSchedulePeriod = json_object_new_array();
  10211. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10212. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10213. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  10214. json_object_object_add(chargingSchedule, "evseId", json_object_new_int(CompositeScheduleIndex));
  10215. if(nPeriod == 0)
  10216. {
  10217. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10218. {
  10219. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10220. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10221. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10222. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10223. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10224. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10225. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10226. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10227. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10228. {
  10229. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10230. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10231. {
  10232. json_object *Period = json_object_new_object();
  10233. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10234. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10235. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10236. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10237. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10238. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10239. json_object_array_add(chargingSchedulePeriod, Period);
  10240. }
  10241. }
  10242. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10243. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10244. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10245. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10246. }
  10247. }
  10248. else
  10249. {
  10250. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10251. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10252. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10253. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10254. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10255. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10256. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10257. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10258. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10259. {
  10260. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10261. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10262. {
  10263. json_object *Period = json_object_new_object();
  10264. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10265. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10266. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10267. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10268. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10269. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10270. json_object_array_add(chargingSchedulePeriod, Period);
  10271. }
  10272. }
  10273. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10274. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10275. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10276. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10277. }
  10278. sprintf(message,"[%d,\"%s\",%s]"
  10279. ,MESSAGE_TYPE_CALLRESULT
  10280. ,uuid
  10281. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10282. json_object_put(GetCompositeSchedule);
  10283. LWS_Send(message);
  10284. result = TRUE;
  10285. return result;
  10286. }
  10287. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10288. {
  10289. mtrace();
  10290. int result = FAIL;
  10291. char message[4096]={0};
  10292. json_object *GetGetDisplayMessages = json_object_new_object();
  10293. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10294. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10295. sprintf(message,"[%d,\"%s\",%s]"
  10296. ,MESSAGE_TYPE_CALLRESULT
  10297. ,uuid
  10298. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10299. json_object_put(GetGetDisplayMessages);
  10300. LWS_Send(message);
  10301. result = TRUE;
  10302. return result;
  10303. }
  10304. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10305. {
  10306. mtrace();
  10307. int result = FAIL;
  10308. char message[4096]={0};
  10309. json_object *GetInstalledCertificateIds = json_object_new_object();
  10310. json_object *certificateHashDataChains = json_object_new_array();
  10311. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10312. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10313. for(int idx=0;idx<certQuantity;idx++)
  10314. {
  10315. json_object *cert = json_object_new_object();
  10316. json_object *certificateHashData = json_object_new_object();
  10317. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10318. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10319. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10320. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10321. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10322. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10323. json_object_array_add(certificateHashDataChains, cert);
  10324. }
  10325. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10326. sprintf(message,"[%d,\"%s\",%s]"
  10327. ,MESSAGE_TYPE_CALLRESULT
  10328. ,uuid
  10329. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10330. json_object_put(GetInstalledCertificateIds);
  10331. LWS_Send(message);
  10332. result = TRUE;
  10333. return result;
  10334. }
  10335. int sendGetLocalListVersionConfirmation(char *uuid)
  10336. {
  10337. mtrace();
  10338. int result = FAIL;
  10339. char message[4096]={0};
  10340. json_object *GetLocalListVersion = json_object_new_object();
  10341. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10342. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10343. sprintf(message,"[%d,\"%s\",%s]"
  10344. ,MESSAGE_TYPE_CALLRESULT
  10345. ,uuid
  10346. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10347. json_object_put(GetLocalListVersion);
  10348. LWS_Send(message);
  10349. result = TRUE;
  10350. return result;
  10351. }
  10352. int sendGetLogConfirmation(char *uuid)
  10353. {
  10354. mtrace();
  10355. int result = FAIL;
  10356. char message[4096]={0};
  10357. json_object *GetLog = json_object_new_object();
  10358. DEBUG_INFO("sendGetLogConfirmation...\n");
  10359. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10360. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10361. sprintf(message,"[%d,\"%s\",%s]"
  10362. ,MESSAGE_TYPE_CALLRESULT
  10363. ,uuid
  10364. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10365. json_object_put(GetLog);
  10366. LWS_Send(message);
  10367. result = TRUE;
  10368. return result;
  10369. }
  10370. int sendGetMonitoringReportConfirmation(char *uuid)
  10371. {
  10372. mtrace();
  10373. int result = FAIL;
  10374. char message[4096]={0};
  10375. json_object *GetMonitoringReport = json_object_new_object();
  10376. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10377. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10378. sprintf(message,"[%d,\"%s\",%s]"
  10379. ,MESSAGE_TYPE_CALLRESULT
  10380. ,uuid
  10381. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10382. json_object_put(GetMonitoringReport);
  10383. LWS_Send(message);
  10384. result = TRUE;
  10385. return result;
  10386. }
  10387. int sendGetReportConfirmation(char *uuid)
  10388. {
  10389. mtrace();
  10390. int result = FAIL;
  10391. char message[4096]={0};
  10392. json_object *GetReport = json_object_new_object();
  10393. DEBUG_INFO("sendGetReportConfirmation...\n");
  10394. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10395. sprintf(message,"[%d,\"%s\",%s]"
  10396. ,MESSAGE_TYPE_CALLRESULT
  10397. ,uuid
  10398. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10399. json_object_put(GetReport);
  10400. LWS_Send(message);
  10401. result = TRUE;
  10402. return result;
  10403. }
  10404. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  10405. {
  10406. mtrace();
  10407. int result = FAIL;
  10408. char message[4096]={0};
  10409. json_object *GetTransactionStatus = json_object_new_object();
  10410. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10411. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  10412. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  10413. sprintf(message,"[%d,\"%s\",%s]"
  10414. ,MESSAGE_TYPE_CALLRESULT
  10415. ,uuid
  10416. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10417. json_object_put(GetTransactionStatus);
  10418. LWS_Send(message);
  10419. result = TRUE;
  10420. return result;
  10421. }
  10422. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10423. {
  10424. mtrace();
  10425. int result = FAIL;
  10426. char message[4096]={0};
  10427. json_object *GetVariables = json_object_new_object();
  10428. json_object *getVariableResults = json_object_new_array();
  10429. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10430. for(int idx=0;idx<variableQuantity;idx++)
  10431. {
  10432. json_object *variableResult = json_object_new_object();
  10433. json_object *component = json_object_new_object();
  10434. json_object *variable = json_object_new_object();
  10435. json_object *evse = json_object_new_object();
  10436. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10437. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10438. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10439. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10440. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10441. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10442. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10443. json_object_object_add(component, "evse", evse);
  10444. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10445. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10446. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10447. json_object_object_add(variableResult, "component", component);
  10448. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10449. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10450. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10451. json_object_object_add(variableResult, "variable", variable);
  10452. json_object_array_add(getVariableResults, variableResult);
  10453. }
  10454. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10455. sprintf(message,"[%d,\"%s\",%s]"
  10456. ,MESSAGE_TYPE_CALLRESULT
  10457. ,uuid
  10458. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10459. json_object_put(GetVariables);
  10460. LWS_Send(message);
  10461. result = TRUE;
  10462. return result;
  10463. }
  10464. int sendInstallCertificateConfirmation(char *uuid)
  10465. {
  10466. mtrace();
  10467. int result = FAIL;
  10468. char message[4096]={0};
  10469. json_object *InstallCertificate = json_object_new_object();
  10470. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10471. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10472. sprintf(message,"[%d,\"%s\",%s]"
  10473. ,MESSAGE_TYPE_CALLRESULT
  10474. ,uuid
  10475. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10476. json_object_put(InstallCertificate);
  10477. LWS_Send(message);
  10478. result = TRUE;
  10479. return result;
  10480. }
  10481. int sendPublishFirmwareConfirmation(char *uuid)
  10482. {
  10483. mtrace();
  10484. int result = FAIL;
  10485. char message[4096]={0};
  10486. json_object *PublishFirmware = json_object_new_object();
  10487. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10488. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10489. sprintf(message,"[%d,\"%s\",%s]"
  10490. ,MESSAGE_TYPE_CALLRESULT
  10491. ,uuid
  10492. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10493. json_object_put(PublishFirmware);
  10494. LWS_Send(message);
  10495. result = TRUE;
  10496. return result;
  10497. }
  10498. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10499. {
  10500. mtrace();
  10501. int result = FAIL;
  10502. char message[4096]={0};
  10503. json_object *RemoteStartTransaction = json_object_new_object();
  10504. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10505. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10506. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10507. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10508. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10509. sprintf(message,"[%d,\"%s\",%s]"
  10510. ,MESSAGE_TYPE_CALLRESULT
  10511. ,uuid
  10512. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10513. json_object_put(RemoteStartTransaction);
  10514. LWS_Send(message);
  10515. result = TRUE;
  10516. return result;
  10517. }
  10518. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10519. {
  10520. mtrace();
  10521. int result = FAIL;
  10522. char message[4096]={0};
  10523. json_object *RemoteStopTransaction = json_object_new_object();
  10524. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  10525. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  10526. sprintf(message,"[%d,\"%s\",%s]"
  10527. ,MESSAGE_TYPE_CALLRESULT
  10528. ,uuid
  10529. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  10530. json_object_put(RemoteStopTransaction);
  10531. LWS_Send(message);
  10532. result = TRUE;
  10533. return result;
  10534. }
  10535. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  10536. {
  10537. mtrace();
  10538. int result = FAIL;
  10539. char message[4096]={0};
  10540. json_object *ReserveNow = json_object_new_object();
  10541. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  10542. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  10543. sprintf(message,"[%d,\"%s\",%s]"
  10544. ,MESSAGE_TYPE_CALLRESULT
  10545. ,uuid
  10546. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10547. json_object_put(ReserveNow);
  10548. LWS_Send(message);
  10549. result = TRUE;
  10550. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10551. return result;
  10552. }
  10553. int sendResetConfirmation(char *uuid)
  10554. {
  10555. mtrace();
  10556. int result = FAIL;
  10557. char message[4096]={0};
  10558. json_object *Reset = json_object_new_object();
  10559. DEBUG_INFO("sendResetConfirmation...\n");
  10560. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10561. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10562. sprintf(message,"[%d,\"%s\",%s]"
  10563. ,MESSAGE_TYPE_CALLRESULT
  10564. ,uuid
  10565. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10566. json_object_put(Reset);
  10567. LWS_Send(message);
  10568. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10569. {
  10570. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10571. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10572. }
  10573. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10574. {
  10575. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10576. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10577. }
  10578. result = TRUE;
  10579. return result;
  10580. }
  10581. int sendSendLocalListConfirmation(char *uuid)
  10582. {
  10583. mtrace();
  10584. int result = FAIL;
  10585. char message[4096]={0};
  10586. json_object *SendLocalList = json_object_new_object();
  10587. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  10588. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10589. sprintf(message,"[%d,\"%s\",%s]"
  10590. ,MESSAGE_TYPE_CALLRESULT
  10591. ,uuid
  10592. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10593. json_object_put(SendLocalList);
  10594. LWS_Send(message);
  10595. result = TRUE;
  10596. return result;
  10597. }
  10598. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10599. {
  10600. mtrace();
  10601. int result = FAIL;
  10602. char message[4096]={0};
  10603. json_object *SetChargingProfile = json_object_new_object();
  10604. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  10605. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  10606. sprintf(message,"[%d,\"%s\",%s]"
  10607. ,MESSAGE_TYPE_CALLRESULT
  10608. ,uuid
  10609. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10610. json_object_put(SetChargingProfile);
  10611. LWS_Send(message);
  10612. result = TRUE;
  10613. return result;
  10614. }
  10615. int sendSetDisplayMessagesConfirmation(char *uuid)
  10616. {
  10617. mtrace();
  10618. int result = FAIL;
  10619. char message[4096]={0};
  10620. json_object *SetDisplayMessage = json_object_new_object();
  10621. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  10622. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  10623. sprintf(message,"[%d,\"%s\",%s]"
  10624. ,MESSAGE_TYPE_CALLRESULT
  10625. ,uuid
  10626. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10627. json_object_put(SetDisplayMessage);
  10628. LWS_Send(message);
  10629. result = TRUE;
  10630. return result;
  10631. }
  10632. int sendSetMonitoringBaseConfirmation(char *uuid)
  10633. {
  10634. mtrace();
  10635. int result = FAIL;
  10636. char message[4096]={0};
  10637. json_object *SetMonitoringBase = json_object_new_object();
  10638. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  10639. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  10640. sprintf(message,"[%d,\"%s\",%s]"
  10641. ,MESSAGE_TYPE_CALLRESULT
  10642. ,uuid
  10643. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  10644. json_object_put(SetMonitoringBase);
  10645. LWS_Send(message);
  10646. result = TRUE;
  10647. return result;
  10648. }
  10649. int sendSetMonitoringLevelConfirmation(char *uuid)
  10650. {
  10651. mtrace();
  10652. int result = FAIL;
  10653. char message[4096]={0};
  10654. json_object *SetMonitoringLevel = json_object_new_object();
  10655. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  10656. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  10657. sprintf(message,"[%d,\"%s\",%s]"
  10658. ,MESSAGE_TYPE_CALLRESULT
  10659. ,uuid
  10660. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  10661. json_object_put(SetMonitoringLevel);
  10662. LWS_Send(message);
  10663. result = TRUE;
  10664. return result;
  10665. }
  10666. int sendSetNetworkProfileConfirmation(char *uuid)
  10667. {
  10668. mtrace();
  10669. int result = FAIL;
  10670. char message[4096]={0};
  10671. json_object *SetNetworkProfile = json_object_new_object();
  10672. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  10673. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  10674. sprintf(message,"[%d,\"%s\",%s]"
  10675. ,MESSAGE_TYPE_CALLRESULT
  10676. ,uuid
  10677. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  10678. json_object_put(SetNetworkProfile);
  10679. LWS_Send(message);
  10680. result = TRUE;
  10681. return result;
  10682. }
  10683. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10684. {
  10685. mtrace();
  10686. int result = FAIL;
  10687. char message[4096]={0};
  10688. json_object *SetVariableMonitoring = json_object_new_object();
  10689. json_object *setMonitoringResults = json_object_new_array();
  10690. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  10691. for(int idx=0;idx<variableQuantity;idx++)
  10692. {
  10693. json_object *variableMonitorResult = json_object_new_object();
  10694. json_object *component = json_object_new_object();
  10695. json_object *variable = json_object_new_object();
  10696. json_object *evse = json_object_new_object();
  10697. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  10698. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  10699. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  10700. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  10701. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  10702. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  10703. json_object_object_add(component, "evse", evse);
  10704. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  10705. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  10706. json_object_object_add(variableMonitorResult, "component", component);
  10707. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  10708. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  10709. json_object_object_add(variableMonitorResult, "variable", variable);
  10710. json_object_array_add(setMonitoringResults, variableMonitorResult);
  10711. }
  10712. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  10713. sprintf(message,"[%d,\"%s\",%s]"
  10714. ,MESSAGE_TYPE_CALLRESULT
  10715. ,uuid
  10716. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10717. json_object_put(SetVariableMonitoring);
  10718. LWS_Send(message);
  10719. result = TRUE;
  10720. return result;
  10721. }
  10722. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  10723. {
  10724. mtrace();
  10725. int result = FAIL;
  10726. char message[4096]={0};
  10727. json_object *SetVariable = json_object_new_object();
  10728. json_object *setVariableResults = json_object_new_array();
  10729. DEBUG_INFO("sendSetVariableConfirmation...\n");
  10730. for(int idx=0;idx<variableQuantity;idx++)
  10731. {
  10732. json_object *variableResult = json_object_new_object();
  10733. json_object *component = json_object_new_object();
  10734. json_object *variable = json_object_new_object();
  10735. json_object *evse = json_object_new_object();
  10736. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  10737. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  10738. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  10739. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  10740. json_object_object_add(component, "evse", evse);
  10741. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  10742. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  10743. json_object_object_add(variableResult, "component", component);
  10744. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  10745. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  10746. json_object_object_add(variableResult, "variable", variable);
  10747. json_object_array_add(setVariableResults, variableResult);
  10748. }
  10749. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  10750. sprintf(message,"[%d,\"%s\",%s]"
  10751. ,MESSAGE_TYPE_CALLRESULT
  10752. ,uuid
  10753. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  10754. json_object_put(SetVariable);
  10755. LWS_Send(message);
  10756. result = TRUE;
  10757. return result;
  10758. }
  10759. int sendTriggerMessageConfirmation(char *uuid)
  10760. {
  10761. mtrace();
  10762. int result = FAIL;
  10763. char message[4096]={0};
  10764. json_object *TriggerMessage = json_object_new_object();
  10765. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  10766. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  10767. sprintf(message,"[%d,\"%s\",%s]",
  10768. MESSAGE_TYPE_CALLRESULT,
  10769. uuid,
  10770. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  10771. json_object_put(TriggerMessage);
  10772. LWS_Send(message);
  10773. result = TRUE;
  10774. return result;
  10775. }
  10776. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  10777. {
  10778. mtrace();
  10779. int result = FAIL;
  10780. char message[4096]={0};
  10781. json_object *UnlockConnector = json_object_new_object();
  10782. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  10783. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  10784. sprintf(message,"[%d,\"%s\",%s]",
  10785. MESSAGE_TYPE_CALLRESULT,
  10786. uuid,
  10787. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  10788. json_object_put(UnlockConnector);
  10789. LWS_Send(message);
  10790. result = TRUE;
  10791. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  10792. return result;
  10793. }
  10794. int sendUnpublishFirmwareConfirmation(char *uuid)
  10795. {
  10796. mtrace();
  10797. int result = FAIL;
  10798. char message[4096]={0};
  10799. json_object *UnpublishFirmware = json_object_new_object();
  10800. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  10801. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  10802. sprintf(message,"[%d,\"%s\",%s]"
  10803. ,MESSAGE_TYPE_CALLRESULT
  10804. ,uuid
  10805. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  10806. json_object_put(UnpublishFirmware);
  10807. LWS_Send(message);
  10808. result = TRUE;
  10809. return result;
  10810. }
  10811. int sendUpdateFirmwareConfirmation(char *uuid)
  10812. {
  10813. mtrace();
  10814. int result = FAIL;
  10815. char message[4096]={0};
  10816. json_object *UpdateFirmware = json_object_new_object();
  10817. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  10818. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  10819. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  10820. sprintf(message,"[%d,\"%s\",%s]"
  10821. ,MESSAGE_TYPE_CALLRESULT
  10822. ,uuid
  10823. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  10824. json_object_put(UpdateFirmware);
  10825. LWS_Send(message);
  10826. result = TRUE;
  10827. return result;
  10828. }
  10829. int sendUnknownConfirmation(char *uuid)
  10830. {
  10831. mtrace();
  10832. int result = FAIL;
  10833. char message[256]={0};
  10834. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  10835. DEBUG_INFO("sendUnknownConfirmation...\n");
  10836. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  10837. LWS_Send(message);
  10838. result = TRUE;
  10839. return result;
  10840. }
  10841. //==========================================
  10842. // send CallError routine
  10843. //==========================================
  10844. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  10845. {
  10846. mtrace();
  10847. char message[220]={0};
  10848. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  10849. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  10850. LWS_Send(message);
  10851. }
  10852. //==========================================
  10853. // Handle server request routine Start
  10854. //==========================================
  10855. int handleCancelReservationRequest(char *uuid, char *payload)
  10856. {
  10857. mtrace();
  10858. int result = FAIL;
  10859. int gunNO = 0;
  10860. int reservationIdInt = -1;
  10861. DEBUG_INFO("handleCancelReservationRequest...\n");
  10862. json_object *CancelReservation;
  10863. CancelReservation = json_tokener_parse(payload);
  10864. if(!is_error(CancelReservation))
  10865. {
  10866. // Required data
  10867. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  10868. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  10869. }
  10870. json_object_put(CancelReservation);
  10871. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  10872. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  10873. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  10874. if(reservationIdInt != -1)
  10875. {
  10876. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10877. //check Transaction active
  10878. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  10879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10880. {
  10881. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  10882. {
  10883. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10884. if(gunType[2] == GUN_TYPE_CHAdeMO)
  10885. {
  10886. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  10887. }
  10888. else
  10889. {
  10890. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  10891. }
  10892. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10893. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10894. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10895. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10896. goto end;
  10897. }
  10898. }
  10899. for (int index = 0; index < CCS_QUANTITY; index++)
  10900. {
  10901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  10902. {
  10903. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10904. if(gunType[2] == GUN_TYPE_CCS)
  10905. {
  10906. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  10907. }
  10908. else
  10909. {
  10910. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  10911. }
  10912. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10913. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10914. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10915. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10916. goto end;
  10917. }
  10918. }
  10919. for (int index = 0; index < GB_QUANTITY; index++)
  10920. {
  10921. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  10922. {
  10923. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10924. if(gunType[2] == GUN_TYPE_GBT)
  10925. {
  10926. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  10927. }
  10928. else
  10929. {
  10930. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  10931. }
  10932. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10933. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10934. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10935. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10936. goto end;
  10937. }
  10938. }
  10939. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10940. {
  10941. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  10942. {
  10943. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10944. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  10945. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10946. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10947. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10948. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10949. goto end;
  10950. }
  10951. }
  10952. for (int index = 0; index < AC_QUANTITY; index++)
  10953. {
  10954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  10955. {
  10956. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10957. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10958. {
  10959. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  10960. }
  10961. else
  10962. {
  10963. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  10964. }
  10965. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10966. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10967. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10968. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10969. goto end;
  10970. }
  10971. }
  10972. }
  10973. //The reservationId does NOT match the reservationId
  10974. sendCancelReservationConfirmation(uuid, gunNO);
  10975. end:
  10976. // Fill in ocpp packet uuid
  10977. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  10978. return result;
  10979. }
  10980. int handleCertificateSignedRequest(char *uuid, char *payload)
  10981. {
  10982. mtrace();
  10983. int result = FAIL;
  10984. json_object *CertificateSigned;
  10985. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10986. CertificateSigned = json_tokener_parse(payload);
  10987. if(!is_error(CertificateSigned))
  10988. {
  10989. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  10990. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  10991. // Required data
  10992. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  10993. // Optional data
  10994. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  10995. {
  10996. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  10997. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  10998. {
  10999. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11000. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11001. fclose(fp);
  11002. }
  11003. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11004. {
  11005. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11006. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11007. fclose(fp);
  11008. }
  11009. }
  11010. else
  11011. {
  11012. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11013. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11014. fclose(fp);
  11015. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11016. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11017. fclose(fp);
  11018. }
  11019. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11020. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11021. }
  11022. else
  11023. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11024. json_object_put(CertificateSigned);
  11025. sendCertificateSignedConfirmation(uuid);
  11026. return result;
  11027. }
  11028. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11029. {
  11030. mtrace();
  11031. int result = FAIL;
  11032. int evseId = 0, gunIndex = 0;
  11033. char operationalStatus[16]={0};
  11034. char comfirmstr[20];
  11035. int specificId = FALSE;
  11036. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11037. json_object *ChangeAvailability;
  11038. ChangeAvailability = json_tokener_parse(payload);
  11039. if(!is_error(ChangeAvailability))
  11040. {
  11041. // Required data
  11042. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11043. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11044. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11045. {
  11046. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11047. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11048. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11049. }
  11050. }
  11051. json_object_put(ChangeAvailability);
  11052. if((evseId != 0) && (evseId <= gunTotalNumber))
  11053. {
  11054. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  11055. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11056. }
  11057. else if(evseId == 0)
  11058. {
  11059. for(int i=0; i < gunTotalNumber; i++)
  11060. {
  11061. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  11062. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11063. }
  11064. }
  11065. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11066. {
  11067. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  11068. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11069. }
  11070. else if(gunIndex == 0)
  11071. {
  11072. for(int i=0; i < gunTotalNumber; i++)
  11073. {
  11074. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  11075. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11076. }
  11077. }
  11078. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11079. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11080. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  11081. {
  11082. specificId = TRUE;
  11083. }
  11084. if(specificId == FALSE)
  11085. goto end;
  11086. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11087. {
  11088. //----------------------gunIndex is 0 ------------------------------------------------//
  11089. if(gunIndex == 0)
  11090. {
  11091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11092. {
  11093. for(int i=0; i < gunTotalNumber; i++)
  11094. {
  11095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11096. {
  11097. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11098. {
  11099. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11100. {
  11101. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11102. goto end;
  11103. }
  11104. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11105. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11106. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11107. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11108. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11109. {
  11110. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11111. goto end;
  11112. }
  11113. }
  11114. }//END FOR CHAdeMO_QUANTITY
  11115. for (int index = 0; index < CCS_QUANTITY; index++)
  11116. {
  11117. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11118. {
  11119. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11120. {
  11121. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11122. goto end;
  11123. }
  11124. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11126. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11127. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11128. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11129. {
  11130. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11131. goto end;
  11132. }
  11133. }
  11134. }//END FOR CCS_QUANTITY
  11135. for (int index = 0; index < GB_QUANTITY; index++)
  11136. {
  11137. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11138. {
  11139. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11140. {
  11141. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11142. goto end;
  11143. }
  11144. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11145. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11146. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11147. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11148. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11149. {
  11150. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11151. goto end;
  11152. }
  11153. }
  11154. }// END FOR GB_QUANTITY
  11155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11156. {
  11157. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11158. {
  11159. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11160. {
  11161. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11162. goto end;
  11163. }
  11164. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11165. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11168. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11169. {
  11170. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11171. goto end;
  11172. }
  11173. }
  11174. }// END FOR DO_QUANTITY
  11175. for (int index = 0; index < AC_QUANTITY; index++)
  11176. {
  11177. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11178. {
  11179. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11180. {
  11181. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11182. goto end;
  11183. }
  11184. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11185. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11186. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11187. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11189. {
  11190. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11191. goto end;
  11192. }
  11193. }
  11194. }//END FOR AC_QUANTITY
  11195. }// END FOR gunTotalNumber
  11196. }
  11197. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11198. {
  11199. for(int i=0; i < gunTotalNumber; i++)
  11200. {
  11201. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11202. {
  11203. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11204. goto end;
  11205. }
  11206. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11207. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11208. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11209. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11210. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11211. {
  11212. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11213. goto end;
  11214. }
  11215. }
  11216. }
  11217. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11218. goto end;
  11219. }
  11220. //----------------------gunIndex is not 0 ------------------------------------------------//
  11221. //check Transaction active
  11222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11223. {
  11224. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  11225. {
  11226. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11227. {
  11228. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11229. goto end;
  11230. }
  11231. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11232. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11233. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11234. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11235. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11236. {
  11237. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11238. goto end;
  11239. }
  11240. else
  11241. {
  11242. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11243. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11244. goto end;
  11245. }
  11246. }
  11247. }//END FOR CHAdeMO_QUANTITY
  11248. for (int index = 0; index < CCS_QUANTITY; index++)
  11249. {
  11250. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  11251. {
  11252. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11253. {
  11254. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11255. goto end;
  11256. }
  11257. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11258. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11259. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11260. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11261. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11262. {
  11263. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11264. goto end;
  11265. }
  11266. else
  11267. {
  11268. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11269. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11270. goto end;
  11271. }
  11272. }
  11273. }//END FOR CCS_QUANTITY
  11274. for (int index = 0; index < GB_QUANTITY; index++)
  11275. {
  11276. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  11277. {
  11278. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11279. {
  11280. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11281. goto end;
  11282. }
  11283. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11284. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11285. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11286. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11287. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11288. {
  11289. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11290. goto end;
  11291. }
  11292. else
  11293. {
  11294. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11295. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11296. goto end;
  11297. }
  11298. }
  11299. }// END FOR GB_QUANTITY
  11300. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11301. {
  11302. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  11303. {
  11304. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11305. {
  11306. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11307. goto end;
  11308. }
  11309. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11310. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11311. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11312. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11313. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11314. {
  11315. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11316. goto end;
  11317. }
  11318. else
  11319. {
  11320. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11321. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11322. goto end;
  11323. }
  11324. }
  11325. }// END FOR DO_QUANTITY
  11326. for (int index = 0; index < AC_QUANTITY; index++)
  11327. {
  11328. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  11329. {
  11330. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11331. {
  11332. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11333. goto end;
  11334. }
  11335. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11336. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11337. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11338. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11339. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11340. {
  11341. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11342. goto end;
  11343. }
  11344. else
  11345. {
  11346. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11347. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11348. goto end;
  11349. }
  11350. }
  11351. }//END FOR AC_QUANTITY
  11352. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11353. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11354. {
  11355. //----------------------gunIndex is 0 ------------------------------------------------//
  11356. if(gunIndex == 0)
  11357. {
  11358. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11359. {
  11360. for(int i=0; i < gunTotalNumber; i++)
  11361. {
  11362. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11363. {
  11364. 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
  11365. {
  11366. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11367. goto end;
  11368. }
  11369. }//END FOR CHAdeMO_QUANTITY
  11370. for (int index = 0; index < CCS_QUANTITY; index++)
  11371. {
  11372. 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
  11373. {
  11374. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11375. goto end;
  11376. }
  11377. }//END FOR CCS_QUANTITY
  11378. for (int index = 0; index < GB_QUANTITY; index++)
  11379. {
  11380. 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
  11381. {
  11382. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11383. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11384. goto end;
  11385. }
  11386. }// END FOR GB_QUANTITY
  11387. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11388. {
  11389. 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
  11390. {
  11391. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11392. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11393. goto end;
  11394. }
  11395. }// END FOR DO_QUANTITY
  11396. for (int index = 0; index < AC_QUANTITY; index++)
  11397. {
  11398. 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
  11399. {
  11400. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11401. goto end;
  11402. }
  11403. }//END FOR CHAdeMO_QUANTITY
  11404. }// END FOR gunTotalNumber
  11405. }
  11406. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11407. {
  11408. for(int i=0; i < gunTotalNumber; i++)
  11409. {
  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. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11421. goto end;
  11422. }
  11423. //----------------------gunIndex is not 0 ------------------------------------------------//
  11424. //check Transaction active
  11425. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11426. {
  11427. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11428. {
  11429. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11430. goto end;
  11431. }
  11432. }//END FOR CHAdeMO_QUANTITY
  11433. for (int index = 0; index < CCS_QUANTITY; index++)
  11434. {
  11435. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11436. {
  11437. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11438. goto end;
  11439. }
  11440. }//END FOR CCS_QUANTITY
  11441. for (int index = 0; index < GB_QUANTITY; index++)
  11442. {
  11443. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11444. {
  11445. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11446. goto end;
  11447. }
  11448. }// END FOR GB_QUANTITY
  11449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11450. {
  11451. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11452. {
  11453. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11454. goto end;
  11455. }
  11456. }// END FOR DO_QUANTITY
  11457. for (int index = 0; index < AC_QUANTITY; index++)
  11458. {
  11459. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11460. {
  11461. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11462. goto end;
  11463. }
  11464. }//END FOR AC_QUANTITY
  11465. }//END FOR AvailabilityEnumTypeStr[Operative]
  11466. end:
  11467. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11468. {
  11469. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  11470. }
  11471. else
  11472. {
  11473. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11474. }
  11475. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11476. {
  11477. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11478. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11479. }
  11480. else if(gunIndex == 0)
  11481. {
  11482. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11483. {
  11484. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  11485. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  11486. }
  11487. }
  11488. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  11489. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11490. return result;
  11491. }
  11492. int handleClearCacheRequest(char *uuid, char *payload)
  11493. {
  11494. mtrace();
  11495. int result = FAIL;
  11496. char rmFileCmd[100]={0};
  11497. struct stat stats;
  11498. DEBUG_INFO("handleClearCacheRequest...\n");
  11499. stat("/Storage/OCPP", &stats);
  11500. // Check for directory existence
  11501. if (S_ISDIR(stats.st_mode) == 1)
  11502. {}
  11503. else
  11504. {
  11505. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  11506. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  11507. system(rmFileCmd);
  11508. }
  11509. if(DB_cleanLocalCache() != PASS)
  11510. {
  11511. DEBUG_INFO("open AuthorizationCache file failed\n");
  11512. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  11513. }
  11514. else
  11515. {
  11516. DEBUG_INFO("open AuthorizationCache file successful\n");
  11517. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  11518. }
  11519. sendClearCacheConfirmation(uuid);
  11520. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11521. return result;
  11522. }
  11523. int handleClearChargingProfileRequest(char *uuid, char *payload)
  11524. {
  11525. mtrace();
  11526. int result = FAIL;
  11527. int resultRename;
  11528. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  11529. char chargingProfilePurposeStr[26]={0};
  11530. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  11531. char tempchargingProfilePurposeStr[26]={0};
  11532. char sstr[160]={0};
  11533. char str[100]={0};
  11534. int c = 0;
  11535. char *loc;
  11536. char fname[200]={0};
  11537. char comfirmstr[20]={0};
  11538. char word[1600]={0};
  11539. int clearflag = FALSE;
  11540. int chargingProfileIdIsNULL = FALSE;
  11541. int connectorIsNULL = FALSE;
  11542. int chargingProfilePurposeIsNULL = FALSE;
  11543. int stackLevelIsNULL = FALSE;
  11544. //int GotoEnd = FALSE;
  11545. FILE *fptr1, *fptr2;
  11546. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  11547. int n_chargingProfile=0;
  11548. int isEmptyFile = FALSE;
  11549. char sLineWord[1600]={0};
  11550. char chargingProfiles[10][100]={0};
  11551. int ChargeProfileCount = 0;
  11552. int ch;
  11553. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11554. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11555. json_object *ClearChargingProfile;
  11556. ClearChargingProfile = json_tokener_parse(payload);
  11557. if(!is_error(ClearChargingProfile))
  11558. {
  11559. // Optional data
  11560. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  11561. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  11562. else
  11563. chargingProfileIdIsNULL = TRUE;
  11564. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  11565. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  11566. else
  11567. connectorIsNULL = TRUE;
  11568. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  11569. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  11570. else
  11571. chargingProfilePurposeIsNULL = TRUE;
  11572. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  11573. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  11574. else
  11575. stackLevelIsNULL = TRUE;
  11576. }
  11577. json_object_put(ClearChargingProfile);
  11578. if(connectorIsNULL == FALSE)
  11579. {
  11580. switch(connectorIdInt)
  11581. {
  11582. case 0:
  11583. if(chargingProfilePurposeIsNULL == TRUE)
  11584. {
  11585. int l = 0;
  11586. strcpy(fname, ChargingStationMaxProfile_JSON);
  11587. if((access(fname,F_OK))!=-1)
  11588. {
  11589. strcpy(chargingProfiles[l], fname);
  11590. l = l + 1;
  11591. }
  11592. strcpy(fname, TxDefaultProfile_0_JSON);
  11593. if((access(fname,F_OK))!=-1)
  11594. {
  11595. strcpy(chargingProfiles[l], fname);
  11596. l = l + 1;
  11597. }
  11598. ChargeProfileCount = l;
  11599. }
  11600. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  11601. {
  11602. strcpy(fname, ChargingStationMaxProfile_JSON);
  11603. if((access(fname,F_OK))!=-1)
  11604. {
  11605. strcpy(chargingProfiles[0], fname);
  11606. ChargeProfileCount = 1;
  11607. }
  11608. }
  11609. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11610. {
  11611. strcpy(fname, TxDefaultProfile_0_JSON);
  11612. if((access(fname,F_OK))!=-1)
  11613. {
  11614. strcpy(chargingProfiles[0], fname);
  11615. ChargeProfileCount = 1;
  11616. }
  11617. }
  11618. break;
  11619. default:
  11620. if(chargingProfilePurposeIsNULL == TRUE)
  11621. {
  11622. int m = 0;
  11623. memset(fname, 0, ARRAY_SIZE(fname));
  11624. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11625. if((access(fname,F_OK))!=-1)
  11626. {
  11627. strcpy(chargingProfiles[m], fname);
  11628. m = m + 1;
  11629. }
  11630. memset(fname, 0, ARRAY_SIZE(fname));
  11631. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11632. if((access(fname,F_OK))!=-1)
  11633. {
  11634. strcpy(chargingProfiles[m], fname);
  11635. m = m + 1;
  11636. }
  11637. ChargeProfileCount = m;
  11638. }
  11639. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11640. {
  11641. //strcpy(fname, TxDefaultProfile_1_JSON);
  11642. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11643. if((access(fname,F_OK))!=-1)
  11644. {
  11645. strcpy(chargingProfiles[0], fname);
  11646. ChargeProfileCount = 1;
  11647. }
  11648. }
  11649. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  11650. {
  11651. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11652. if((access(fname,F_OK))!=-1)
  11653. {
  11654. strcpy(chargingProfiles[0], fname);
  11655. ChargeProfileCount = 1;
  11656. }
  11657. }
  11658. //strcpy(fname, ChargePointMaxProfile_JSON );
  11659. break;
  11660. }
  11661. }
  11662. else // Check all Charging Profiles
  11663. {
  11664. int i = 0;
  11665. char fnametemp[200]={0};
  11666. ChargeProfileCount = 0;
  11667. //Check ChargePointMaxProfile.json exit
  11668. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11669. {
  11670. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  11671. i = i + 1;
  11672. }
  11673. //Check TxDefaultProfile_%d.json
  11674. for(int j=1; j <= gunTotalNumber; j++)
  11675. {
  11676. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11677. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  11678. if((access(fnametemp,F_OK))!=-1)
  11679. {
  11680. strcpy(chargingProfiles[i], fnametemp);
  11681. i = i + 1;
  11682. }
  11683. }
  11684. //Check TxProfile_%d.json
  11685. for(int j=1; j <= gunTotalNumber; j++)
  11686. {
  11687. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11688. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  11689. if((access(fnametemp,F_OK))!=-1)
  11690. {
  11691. strcpy(chargingProfiles[i], fnametemp);
  11692. i = i + 1;
  11693. }
  11694. }
  11695. ChargeProfileCount = i;
  11696. }// End connectorIsNULL is TRUE
  11697. if(ChargeProfileCount == 0)
  11698. {
  11699. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11700. goto end;
  11701. }
  11702. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  11703. {
  11704. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11705. goto end;
  11706. }
  11707. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  11708. {
  11709. memset(str, 0, ARRAY_SIZE(str));
  11710. // clear temp file
  11711. sprintf(str,"rm -f %s",temp);
  11712. system(str);
  11713. for(int k=0; k < ChargeProfileCount; k++)
  11714. {
  11715. memset(str, 0, ARRAY_SIZE(str));
  11716. //clear file in C
  11717. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11718. system(str);
  11719. }
  11720. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11721. goto end;
  11722. }
  11723. else if(connectorIsNULL == TRUE)
  11724. {
  11725. for(int k=0; k < ChargeProfileCount; k++)
  11726. {
  11727. fptr1 = fopen(chargingProfiles[k], "r");
  11728. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  11729. //Check Charging Profile Count
  11730. while(fscanf(fptr1, "%s", word) != EOF)
  11731. {
  11732. //DEBUG_INFO("word=%s\n",word);
  11733. if(strstr(word, "id")!= NULL)
  11734. {
  11735. //DEBUG_INFO("test id \n");
  11736. n_chargingProfile = n_chargingProfile + 1;
  11737. //DEBUG_INFO("id Found\n");
  11738. }
  11739. }
  11740. rewind(fptr1);
  11741. //search Charging Profile Element
  11742. //int i= 0;
  11743. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11744. {
  11745. //------------------------tempconnectorIdInt------------------------//
  11746. loc = strstr(sLineWord, "connectorId");
  11747. c = 0;
  11748. memset(sstr ,0, sizeof(sstr) );
  11749. while (loc[strlen("connectorId")+2+c] != ',')
  11750. {
  11751. sstr[c] = loc[strlen("connectorId")+2+c];
  11752. c++;
  11753. }
  11754. sstr[c] = '\0';
  11755. tempconnectorIdInt = atoi(sstr);
  11756. printf("file's gun number is %d\n", tempconnectorIdInt);
  11757. //--------------------------id--------------------//
  11758. c = 0;
  11759. loc = strstr(sLineWord, "id");
  11760. memset(sstr ,0, ARRAY_SIZE(sstr));
  11761. while (loc[strlen("id")+2+c] != ',')
  11762. {
  11763. sstr[c] = loc[strlen("id")+2+c];
  11764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11765. c++;
  11766. }
  11767. sstr[c] = '\0';
  11768. tempchargingProfileIdInt = atoi(sstr);
  11769. //stackLevel
  11770. c = 0;
  11771. loc = strstr(sLineWord, "stackLevel");
  11772. memset(sstr ,0, ARRAY_SIZE(sstr));
  11773. while (loc[strlen("stackLevel")+2+c] != ',')
  11774. {
  11775. sstr[c] = loc[strlen("stackLevel")+2+c];
  11776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11777. c++;
  11778. }
  11779. sstr[c] = '\0';
  11780. tempstackLevelInt = atoi(sstr);
  11781. c = 0;
  11782. loc = strstr(sLineWord, "chargingProfilePurpose");
  11783. memset(sstr ,0, ARRAY_SIZE(sstr));
  11784. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11785. {
  11786. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11787. c++;
  11788. }
  11789. sstr[c] = '\0';
  11790. strcpy(tempchargingProfilePurposeStr, sstr);
  11791. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11792. {
  11793. //------- not write to fptr2-------//
  11794. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11795. //clearflag = TRUE;
  11796. }
  11797. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11798. {
  11799. //------- not write to fptr2-------//
  11800. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11801. }
  11802. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  11803. {
  11804. //------- not write to fptr2-------//
  11805. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11806. }
  11807. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  11808. {
  11809. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11810. }
  11811. else
  11812. {
  11813. fprintf(fptr2, sLineWord);//writing data into file
  11814. }
  11815. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11816. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11817. if(clearflag == TRUE)
  11818. {
  11819. fclose(fptr1);
  11820. fclose(fptr2);
  11821. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11822. system(str);
  11823. // clear temp file
  11824. sprintf(str,"rm -f %s",temp);
  11825. system(str);
  11826. }
  11827. else
  11828. {
  11829. fclose(fptr1);
  11830. fclose(fptr2);
  11831. memset(str, 0, ARRAY_SIZE(str));
  11832. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11833. system(str);
  11834. resultRename = rename(temp, chargingProfiles[k]);
  11835. if(resultRename == 0)
  11836. {
  11837. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  11838. }
  11839. else
  11840. {
  11841. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  11842. }
  11843. if(comfirmstr[0]== 0)
  11844. {
  11845. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11846. }
  11847. //Check chargingProfile is empty file
  11848. /*------ Read the file ----------------*/
  11849. fptr1=fopen(chargingProfiles[k],"r");
  11850. ch=fgetc(fptr1);
  11851. rewind(fptr1);
  11852. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11853. if(ch!=EOF)
  11854. {
  11855. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  11856. {
  11857. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  11858. if(sLineWord[0]=='\0')
  11859. {
  11860. isEmptyFile = TRUE;
  11861. break;
  11862. }
  11863. else
  11864. {
  11865. isEmptyFile = FALSE;
  11866. break;
  11867. }
  11868. }
  11869. }
  11870. else
  11871. isEmptyFile = TRUE;
  11872. fclose(fptr1);
  11873. if(isEmptyFile == TRUE)
  11874. {
  11875. memset(str, 0, ARRAY_SIZE(str));
  11876. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11877. system(str);
  11878. }
  11879. }
  11880. }// End of while(int k=0; k < ChargePointCount; k++)
  11881. }
  11882. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  11883. {
  11884. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  11885. for(int k=0; k < ChargeProfileCount; k++)
  11886. {
  11887. fptr1 = fopen(chargingProfiles[k], "r");
  11888. fptr2 = fopen(temp, "w+");
  11889. //Check Charging Profile Count
  11890. while(fscanf(fptr1, "%s", word) != EOF)
  11891. {
  11892. //DEBUG_INFO("word=%s\n",word);
  11893. if(strstr(word, "id")!= NULL)
  11894. {
  11895. n_chargingProfile = n_chargingProfile + 1;
  11896. }
  11897. }
  11898. rewind(fptr1);
  11899. //search Charging Profile Element
  11900. //int i= 0;
  11901. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11902. {
  11903. //*************************tempconnectorIdInt*********************************/
  11904. loc = strstr(sLineWord, "connectorId");
  11905. c = 0;
  11906. memset(sstr ,0, ARRAY_SIZE(sstr));
  11907. while (loc[strlen("connectorId")+2+c] != ',')
  11908. {
  11909. sstr[c] = loc[strlen("connectorId")+2+c];
  11910. c++;
  11911. }
  11912. sstr[c] = '\0';
  11913. tempconnectorIdInt = atoi(sstr);
  11914. //id
  11915. c = 0;
  11916. loc = strstr(sLineWord, "id");
  11917. memset(sstr ,0, ARRAY_SIZE(sstr));
  11918. while (loc[strlen("id")+2+c] != ',')
  11919. {
  11920. sstr[c] = loc[strlen("id")+2+c];
  11921. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11922. c++;
  11923. }
  11924. sstr[c] = '\0';
  11925. tempchargingProfileIdInt = atoi(sstr);
  11926. //stackLevel
  11927. c = 0;
  11928. loc = strstr(sLineWord, "stackLevel");
  11929. memset(sstr ,0, ARRAY_SIZE(sstr));
  11930. while (loc[strlen("stackLevel")+2+c] != ',')
  11931. {
  11932. sstr[c] = loc[strlen("stackLevel")+2+c];
  11933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11934. c++;
  11935. }
  11936. sstr[c] = '\0';
  11937. tempstackLevelInt = atoi(sstr);
  11938. c = 0;
  11939. loc = strstr(sLineWord, "chargingProfilePurpose");
  11940. memset(sstr ,0, ARRAY_SIZE(sstr));
  11941. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11942. {
  11943. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11944. c++;
  11945. }
  11946. sstr[c] = '\0';
  11947. strcpy(tempchargingProfilePurposeStr, sstr);
  11948. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11949. {
  11950. //------- not write to fptr2-------//
  11951. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11952. //clearflag = TRUE;
  11953. }
  11954. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  11955. {
  11956. //------- not write to fptr2-------//
  11957. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11958. }
  11959. else if(stackLevelIsNULL == TRUE)
  11960. {
  11961. //Clear Whole File
  11962. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11963. clearflag = TRUE;
  11964. break;
  11965. }
  11966. else
  11967. {
  11968. fprintf(fptr2, sLineWord);//writing data into file
  11969. }
  11970. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11971. }
  11972. if(clearflag == TRUE)
  11973. {
  11974. fclose(fptr1);
  11975. fclose(fptr2);
  11976. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11977. system(str);
  11978. // clear temp file
  11979. sprintf(str,"rm -f %s",temp);
  11980. system(str);
  11981. }
  11982. else
  11983. {
  11984. fclose(fptr1);
  11985. fclose(fptr2);
  11986. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11987. system(str);
  11988. resultRename = rename(temp, chargingProfiles[k]);
  11989. if(resultRename == 0)
  11990. {
  11991. DEBUG_INFO("File ChargingProfile renamed successfully");
  11992. }
  11993. else
  11994. {
  11995. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  11996. }
  11997. if(comfirmstr[0]== 0)
  11998. {
  11999. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12000. }
  12001. //Check chargingProfile is empty file
  12002. /*------ Read the file ----------------*/
  12003. fptr1=fopen(chargingProfiles[k],"r");
  12004. ch=fgetc(fptr1);
  12005. rewind(fptr1);
  12006. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12007. if(ch!=EOF)
  12008. {
  12009. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12010. {
  12011. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12012. if(sLineWord[0]=='\0')
  12013. {
  12014. isEmptyFile = TRUE;
  12015. break;
  12016. }
  12017. else
  12018. {
  12019. isEmptyFile = FALSE;
  12020. break;
  12021. }
  12022. }
  12023. }
  12024. else
  12025. isEmptyFile = TRUE;
  12026. fclose(fptr1);
  12027. if(isEmptyFile == TRUE)
  12028. {
  12029. memset(str, 0, ARRAY_SIZE(str));
  12030. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12031. system(str);
  12032. }
  12033. /*------- End of reading ---------------*/
  12034. }
  12035. } // while(int k=0; k < ChargeProfileCount; k++)
  12036. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12037. end:
  12038. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12039. {
  12040. if(connectorIdInt == 0)
  12041. {
  12042. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12043. {
  12044. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12045. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12046. }
  12047. }
  12048. else
  12049. {
  12050. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12051. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  12052. }
  12053. }
  12054. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12055. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12056. return result;
  12057. }
  12058. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12059. {
  12060. mtrace();
  12061. int result = FAIL;
  12062. json_object *ClearDisplayMessage;
  12063. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12064. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12065. ClearDisplayMessage = json_tokener_parse(payload);
  12066. if(!is_error(ClearDisplayMessage))
  12067. {
  12068. // Required data
  12069. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12070. {
  12071. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12072. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12073. }
  12074. }
  12075. json_object_put(ClearDisplayMessage);
  12076. sendCostUpdatedConfirmation(uuid);
  12077. return result;
  12078. }
  12079. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12080. {
  12081. mtrace();
  12082. int result = FAIL;
  12083. json_object *ClearVariableMonitorin;
  12084. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12085. ClearVariableMonitorin = json_tokener_parse(payload);
  12086. if(!is_error(ClearVariableMonitorin))
  12087. {
  12088. // Required data
  12089. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12090. {
  12091. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12092. {
  12093. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12094. /*
  12095. * TODO:
  12096. * 1. Check response
  12097. */
  12098. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12099. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12100. }
  12101. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12102. }
  12103. }
  12104. json_object_put(ClearVariableMonitorin);
  12105. return result;
  12106. }
  12107. int handleCostUpdatedRequest(char *uuid, char *payload)
  12108. {
  12109. mtrace();
  12110. int result = FAIL;
  12111. json_object *CostUpdate;
  12112. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12113. CostUpdate = json_tokener_parse(payload);
  12114. if(!is_error(CostUpdate))
  12115. {
  12116. // Required data
  12117. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12118. {
  12119. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12120. }
  12121. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12122. {
  12123. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12124. }
  12125. }
  12126. json_object_put(CostUpdate);
  12127. sendCostUpdatedConfirmation(uuid);
  12128. return result;
  12129. }
  12130. int handleCustomerInformationRequest(char *uuid, char *payload)
  12131. {
  12132. mtrace();
  12133. int result = FAIL;
  12134. json_object *CustomerInformation;
  12135. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12136. CustomerInformation = json_tokener_parse(payload);
  12137. if(!is_error(CustomerInformation))
  12138. {
  12139. // Required data
  12140. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12141. {
  12142. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12143. }
  12144. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12145. {
  12146. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12147. }
  12148. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12149. {
  12150. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12151. }
  12152. // Optional data
  12153. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12154. {
  12155. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12156. {
  12157. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12158. }
  12159. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12160. {
  12161. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12162. }
  12163. }
  12164. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12165. {
  12166. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12167. {
  12168. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12169. }
  12170. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12171. {
  12172. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12173. }
  12174. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12175. {
  12176. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12177. }
  12178. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12179. {
  12180. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12181. }
  12182. }
  12183. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12184. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12185. }
  12186. else
  12187. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12188. json_object_put(CustomerInformation);
  12189. sendCustomerInformationConfirmation(uuid);
  12190. return result;
  12191. }
  12192. void createFirmwareVersionByDataTransfer(void)
  12193. {
  12194. json_object *FirmwareDataTransfer = json_object_new_object();
  12195. // AC & DC model
  12196. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12197. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12198. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12199. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12200. // DC model
  12201. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12202. {
  12203. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12204. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12205. (gunType[3] != GUN_TYPE_UNKNOWN))
  12206. {
  12207. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12208. }
  12209. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12210. {
  12211. // DS DM DW
  12212. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12213. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12214. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12215. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12216. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12217. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12218. }
  12219. else
  12220. {
  12221. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12222. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12223. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12224. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12225. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12226. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12227. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12228. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12229. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12230. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12231. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12232. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12233. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12234. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12235. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12236. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12237. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12238. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12239. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12240. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12241. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12242. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12243. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12244. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12245. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12246. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12247. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12248. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12249. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12250. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12251. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12252. }
  12253. }
  12254. // 4G model
  12255. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12256. {
  12257. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12258. }
  12259. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12260. json_object_put(FirmwareDataTransfer);
  12261. }
  12262. int handleDataTransferRequest(char *uuid, char *payload)
  12263. {
  12264. mtrace();
  12265. int result = PASS;
  12266. DEBUG_INFO("handleDataTransferRequest...\n");
  12267. if((uuid != NULL) && (payload != NULL))
  12268. {
  12269. json_object *DataTransfer;
  12270. DataTransfer = json_tokener_parse(payload);
  12271. if(!is_error(DataTransfer))
  12272. {
  12273. // Required data
  12274. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12275. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12276. // Optional data
  12277. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12278. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12279. if(json_object_object_get(DataTransfer, "data") != NULL)
  12280. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12281. result = PASS;
  12282. }
  12283. json_object_put(DataTransfer);
  12284. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12285. {
  12286. // Send all moudle firmware version on EVSE
  12287. createFirmwareVersionByDataTransfer();
  12288. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12289. }
  12290. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12291. {
  12292. system("/usr/bin/run_tmate_restart.sh &");
  12293. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12294. }
  12295. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12296. {
  12297. json_object *data;
  12298. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12299. if(!is_error(data))
  12300. {
  12301. 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))
  12302. {
  12303. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12304. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12305. if(json_object_object_get(data, "SOC") != NULL)
  12306. {
  12307. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12308. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12309. }
  12310. if(json_object_object_get(data, "Energy") != NULL)
  12311. {
  12312. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12313. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12314. }
  12315. if(json_object_object_get(data, "Duration") != NULL)
  12316. {
  12317. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12318. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12319. }
  12320. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12321. }
  12322. else
  12323. {
  12324. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12325. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12326. }
  12327. }
  12328. else
  12329. {
  12330. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12331. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12332. }
  12333. json_object_put(data);
  12334. }
  12335. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12336. {
  12337. json_object *data;
  12338. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12339. if(!is_error(data))
  12340. {
  12341. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12342. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12343. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12344. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12345. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12346. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12347. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12348. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12349. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12350. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12351. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12352. }
  12353. else
  12354. {
  12355. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12356. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12357. }
  12358. json_object_put(data);
  12359. }
  12360. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12361. {
  12362. json_object *data;
  12363. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12364. if(!is_error(data))
  12365. {
  12366. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12367. if(json_object_object_get(data, "Content_Type") != NULL)
  12368. {
  12369. 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))
  12370. {
  12371. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12372. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12373. {
  12374. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12375. }
  12376. }
  12377. else
  12378. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12379. }
  12380. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12381. }
  12382. else
  12383. {
  12384. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12385. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12386. }
  12387. json_object_put(data);
  12388. }
  12389. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12390. {
  12391. json_object *data;
  12392. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12393. if(!is_error(data))
  12394. {
  12395. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12396. if(json_object_object_get(data, "ConnectorId") != NULL)
  12397. {
  12398. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12399. }
  12400. if(json_object_object_get(data, "Page_Index") != NULL)
  12401. {
  12402. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12403. }
  12404. if(json_object_object_get(data, "Duration") != NULL)
  12405. {
  12406. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12407. }
  12408. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12409. }
  12410. else
  12411. {
  12412. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12413. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12414. }
  12415. json_object_put(data);
  12416. }
  12417. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12418. {
  12419. json_object *data;
  12420. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12421. if(!is_error(data))
  12422. {
  12423. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12424. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12425. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12426. {
  12427. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12428. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12429. else
  12430. {
  12431. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12432. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12433. }
  12434. }
  12435. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12436. {
  12437. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12438. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12439. else
  12440. {
  12441. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12442. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12443. }
  12444. }
  12445. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12446. {
  12447. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12448. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12449. else
  12450. {
  12451. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12452. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12453. }
  12454. }
  12455. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12456. {
  12457. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12458. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12459. else
  12460. {
  12461. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12462. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12463. }
  12464. }
  12465. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12466. {
  12467. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12468. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12469. else
  12470. {
  12471. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12472. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12473. }
  12474. }
  12475. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12476. {
  12477. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  12478. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  12479. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  12480. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  12481. else
  12482. {
  12483. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12484. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12485. }
  12486. }
  12487. if(json_object_object_get(data, "isAuthentication") != NULL)
  12488. {
  12489. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  12490. {
  12491. case 0:
  12492. case 1:
  12493. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  12494. break;
  12495. default:
  12496. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12497. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12498. break;
  12499. }
  12500. }
  12501. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  12502. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12503. }
  12504. else
  12505. {
  12506. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12507. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12508. }
  12509. json_object_put(data);
  12510. }
  12511. else
  12512. {
  12513. // Can not find valid message id
  12514. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12515. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  12516. ,ShmOCPP20Data->DataTransfer[0].vendorId
  12517. ,ShmOCPP20Data->DataTransfer[0].messageId
  12518. ,ShmOCPP20Data->DataTransfer[0].data);
  12519. }
  12520. }
  12521. else
  12522. {
  12523. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12524. result = FAIL;
  12525. }
  12526. sendDataTransferConfirmation(uuid, 0);
  12527. return result;
  12528. }
  12529. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12530. {
  12531. mtrace();
  12532. int result = FAIL;
  12533. json_object *DeleteCertificate;
  12534. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12535. DeleteCertificate = json_tokener_parse(payload);
  12536. if(!is_error(DeleteCertificate))
  12537. {
  12538. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  12539. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  12540. // Required data
  12541. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  12542. {
  12543. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  12544. {
  12545. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12546. }
  12547. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  12548. {
  12549. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12550. }
  12551. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  12552. {
  12553. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12554. }
  12555. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  12556. {
  12557. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12558. }
  12559. /*
  12560. * TODO:
  12561. * 1. Delete certification and response
  12562. */
  12563. if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA256]) != NULL)
  12564. {
  12565. }
  12566. else if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA384]) != NULL)
  12567. {
  12568. }
  12569. else
  12570. {
  12571. }
  12572. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  12573. }
  12574. }
  12575. else
  12576. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  12577. json_object_put(DeleteCertificate);
  12578. sendDeleteCertificateConfirmation(uuid);
  12579. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12580. return result;
  12581. }
  12582. int handleGetBaseReportRequest(char *uuid, char *payload)
  12583. {
  12584. mtrace();
  12585. int result = FAIL;
  12586. json_object *GetBaseRepor;
  12587. DEBUG_INFO("handleGetBaseReportRequest...\n");
  12588. GetBaseRepor = json_tokener_parse(payload);
  12589. if(!is_error(GetBaseRepor))
  12590. {
  12591. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  12592. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  12593. // Required data
  12594. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  12595. {
  12596. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  12597. }
  12598. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  12599. {
  12600. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  12601. }
  12602. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  12603. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12604. else
  12605. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12606. }
  12607. else
  12608. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12609. json_object_put(GetBaseRepor);
  12610. sendGetBaseReportConfirmation(uuid);
  12611. return result;
  12612. }
  12613. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  12614. {
  12615. mtrace();
  12616. int result = FAIL;
  12617. int gun_index = -1;
  12618. json_object *GetChargingProfiles;
  12619. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  12620. GetChargingProfiles = json_tokener_parse(payload);
  12621. if(!is_error(GetChargingProfiles))
  12622. {
  12623. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  12624. {
  12625. 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;
  12626. }
  12627. if(gun_index >-1)
  12628. {
  12629. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  12630. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  12631. // Required data
  12632. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  12633. {
  12634. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  12635. }
  12636. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  12637. {
  12638. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  12639. {
  12640. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  12641. }
  12642. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  12643. {
  12644. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  12645. }
  12646. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  12647. {
  12648. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  12649. {
  12650. 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)));
  12651. }
  12652. }
  12653. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  12654. {
  12655. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  12656. {
  12657. 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));
  12658. }
  12659. }
  12660. }
  12661. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  12662. }
  12663. else
  12664. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  12665. }
  12666. json_object_put(GetChargingProfiles);
  12667. sendGetChargingProfilesConfirmation(uuid, gun_index);
  12668. return result;
  12669. }
  12670. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  12671. {
  12672. mtrace();
  12673. int result = FAIL;
  12674. int connectorIdInt, durationInt;
  12675. char chargingRateUnitStr[4]={0};
  12676. char comfirmstr[20];
  12677. int confirmPeriods = 0;
  12678. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  12679. json_object *GetCompositeSchedule;
  12680. GetCompositeSchedule = json_tokener_parse(payload);
  12681. if(!is_error(GetCompositeSchedule))
  12682. {
  12683. // Required data
  12684. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  12685. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  12686. else
  12687. connectorIdInt = -1;
  12688. if(json_object_object_get(GetCompositeSchedule, "duration"))
  12689. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  12690. else
  12691. durationInt = 86400;
  12692. // Optional data
  12693. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  12694. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  12695. }
  12696. json_object_put(GetCompositeSchedule);
  12697. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  12698. if((connectorIdInt == 0) ||
  12699. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  12700. {
  12701. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  12702. struct ChargingProfileType tmpProfile[1];
  12703. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  12704. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  12705. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  12706. {
  12707. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  12708. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  12709. }
  12710. else
  12711. {
  12712. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  12713. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  12714. }
  12715. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12716. {
  12717. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  12718. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  12719. }
  12720. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  12721. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12722. {
  12723. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  12724. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  12725. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  12726. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  12727. (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))
  12728. {
  12729. confirmPeriods = idx;
  12730. break;
  12731. }
  12732. }
  12733. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  12734. {
  12735. confirmPeriods += 1;
  12736. }
  12737. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12738. }
  12739. else
  12740. {
  12741. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  12742. }
  12743. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  12744. return result;
  12745. }
  12746. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  12747. {
  12748. mtrace();
  12749. int result = FAIL;
  12750. json_object *GetDisplayMessages;
  12751. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  12752. GetDisplayMessages = json_tokener_parse(payload);
  12753. if(!is_error(GetDisplayMessages))
  12754. {
  12755. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  12756. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  12757. // Required data
  12758. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  12759. {
  12760. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  12761. }
  12762. // Optional data
  12763. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  12764. {
  12765. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  12766. }
  12767. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  12768. {
  12769. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  12770. }
  12771. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  12772. {
  12773. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  12774. {
  12775. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  12776. }
  12777. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  12778. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  12779. }
  12780. else
  12781. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  12782. }
  12783. json_object_put(GetDisplayMessages);
  12784. return result;
  12785. }
  12786. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12787. {
  12788. mtrace();
  12789. int result = FAIL;
  12790. json_object *GetInstalledCertificateIds;
  12791. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12792. GetInstalledCertificateIds = json_tokener_parse(payload);
  12793. if(!is_error(GetInstalledCertificateIds))
  12794. {
  12795. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  12796. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  12797. // Optional data
  12798. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  12799. {
  12800. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  12801. {
  12802. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  12803. /*
  12804. * TODO:
  12805. * 1. Get installed certificate info for response
  12806. */
  12807. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GRootCertificate]) != NULL)
  12808. {
  12809. }
  12810. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_MORootCertificate]) != NULL)
  12811. {
  12812. }
  12813. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_CSMSRootCertificate]) != NULL)
  12814. {
  12815. }
  12816. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GCertificateChain]) != NULL)
  12817. {
  12818. }
  12819. else
  12820. {
  12821. }
  12822. }
  12823. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  12824. }
  12825. else
  12826. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  12827. }
  12828. json_object_put(GetInstalledCertificateIds);
  12829. sendInstallCertificateConfirmation(uuid);
  12830. return result;
  12831. }
  12832. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  12833. {
  12834. mtrace();
  12835. int result = FAIL;
  12836. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  12837. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  12838. {
  12839. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  12840. localversion = 0;
  12841. }
  12842. else
  12843. {
  12844. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  12845. localversion = 0;
  12846. DB_getListVerion();
  12847. }
  12848. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  12849. sendGetLocalListVersionConfirmation(uuid);
  12850. return result;
  12851. }
  12852. static char fnamePlusPath[100]={0};
  12853. static char fnamePWithNoPath[60]={0};
  12854. void checkUploadLog(void)
  12855. {
  12856. FILE *fp;
  12857. /* Open the command for reading. */
  12858. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  12859. if (fp == NULL) {
  12860. printf("Failed to run command\n" );
  12861. exit(1);
  12862. }
  12863. int ftppathlen = 0;
  12864. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  12865. int i = 0;
  12866. /* Read the output a line at a time - output it. */
  12867. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  12868. if(i==0)
  12869. {
  12870. ftppathlen = strlen(fnamePlusPath);
  12871. printf("%s\n", fnamePlusPath);
  12872. fnamePlusPath[ftppathlen]='\0';
  12873. break;
  12874. }
  12875. i= i+1;
  12876. }
  12877. /* close */
  12878. pclose(fp);
  12879. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  12880. {
  12881. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  12882. {
  12883. fnamePlusPath[k]='\0';
  12884. }
  12885. }
  12886. i=1;
  12887. //char fname[60]={0};
  12888. while(i < ftppathlen)
  12889. {
  12890. int len=ftppathlen-i;
  12891. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  12892. {
  12893. printf("compare '/' all right\n");
  12894. break;
  12895. }
  12896. i=i+1;
  12897. }
  12898. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  12899. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  12900. fnamePWithNoPath[i+1] = '\0';
  12901. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  12902. {
  12903. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  12904. {
  12905. fnamePWithNoPath[j]='\0';
  12906. }
  12907. }
  12908. FILE* fp1 = fopen(fnamePlusPath, "r");
  12909. if (fp1)
  12910. {
  12911. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  12912. // file exists
  12913. fclose(fp1);
  12914. }
  12915. else
  12916. {
  12917. // file doesn't exist
  12918. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  12919. }
  12920. }
  12921. void* GetLogProcess(void* data)
  12922. {
  12923. pthread_detach(pthread_self());
  12924. mtrace();
  12925. int requestId, retriesInt=0, retryIntervalInt=0;
  12926. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  12927. 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};
  12928. int port=0;
  12929. int isSuccess = FALSE;
  12930. char ftpbuf[1024]={0};
  12931. char cmdBuf[2048];
  12932. struct tm *tmNow;
  12933. time_t CurrentTime;
  12934. struct tm tmStart;
  12935. struct tm tmStop;
  12936. CurrentTime = time(NULL);
  12937. tmNow=localtime(&CurrentTime);
  12938. uint16_t targetYear, targetMonth;
  12939. json_object *GetLog;
  12940. DEBUG_INFO("GetGetProcess...\n");
  12941. GetLog = json_tokener_parse(data);
  12942. if(!is_error(GetLog))
  12943. {
  12944. // Required data
  12945. if(json_object_object_get(GetLog, "requestId") != NULL)
  12946. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12947. if(json_object_object_get(GetLog, "logType") != NULL)
  12948. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12949. if(json_object_object_get(GetLog, "log") != NULL)
  12950. {
  12951. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  12952. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12953. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12954. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12955. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12956. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12957. }
  12958. // Optional data
  12959. if(json_object_object_get(GetLog, "retries") != NULL)
  12960. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12961. else
  12962. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  12963. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12964. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12965. else
  12966. retryIntervalInt = 30;
  12967. }
  12968. json_object_put(GetLog);
  12969. ShmOCPP20Data->GetLog.requestId = requestId;
  12970. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  12971. {
  12972. /*
  12973. * TODO:
  12974. * 1. Pack security log
  12975. */
  12976. }
  12977. else
  12978. {
  12979. // Pack log to compress file
  12980. 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) &&
  12981. (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))
  12982. {
  12983. // Pack system log
  12984. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  12985. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  12986. targetYear = tmStart.tm_year;
  12987. targetMonth = tmStart.tm_mon;
  12988. do
  12989. {
  12990. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  12991. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  12992. if(targetMonth+1>=13)
  12993. {
  12994. targetYear += 1;
  12995. targetMonth = 1;
  12996. }
  12997. else
  12998. {
  12999. targetMonth += 1;
  13000. }
  13001. }while((targetYear < (tmNow->tm_year+1900)) ||
  13002. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13003. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13004. system(cmdBuf);
  13005. // Pack charging & event log
  13006. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13007. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13008. targetYear = tmStart.tm_year;
  13009. targetMonth = tmStart.tm_mon;
  13010. do
  13011. {
  13012. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13013. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  13014. if(targetMonth+1>=13)
  13015. {
  13016. targetYear += 1;
  13017. targetMonth = 1;
  13018. }
  13019. else
  13020. {
  13021. targetMonth += 1;
  13022. }
  13023. }while((targetYear < (tmNow->tm_year+1900)) ||
  13024. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13025. if(isCancelUploadLog)
  13026. {
  13027. isCancelUploadLog = FALSE;
  13028. pthread_exit(NULL);
  13029. }
  13030. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13031. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13032. system(cmdBuf);
  13033. // Combine log file
  13034. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13035. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13036. }
  13037. else
  13038. {
  13039. system("exec /root/logPackTools 'log' 6");
  13040. }
  13041. }
  13042. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13043. system(cmdBuf);
  13044. checkUploadLog();
  13045. //****************location*******************/
  13046. if(strcmp(remoteLocation,"")==0)
  13047. {
  13048. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13049. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13050. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13051. goto end;
  13052. }
  13053. memset(protocol, 0, ARRAY_SIZE(protocol));
  13054. memset(user, 0, ARRAY_SIZE(user) );
  13055. memset(password, 0, ARRAY_SIZE(password));
  13056. memset(host, 0, ARRAY_SIZE(host));
  13057. memset(path, 0, ARRAY_SIZE(path));
  13058. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13059. memset(host1, 0, ARRAY_SIZE(host1));
  13060. memset(path1, 0, ARRAY_SIZE(path1));
  13061. /*location: ftp://user:password@host:port/path*/
  13062. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13063. if((access(fnamePlusPath,F_OK))!=-1)
  13064. {
  13065. DEBUG_INFO("fnamePlusPath exist.\n");
  13066. }
  13067. else
  13068. {
  13069. DEBUG_INFO("fnamePlusPath not exist!\n");
  13070. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13071. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13072. goto end;
  13073. }
  13074. if(strchr(remoteLocation,'@')==NULL)
  13075. {
  13076. sscanf(remoteLocation,
  13077. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13078. protocol, host, &port, path);
  13079. strcpy(user,"anonymous");
  13080. strcpy(password,"");
  13081. }
  13082. else
  13083. {
  13084. //DEBUG_INFO("pch=%s\n", pch);
  13085. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13086. protocol, user, password, host, &port, path);
  13087. }
  13088. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13089. {
  13090. DEBUG_INFO("protocol is not ftp/http ! \n");
  13091. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13092. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13093. goto end;
  13094. }
  13095. if(strncmp(remoteLocation,"http", 4) == 0)
  13096. {
  13097. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13098. sprintf(ftppath,"/%s", path);
  13099. do
  13100. {
  13101. if(isCancelUploadLog)
  13102. {
  13103. isCancelUploadLog = FALSE;
  13104. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  13105. pthread_exit(NULL);
  13106. }
  13107. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13108. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13109. sleep(3);
  13110. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13111. if(!isSuccess)
  13112. {
  13113. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13114. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13115. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13116. sleep(retryIntervalInt);
  13117. }
  13118. else
  13119. {
  13120. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13121. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13122. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13123. }
  13124. retriesInt--;
  13125. }while((isSuccess == 0)&&(retriesInt >= 0));
  13126. }
  13127. else
  13128. {
  13129. sscanf(host,"%[^/]%s",host1, path1);
  13130. if(strlen(path) > 0)
  13131. sprintf(ftppath,"/%s", path);
  13132. else
  13133. sprintf(ftppath,"/%s", path1);
  13134. int ftppathlen=strlen(ftppath);
  13135. int i=1;
  13136. char filenametemp[50];
  13137. while(i < ftppathlen)
  13138. {
  13139. int len=ftppathlen-i;
  13140. if(ftppath[len]== 47) // '/' ascll code: 47
  13141. {
  13142. DEBUG_INFO("find '/' all right\n");
  13143. break;
  13144. }
  13145. i=i+1;
  13146. }
  13147. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13148. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13149. filenametemp[i+1] = 0;
  13150. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13151. if(port == 0)
  13152. port = 21;
  13153. do
  13154. {
  13155. if(isCancelUploadLog)
  13156. {
  13157. isCancelUploadLog = FALSE;
  13158. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  13159. pthread_exit(NULL);
  13160. }
  13161. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13162. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13163. sleep(3);
  13164. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13165. if(!isSuccess)
  13166. {
  13167. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13168. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13169. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13170. sleep(retryIntervalInt);
  13171. }
  13172. else
  13173. {
  13174. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13175. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13176. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13177. }
  13178. retriesInt--;
  13179. }while((!isSuccess)&&(retriesInt >= 0));
  13180. }
  13181. end:
  13182. system("rm -f /mnt/*");
  13183. sleep(5);
  13184. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13185. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13186. interLock.isGetLogGoing = OFF;
  13187. pthread_exit(NULL);
  13188. }
  13189. int handleGetLogRequest(char *uuid, char *payload)
  13190. {
  13191. mtrace();
  13192. int result = FAIL;
  13193. char fName[258];
  13194. time_t CurrentTime;
  13195. struct tm *tm;
  13196. pthread_t th_Status;
  13197. CurrentTime = time(NULL);
  13198. tm = localtime(&CurrentTime);
  13199. 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);
  13200. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  13201. if(interLock.isGetLogGoing)
  13202. {
  13203. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  13204. isCancelUploadLog = TRUE;
  13205. interLock.isGetLogGoing = OFF;
  13206. sleep(1);
  13207. }
  13208. else
  13209. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  13210. sendGetLogConfirmation(uuid);
  13211. if(!interLock.isGetLogGoing)
  13212. {
  13213. interLock.isGetLogGoing = ON;
  13214. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  13215. sleep(1);
  13216. }
  13217. else
  13218. {
  13219. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  13220. }
  13221. return result;
  13222. }
  13223. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  13224. {
  13225. mtrace();
  13226. int result = FAIL;
  13227. json_object *GetMonitoringReport;
  13228. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  13229. GetMonitoringReport = json_tokener_parse(payload);
  13230. if(!is_error(GetMonitoringReport))
  13231. {
  13232. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  13233. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  13234. // Required data
  13235. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  13236. {
  13237. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  13238. }
  13239. // Optional data
  13240. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  13241. {
  13242. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  13243. }
  13244. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  13245. {
  13246. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  13247. {
  13248. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  13249. {
  13250. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  13251. {
  13252. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  13253. {
  13254. 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")));
  13255. }
  13256. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13257. {
  13258. 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")));
  13259. }
  13260. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13261. {
  13262. 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)
  13263. {
  13264. 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"));
  13265. }
  13266. 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)
  13267. {
  13268. 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"));
  13269. }
  13270. }
  13271. }
  13272. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  13273. {
  13274. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13275. {
  13276. 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")));
  13277. }
  13278. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13279. {
  13280. 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")));
  13281. }
  13282. }
  13283. }
  13284. }
  13285. }
  13286. }
  13287. json_object_put(GetMonitoringReport);
  13288. /*
  13289. * TODO:
  13290. * 1. Response result
  13291. */
  13292. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13293. sendGetMonitoringReportConfirmation(uuid);
  13294. return result;
  13295. }
  13296. int handleGetReportRequest(char *uuid, char *payload)
  13297. {
  13298. mtrace();
  13299. int result = FAIL;
  13300. json_object *GetReport;
  13301. DEBUG_INFO("handleGetReportRequest...\n");
  13302. GetReport = json_tokener_parse(payload);
  13303. if(!is_error(GetReport))
  13304. {
  13305. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  13306. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  13307. // Required data
  13308. if(json_object_object_get(GetReport, "requestId") != NULL)
  13309. {
  13310. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  13311. }
  13312. // Optional data
  13313. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  13314. {
  13315. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  13316. }
  13317. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  13318. {
  13319. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  13320. {
  13321. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  13322. {
  13323. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  13324. {
  13325. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  13326. {
  13327. 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")));
  13328. }
  13329. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13330. {
  13331. 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")));
  13332. }
  13333. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13334. {
  13335. 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)
  13336. {
  13337. 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"));
  13338. }
  13339. 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)
  13340. {
  13341. 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"));
  13342. }
  13343. }
  13344. }
  13345. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  13346. {
  13347. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13348. {
  13349. 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")));
  13350. }
  13351. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13352. {
  13353. 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")));
  13354. }
  13355. }
  13356. }
  13357. }
  13358. }
  13359. }
  13360. json_object_put(GetReport);
  13361. /*
  13362. * TODO:
  13363. * 1. Response result
  13364. */
  13365. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13366. sendGetReportConfirmation(uuid);
  13367. return result;
  13368. }
  13369. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  13370. {
  13371. mtrace();
  13372. int result = FAIL;
  13373. int8_t gun_index = -1;
  13374. json_object *GetTransactionStatus;
  13375. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  13376. GetTransactionStatus = json_tokener_parse(payload);
  13377. if(!is_error(GetTransactionStatus))
  13378. {
  13379. /*
  13380. * TODO:
  13381. * 1. Check transaction locate which connector
  13382. */
  13383. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  13384. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  13385. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  13386. {
  13387. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  13388. }
  13389. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  13390. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  13391. }
  13392. json_object_put(GetTransactionStatus);
  13393. sendGetTransactionStatusConfirmation(uuid, gun_index);
  13394. return result;
  13395. }
  13396. int handleGetVariablesRequest(char *uuid, char *payload)
  13397. {
  13398. mtrace();
  13399. int result = FAIL;
  13400. int isUnknownComponent = TRUE;
  13401. json_object *GetVariables;
  13402. DEBUG_INFO("handleGetVariablesRequest...\n");
  13403. GetVariables = json_tokener_parse(payload);
  13404. if(!is_error(GetVariables))
  13405. {
  13406. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  13407. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  13408. // Required data
  13409. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  13410. {
  13411. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  13412. {
  13413. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  13414. {
  13415. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  13416. {
  13417. 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")));
  13418. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  13419. }
  13420. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  13421. {
  13422. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  13423. }*/
  13424. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  13425. {
  13426. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  13427. {
  13428. 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")));
  13429. }
  13430. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  13431. {
  13432. 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")));
  13433. }
  13434. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  13435. {
  13436. 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)
  13437. {
  13438. 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"));
  13439. }
  13440. 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)
  13441. {
  13442. 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"));
  13443. }
  13444. }
  13445. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  13446. }
  13447. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  13448. {
  13449. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  13450. {
  13451. 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")));
  13452. }
  13453. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  13454. {
  13455. 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")));
  13456. }
  13457. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  13458. }
  13459. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13460. {
  13461. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  13462. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  13463. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  13464. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  13465. {
  13466. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  13467. isUnknownComponent = FALSE;
  13468. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  13469. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  13470. {
  13471. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  13472. break;
  13473. }
  13474. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13475. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  13476. {
  13477. struct sysinfo s_info;
  13478. int error = sysinfo(&s_info);
  13479. if(error != 0)
  13480. {
  13481. DEBUG_WARN("System uptime get error: %d\n", error);
  13482. }
  13483. else
  13484. {
  13485. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  13486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  13487. }
  13488. }
  13489. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13490. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  13491. {
  13492. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  13493. }
  13494. else
  13495. {
  13496. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  13497. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  13498. }
  13499. break;
  13500. }
  13501. else
  13502. {
  13503. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  13504. {
  13505. isUnknownComponent = FALSE;
  13506. }
  13507. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  13508. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  13509. }
  13510. }
  13511. if(isUnknownComponent == TRUE)
  13512. {
  13513. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  13514. }
  13515. }
  13516. }
  13517. }
  13518. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  13519. }
  13520. json_object_put(GetVariables);
  13521. return result;
  13522. }
  13523. int handleInstallCertificateRequest(char *uuid, char *payload)
  13524. {
  13525. mtrace();
  13526. int result = FAIL;
  13527. json_object *InstallCertificate;
  13528. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13529. InstallCertificate = json_tokener_parse(payload);
  13530. if(!is_error(InstallCertificate))
  13531. {
  13532. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  13533. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  13534. // Required data
  13535. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  13536. {
  13537. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13538. }
  13539. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  13540. {
  13541. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13542. }
  13543. }
  13544. json_object_put(InstallCertificate);
  13545. /*
  13546. * TODO:
  13547. * 1. Install certification preocess and response
  13548. */
  13549. if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]))
  13550. {
  13551. }
  13552. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]))
  13553. {
  13554. }
  13555. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]))
  13556. {
  13557. }
  13558. else
  13559. {
  13560. }
  13561. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13562. sendInstallCertificateConfirmation(uuid);
  13563. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13564. return result;
  13565. }
  13566. int handlePublishFirmwareRequest(char *uuid, char *payload)
  13567. {
  13568. mtrace();
  13569. int result = FAIL;
  13570. json_object *PublishFirmware;
  13571. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  13572. PublishFirmware = json_tokener_parse(payload);
  13573. if(!is_error(PublishFirmware))
  13574. {
  13575. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  13576. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  13577. // Required data
  13578. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  13579. {
  13580. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  13581. }
  13582. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  13583. {
  13584. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  13585. }
  13586. // Optional data
  13587. if(json_object_object_get(PublishFirmware, "location") != NULL)
  13588. {
  13589. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  13590. }
  13591. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  13592. {
  13593. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  13594. }
  13595. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  13596. {
  13597. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  13598. }
  13599. }
  13600. json_object_put(PublishFirmware);
  13601. /*
  13602. * TODO:
  13603. * 1. Publish firmware preocess and response
  13604. */
  13605. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13606. sendPublishFirmwareConfirmation(uuid);
  13607. return result;
  13608. }
  13609. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  13610. {
  13611. mtrace();
  13612. int result = FAIL;
  13613. int8_t connectorIdx = -1;
  13614. uint8_t tempIndex;
  13615. uint8_t isOverConnectorMax = FALSE;
  13616. uint8_t isPeriodOverMax = FALSE;
  13617. uint8_t isTxProfile = TRUE;
  13618. uint8_t isAllowStart = TRUE;
  13619. uint8_t filename[128]={0};
  13620. char cmdBuf[128];
  13621. FILE *filePtr;
  13622. json_object *RemoteStartTransaction;
  13623. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  13624. RemoteStartTransaction = json_tokener_parse(payload);
  13625. if(!is_error(RemoteStartTransaction))
  13626. {
  13627. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  13628. {
  13629. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  13630. {
  13631. connectorIdx = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  13632. }
  13633. else
  13634. {
  13635. isOverConnectorMax = TRUE;
  13636. DEBUG_WARN("Connector id shall not equal 0 and less than max connector id.\n");
  13637. }
  13638. }
  13639. else
  13640. {
  13641. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13642. {
  13643. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  13644. {
  13645. connectorIdx = (idx+1);
  13646. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdx);
  13647. break;
  13648. }
  13649. }
  13650. }
  13651. if(isOverConnectorMax == FALSE)
  13652. {
  13653. if(connectorIdx > 0)
  13654. {
  13655. DEBUG_INFO("Connector id: %d\n", connectorIdx);
  13656. memset(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1], 0, sizeof(struct RequestStartTransaction_20));
  13657. memcpy(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid));
  13658. // Required data
  13659. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13660. {
  13661. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13662. }
  13663. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13664. {
  13665. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13666. {
  13667. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13668. }
  13669. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13670. {
  13671. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13672. }
  13673. }
  13674. // Optional data
  13675. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13676. {
  13677. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13678. {
  13679. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13680. }
  13681. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13682. {
  13683. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13684. }
  13685. }
  13686. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13687. {
  13688. // Check periods is over max configuration
  13689. 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))
  13690. {
  13691. isPeriodOverMax = TRUE;
  13692. }
  13693. // Check profile purpose is TxProfile
  13694. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13695. {
  13696. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13697. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13698. }
  13699. else
  13700. {
  13701. isTxProfile = FALSE;
  13702. }
  13703. }
  13704. //check Transaction active
  13705. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  13706. {
  13707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13708. {
  13709. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13710. }
  13711. else
  13712. {
  13713. tempIndex = (connectorIdx-1);
  13714. }
  13715. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13716. {
  13717. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  13718. {
  13719. 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))
  13720. {
  13721. //Reserved
  13722. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  13723. }
  13724. 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))
  13725. {
  13726. //Reserved
  13727. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  13728. isAllowStart = FALSE;
  13729. }
  13730. else
  13731. {
  13732. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13733. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  13734. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  13735. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  13736. {
  13737. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  13738. isAllowStart = FALSE;
  13739. }
  13740. }//END FOR ELSE
  13741. }
  13742. }// END FOR CHAdeMO_QUANTITY
  13743. }
  13744. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  13745. {
  13746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13747. {
  13748. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13749. }
  13750. else
  13751. {
  13752. tempIndex = (connectorIdx-1);
  13753. }
  13754. for (int index = 0; index < CCS_QUANTITY; index++)
  13755. {
  13756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13757. {
  13758. 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))
  13759. {
  13760. //Reserved
  13761. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  13762. }
  13763. 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))
  13764. {
  13765. //Reserved
  13766. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  13767. isAllowStart = FALSE;
  13768. }
  13769. else
  13770. {
  13771. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13772. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13773. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13774. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13775. {
  13776. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  13777. isAllowStart = FALSE;
  13778. }
  13779. }// END FOR ELSE
  13780. }
  13781. }// END FOR CCS_QUANTITY
  13782. }
  13783. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  13784. {
  13785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13786. {
  13787. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13788. }
  13789. else
  13790. {
  13791. tempIndex = (connectorIdx-1);
  13792. }
  13793. for (int index = 0; index < GB_QUANTITY; index++)
  13794. {
  13795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  13796. {
  13797. 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))
  13798. {
  13799. //Reserved
  13800. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  13801. }
  13802. 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))
  13803. {
  13804. //Reserved
  13805. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  13806. isAllowStart = FALSE;
  13807. }
  13808. else
  13809. {
  13810. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13811. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13812. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13813. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13814. {
  13815. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  13816. isAllowStart = FALSE;
  13817. }
  13818. }// END FOR ELSE
  13819. }
  13820. } // END FOR GB_QUANTITY
  13821. }
  13822. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  13823. {
  13824. tempIndex = (connectorIdx-1);
  13825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13826. {
  13827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  13828. {
  13829. 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))
  13830. {
  13831. //Reserved
  13832. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  13833. }
  13834. 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))
  13835. {
  13836. //Reserved
  13837. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  13838. isAllowStart = FALSE;
  13839. }
  13840. else
  13841. {
  13842. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13843. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13844. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13845. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13846. {
  13847. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  13848. isAllowStart = FALSE;
  13849. }
  13850. }// END FOR ELSE
  13851. }
  13852. } // END FOR GB_QUANTITY
  13853. }
  13854. else
  13855. {
  13856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13857. {
  13858. tempIndex = 2;
  13859. }
  13860. else
  13861. {
  13862. tempIndex = (connectorIdx-1);
  13863. }
  13864. for (int index = 0; index < AC_QUANTITY; index++)
  13865. {
  13866. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  13867. {
  13868. 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))
  13869. {
  13870. //Reserved
  13871. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  13872. }
  13873. 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))
  13874. {
  13875. //Reserved
  13876. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  13877. isAllowStart = FALSE;
  13878. }
  13879. else
  13880. {
  13881. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13882. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13883. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13884. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13885. {
  13886. DEBUG_WARN("AC connector not allow start cause busy.\n");
  13887. isAllowStart = FALSE;
  13888. }
  13889. }//END FOR ELSE
  13890. }
  13891. }// END FOR AC_QUANTITY
  13892. }
  13893. }
  13894. else
  13895. {
  13896. DEBUG_INFO("Connector id does not specific.\n");
  13897. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13898. {
  13899. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  13900. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  13901. // Required data
  13902. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13903. {
  13904. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13905. }
  13906. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13907. {
  13908. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13909. {
  13910. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13911. }
  13912. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13913. {
  13914. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13915. }
  13916. }
  13917. // Optional data
  13918. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13919. {
  13920. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13921. {
  13922. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13923. }
  13924. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13925. {
  13926. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13927. }
  13928. }
  13929. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13930. {
  13931. // Check periods is over max configuration
  13932. 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))
  13933. {
  13934. isPeriodOverMax = TRUE;
  13935. }
  13936. // Check profile purpose is TxProfile
  13937. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13938. {
  13939. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13940. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  13941. }
  13942. else
  13943. {
  13944. isTxProfile = FALSE;
  13945. }
  13946. }
  13947. }
  13948. }
  13949. }
  13950. // Profile replace or add info
  13951. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  13952. {
  13953. if(connectorIdx != -1)
  13954. {
  13955. if(strlen((char*)filename) > 0)
  13956. {
  13957. // Save profile to file
  13958. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13959. system(cmdBuf);
  13960. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", connectorIdx);
  13961. filePtr = fopen((char*)filename, "w");
  13962. 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));
  13963. fclose(filePtr);
  13964. }
  13965. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  13966. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  13967. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
  13968. result = PASS;
  13969. }
  13970. else
  13971. {
  13972. uint8_t isHasIdleConnector = FALSE;
  13973. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13974. {
  13975. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  13976. {
  13977. isHasIdleConnector = TRUE;
  13978. break;
  13979. }
  13980. }
  13981. if(isHasIdleConnector == TRUE)
  13982. {
  13983. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  13984. if(strlen((char*)filename) > 0)
  13985. {
  13986. // Save profile to file
  13987. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  13988. system(cmdBuf);
  13989. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  13990. filePtr = fopen((char*)filename, "w");
  13991. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  13992. fclose(filePtr);
  13993. }
  13994. refreshStartTimer(&clientTime.RemoteStartWait);
  13995. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  13996. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13997. {
  13998. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  13999. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  14000. }
  14001. result = PASS;
  14002. }
  14003. else
  14004. {
  14005. DEBUG_INFO("There is not any connector is idle.\n");
  14006. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14007. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14008. }
  14009. }
  14010. }
  14011. else
  14012. {
  14013. if(isOverConnectorMax != FALSE)
  14014. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  14015. if(isPeriodOverMax)
  14016. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14017. if(!isTxProfile)
  14018. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  14019. if(!isAllowStart)
  14020. DEBUG_WARN("Target connector does not allow start.\n");
  14021. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((connectorIdx-1)<0?0:(connectorIdx-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  14022. }
  14023. }
  14024. json_object_put(RemoteStartTransaction);
  14025. sendRemoteStartTransactionConfirmation(uuid, ((connectorIdx-1)<0?0:(connectorIdx-1)));
  14026. return result;
  14027. }
  14028. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  14029. {
  14030. mtrace();
  14031. int result = FAIL;
  14032. int match = FALSE;
  14033. int GunNO = 0;
  14034. int tempIndex = 0;
  14035. char transactionIdStr[37];
  14036. int transactionIdIsNULL= TRUE;
  14037. json_object *RemoteStopTransaction;
  14038. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  14039. if(server_pending == TRUE)
  14040. {
  14041. return 0;
  14042. }
  14043. RemoteStopTransaction = json_tokener_parse(payload);
  14044. if(!is_error(RemoteStopTransaction))
  14045. {
  14046. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  14047. {
  14048. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  14049. transactionIdIsNULL = FALSE;
  14050. }
  14051. }
  14052. json_object_put(RemoteStopTransaction);
  14053. if(transactionIdIsNULL == FALSE)
  14054. {
  14055. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14056. {
  14057. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  14058. {
  14059. //check Transaction active
  14060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14061. {
  14062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14063. {
  14064. tempIndex = ((gun_index==2) ? 1: 0);
  14065. }
  14066. else
  14067. {
  14068. tempIndex = gun_index;
  14069. }
  14070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14071. {
  14072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14073. {
  14074. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14075. {
  14076. match = TRUE;
  14077. GunNO = gun_index;
  14078. }
  14079. }
  14080. }// END FOR CHAdeMO_QUANTITY
  14081. }
  14082. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14083. {
  14084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14085. {
  14086. tempIndex = ((gun_index==2) ? 1: 0);
  14087. }
  14088. else
  14089. {
  14090. tempIndex = gun_index;
  14091. }
  14092. for (int index = 0; index < CCS_QUANTITY; index++)
  14093. {
  14094. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14095. {
  14096. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14097. {
  14098. match = TRUE;
  14099. GunNO = gun_index;
  14100. }
  14101. }
  14102. }// END FOR CCS_QUANTITY
  14103. }
  14104. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14105. {
  14106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14107. {
  14108. tempIndex = ((gun_index==2) ? 1: 0);
  14109. }
  14110. else
  14111. {
  14112. tempIndex = gun_index;
  14113. }
  14114. for (int index = 0; index < GB_QUANTITY; index++)
  14115. {
  14116. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14117. {
  14118. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14119. {
  14120. match = TRUE;
  14121. GunNO = gun_index;
  14122. }
  14123. }
  14124. }// END FOR GB_QUANTITY
  14125. }
  14126. else if(gunType[gun_index] == GUN_TYPE_DO)
  14127. {
  14128. tempIndex = gun_index;
  14129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14130. {
  14131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14132. {
  14133. 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
  14134. {
  14135. match = TRUE;
  14136. GunNO = gun_index;
  14137. }
  14138. }
  14139. }// END FOR GB_QUANTITY
  14140. }
  14141. else
  14142. {
  14143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14144. {
  14145. tempIndex = 2;
  14146. }
  14147. else
  14148. {
  14149. tempIndex = gun_index;
  14150. }
  14151. for (int index = 0; index < AC_QUANTITY; index++)
  14152. {
  14153. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14154. {
  14155. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14156. {
  14157. match = TRUE;
  14158. GunNO = gun_index;
  14159. }
  14160. }
  14161. }// END FOR CHAdeMO_QUANTITY
  14162. } // END FOR AC ELSE
  14163. }// CHECK IF ResponseTransactionId == transactionIdInt
  14164. }//END FOR
  14165. if( match == TRUE)
  14166. {
  14167. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  14168. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14169. }
  14170. else
  14171. {
  14172. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14173. }
  14174. }
  14175. else
  14176. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14177. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  14178. return result;
  14179. }
  14180. int handleReserveNowRequest(char *uuid, char *payload)
  14181. {
  14182. mtrace();
  14183. int result = FAIL;
  14184. int connectorIdInt=0, reservationIdInt=0;
  14185. int tempIndex = 0;
  14186. json_object *ReserveNow;
  14187. DEBUG_INFO("handleReserveNowRequest ...\n");
  14188. ReserveNow = json_tokener_parse(payload);
  14189. if(!is_error(ReserveNow))
  14190. {
  14191. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  14192. {
  14193. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14194. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  14195. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  14196. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14197. }
  14198. // Required data
  14199. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  14200. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  14201. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  14202. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  14203. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  14204. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  14205. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  14206. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  14207. // Optional data
  14208. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  14209. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  14210. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  14211. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  14212. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  14213. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  14214. result = PASS;
  14215. }
  14216. json_object_put(ReserveNow);
  14217. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14218. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  14219. {
  14220. //check Transaction active
  14221. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  14222. {
  14223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14224. {
  14225. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14226. }
  14227. else
  14228. {
  14229. tempIndex = connectorIdInt -1;
  14230. }
  14231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14232. {
  14233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14234. {
  14235. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14236. {
  14237. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14238. {
  14239. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14240. {
  14241. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  14242. {
  14243. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14244. }
  14245. else
  14246. {
  14247. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14248. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14249. }
  14250. }
  14251. 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'))
  14252. {
  14253. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14254. }
  14255. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14256. {
  14257. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14258. }
  14259. else
  14260. {
  14261. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14262. }
  14263. }
  14264. 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
  14265. {
  14266. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14267. }
  14268. }
  14269. else
  14270. {
  14271. //replace reservation
  14272. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14273. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14274. }
  14275. }
  14276. } // END FOR CHAdeMO_QUANTITY
  14277. }
  14278. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  14279. {
  14280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14281. {
  14282. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14283. }
  14284. else
  14285. {
  14286. tempIndex = connectorIdInt -1;
  14287. }
  14288. for (int index = 0; index < CCS_QUANTITY; index++)
  14289. {
  14290. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14291. {
  14292. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14293. {
  14294. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14295. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14296. {
  14297. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14298. {
  14299. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  14300. {
  14301. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14302. }
  14303. else
  14304. {
  14305. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14306. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14307. }
  14308. }
  14309. 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'))
  14310. {
  14311. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14312. }
  14313. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  14314. {
  14315. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14316. }
  14317. else
  14318. {
  14319. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14320. }
  14321. }
  14322. 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
  14323. {
  14324. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14325. }
  14326. }
  14327. else
  14328. {
  14329. //replace reservation
  14330. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14331. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14332. }
  14333. }
  14334. } // END FOR CCS_QUANTITY
  14335. }
  14336. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  14337. {
  14338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14339. {
  14340. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14341. }
  14342. else
  14343. {
  14344. tempIndex = connectorIdInt -1;
  14345. }
  14346. for (int index = 0; index < GB_QUANTITY; index++)
  14347. {
  14348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14349. {
  14350. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14351. {
  14352. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14353. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14354. {
  14355. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14356. {
  14357. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  14358. {
  14359. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14360. }
  14361. else
  14362. {
  14363. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14364. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14365. }
  14366. }
  14367. 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'))
  14368. {
  14369. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14370. }
  14371. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14372. {
  14373. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14374. }
  14375. else
  14376. {
  14377. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14378. }
  14379. }
  14380. 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
  14381. {
  14382. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14383. }
  14384. }
  14385. else
  14386. {
  14387. //replace reservation
  14388. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14389. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14390. }
  14391. }
  14392. }// END FOR GB_QUANTITY
  14393. }
  14394. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  14395. {
  14396. tempIndex = connectorIdInt -1;
  14397. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14398. {
  14399. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14400. {
  14401. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  14402. {
  14403. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14404. 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
  14405. {
  14406. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14407. {
  14408. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  14409. {
  14410. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14411. }
  14412. else
  14413. {
  14414. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14415. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14416. }
  14417. }
  14418. 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'))
  14419. {
  14420. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14421. }
  14422. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14423. {
  14424. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14425. }
  14426. else
  14427. {
  14428. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14429. }
  14430. }
  14431. 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
  14432. {
  14433. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14434. }
  14435. }
  14436. else
  14437. {
  14438. //replace reservation
  14439. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14440. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14441. }
  14442. }
  14443. }// END FOR DO_QUANTITY
  14444. }
  14445. else
  14446. {
  14447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14448. {
  14449. tempIndex = 2;
  14450. }
  14451. else
  14452. {
  14453. tempIndex = (connectorIdInt -1);
  14454. }
  14455. for (int index = 0; index < AC_QUANTITY; index++)
  14456. {
  14457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14458. {
  14459. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14460. {
  14461. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14462. {
  14463. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14464. {
  14465. 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))
  14466. {
  14467. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14468. }
  14469. else
  14470. {
  14471. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14472. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14473. }
  14474. }
  14475. 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'))
  14476. {
  14477. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14478. }
  14479. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14480. {
  14481. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14482. }
  14483. else
  14484. {
  14485. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14486. }
  14487. }
  14488. 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
  14489. {
  14490. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14491. }
  14492. }
  14493. else
  14494. {
  14495. //replace reservation
  14496. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14497. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14498. }
  14499. }
  14500. } // END FOR AC_QUANTITY
  14501. }
  14502. }
  14503. else if(connectorIdInt == 0)
  14504. {
  14505. //check Transaction active
  14506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14507. {
  14508. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14509. {
  14510. 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'))
  14511. {
  14512. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14513. goto end;
  14514. }
  14515. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14516. {
  14517. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14518. goto end;
  14519. }
  14520. 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
  14521. {
  14522. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14523. goto end;
  14524. }
  14525. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14526. {
  14527. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14528. goto end;
  14529. }
  14530. }
  14531. }// END FOR CHAdeMO_QUANTITY
  14532. for (int index = 0; index < CCS_QUANTITY; index++)
  14533. {
  14534. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14535. {
  14536. 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'))
  14537. {
  14538. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14539. goto end;
  14540. }
  14541. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  14542. {
  14543. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14544. goto end;
  14545. }
  14546. 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
  14547. {
  14548. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14549. goto end;
  14550. }
  14551. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14552. {
  14553. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14554. goto end;
  14555. }
  14556. }
  14557. } // END FOR CCS_QUANTITY
  14558. for (int index = 0; index < GB_QUANTITY; index++)
  14559. {
  14560. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14561. {
  14562. 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'))
  14563. {
  14564. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14565. goto end;
  14566. }
  14567. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14568. {
  14569. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14570. goto end;
  14571. }
  14572. 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
  14573. {
  14574. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14575. goto end;
  14576. }
  14577. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14578. {
  14579. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14580. goto end;
  14581. }
  14582. }
  14583. } // END FOR GB_QUANTITY
  14584. for (int index = 0; index < AC_QUANTITY; index++)
  14585. {
  14586. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14587. {
  14588. 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'))
  14589. {
  14590. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14591. goto end;
  14592. }
  14593. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14594. {
  14595. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14596. goto end;
  14597. }
  14598. 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
  14599. {
  14600. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14601. goto end;
  14602. }
  14603. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14604. {
  14605. 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))
  14606. {
  14607. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14608. goto end;
  14609. }
  14610. }
  14611. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14612. {
  14613. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14614. goto end;
  14615. }
  14616. }
  14617. }// END FOR AC_QUANTITY
  14618. //The connectorId is 0
  14619. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  14620. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14621. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  14622. result = TRUE;
  14623. return result;
  14624. }
  14625. else
  14626. {
  14627. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14628. }
  14629. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  14630. {
  14631. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  14632. result = TRUE;
  14633. return result;
  14634. }
  14635. end:
  14636. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  14637. return result;
  14638. }
  14639. int handleResetRequest(char *uuid, char *payload)
  14640. {
  14641. mtrace();
  14642. int result = FAIL;
  14643. json_object *Reset = json_object_new_object();
  14644. DEBUG_INFO("handleResetRequest...\n");
  14645. Reset = json_tokener_parse(payload);
  14646. if(!is_error(Reset))
  14647. {
  14648. // Required data
  14649. if(json_object_object_get(Reset, "type") != NULL)
  14650. {
  14651. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  14652. }
  14653. if(json_object_object_get(Reset, "evseId") != NULL)
  14654. {
  14655. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  14656. }
  14657. }
  14658. json_object_put(Reset);
  14659. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  14660. {
  14661. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  14662. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  14663. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  14664. result = PASS;
  14665. }
  14666. else
  14667. {
  14668. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  14669. }
  14670. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  14671. sendResetConfirmation(uuid);
  14672. return result;
  14673. }
  14674. int handleSendLocalListRequest(char *uuid, char *payload)
  14675. {
  14676. mtrace();
  14677. int result = FAIL;
  14678. int checkState_Faulted = FALSE;
  14679. json_object *SendLocalList;
  14680. DEBUG_INFO("handleSendLocalListRequest...\n");
  14681. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  14682. {
  14683. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14684. goto end;
  14685. }
  14686. SendLocalList = json_tokener_parse(payload);
  14687. if(!is_error(SendLocalList))
  14688. {
  14689. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  14690. // Required data
  14691. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  14692. {
  14693. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  14694. }
  14695. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  14696. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  14697. // Optional data
  14698. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  14699. {
  14700. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  14701. {
  14702. // Required data
  14703. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  14704. {
  14705. 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")));
  14706. 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")));
  14707. }
  14708. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  14709. {
  14710. 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")));
  14711. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  14712. 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")));
  14713. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  14714. 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"));
  14715. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  14716. {
  14717. 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")));
  14718. 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")));
  14719. }
  14720. }
  14721. }
  14722. }
  14723. }
  14724. json_object_put(SendLocalList);
  14725. //check Charge Point state
  14726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14727. {
  14728. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14729. {
  14730. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14731. }
  14732. }
  14733. for (int index = 0; index < CCS_QUANTITY; index++)
  14734. {
  14735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14736. {
  14737. checkState_Faulted = TRUE; //OCPP Status
  14738. }
  14739. }
  14740. for (int index = 0; index < GB_QUANTITY; index++)
  14741. {
  14742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14743. {
  14744. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14745. }
  14746. }
  14747. for (int index = 0; index < AC_QUANTITY; index++)
  14748. {
  14749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14750. {
  14751. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14752. }
  14753. }
  14754. if(checkState_Faulted == TRUE)
  14755. {
  14756. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14757. goto end;
  14758. }
  14759. // Check update type
  14760. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  14761. {
  14762. //Local list full update
  14763. DEBUG_INFO("Local list full update.\n");
  14764. DB_getListVerion();
  14765. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14766. {
  14767. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14768. goto end;
  14769. }*/
  14770. DB_cleanLocalList();
  14771. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14772. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14773. }
  14774. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  14775. {
  14776. //Local list different update
  14777. DEBUG_INFO("Local list different 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_VersionMismatch]);
  14782. goto end;
  14783. }
  14784. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14785. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14786. }
  14787. else
  14788. {
  14789. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14790. goto end;
  14791. }
  14792. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  14793. end:
  14794. sendSendLocalListConfirmation(uuid);
  14795. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14796. return result;
  14797. }
  14798. int handleSetChargingProfileRequest(char *uuid, char *payload)
  14799. {
  14800. mtrace();
  14801. int result = FAIL;
  14802. struct SetChargingProfile_20 SetProfileReq = {0};
  14803. uint8_t isLostConnectorId = FALSE;
  14804. uint8_t isPeriodOverMax = FALSE;
  14805. uint8_t isStackOverMax = FALSE;
  14806. uint8_t isProfileOverMax = FALSE;
  14807. uint8_t isConnectorMismatch = FALSE;
  14808. uint8_t isTransactiodIdMismatch = FALSE;
  14809. uint8_t isInvalidLimit = FALSE;
  14810. uint8_t isWrongFormat = FALSE;
  14811. uint8_t replaceableProfileCnt = 0;
  14812. uint8_t existProfileQuantity = 0;
  14813. uint8_t filename[128]={0};
  14814. uint8_t dataLine[4096]={0};
  14815. FILE *filePtr;
  14816. json_object *SetChargingProfile;
  14817. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  14818. SetChargingProfile = json_tokener_parse(payload);
  14819. if(!is_error(SetChargingProfile))
  14820. {
  14821. // Required data
  14822. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  14823. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  14824. else
  14825. isLostConnectorId = TRUE;
  14826. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  14827. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  14828. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  14829. {
  14830. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  14831. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  14832. {
  14833. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  14834. }
  14835. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  14836. {
  14837. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  14838. }
  14839. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  14840. {
  14841. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  14842. }
  14843. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  14844. {
  14845. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  14846. }
  14847. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  14848. {
  14849. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  14850. }
  14851. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  14852. {
  14853. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  14854. }
  14855. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  14856. {
  14857. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  14858. }
  14859. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  14860. {
  14861. int chargingScheduleCount = 0;
  14862. int chargingSchedulePeriodCount = 0;
  14863. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  14864. {
  14865. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  14866. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  14867. {
  14868. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  14869. {
  14870. 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")));
  14871. }
  14872. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  14873. {
  14874. 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"));
  14875. }
  14876. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  14877. {
  14878. 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"));
  14879. }
  14880. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  14881. {
  14882. 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")));
  14883. }
  14884. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  14885. {
  14886. 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"));
  14887. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  14888. {
  14889. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  14890. {
  14891. 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)
  14892. {
  14893. 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"));
  14894. }
  14895. 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)
  14896. {
  14897. 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"));
  14898. }
  14899. 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)
  14900. {
  14901. 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"));
  14902. }
  14903. 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)
  14904. {
  14905. 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"));
  14906. }
  14907. // Check invalid limit
  14908. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  14909. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  14910. {
  14911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  14912. {
  14913. 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)))) ||
  14914. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  14915. {
  14916. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  14917. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  14918. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  14919. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  14920. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  14921. isInvalidLimit = TRUE;
  14922. }
  14923. }
  14924. else
  14925. {
  14926. 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) ||
  14927. (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)))
  14928. {
  14929. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  14930. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  14931. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  14932. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  14933. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  14934. isInvalidLimit = TRUE;
  14935. }
  14936. }
  14937. }
  14938. }
  14939. }
  14940. else
  14941. {
  14942. isPeriodOverMax = TRUE;
  14943. }
  14944. }
  14945. }
  14946. }
  14947. else
  14948. {
  14949. isWrongFormat = TRUE;
  14950. }
  14951. }
  14952. // Check periods is over max configuration
  14953. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  14954. {
  14955. if(SetProfileReq.evseId == 0)
  14956. {
  14957. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  14958. filePtr = fopen((char*)filename, "r");
  14959. if (!filePtr)
  14960. {
  14961. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  14962. filePtr = fopen((char*)filename, "w+");
  14963. }
  14964. else
  14965. {
  14966. //Check Charging Profile Count
  14967. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  14968. char *line = NULL;
  14969. size_t len = 0;
  14970. while(getline(&line, &len, filePtr) != -1)
  14971. {
  14972. json_object *obj = NULL;
  14973. obj = json_tokener_parse(line);
  14974. if(is_error(obj))
  14975. {
  14976. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  14977. }
  14978. else
  14979. {
  14980. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  14981. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  14982. {
  14983. existProfileQuantity += 1;
  14984. }
  14985. else
  14986. replaceableProfileCnt += 1;
  14987. }
  14988. //DEBUG_INFO("word=%s\n",word);
  14989. /*if(strstr((char*)dataLine, "id")!= NULL)
  14990. {
  14991. existProfileQuantity += 1;
  14992. }*/
  14993. }
  14994. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  14995. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  14996. {
  14997. isStackOverMax = TRUE;
  14998. }
  14999. }
  15000. fclose(filePtr);
  15001. }
  15002. else
  15003. isConnectorMismatch = TRUE;
  15004. }
  15005. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  15006. {
  15007. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  15008. isConnectorMismatch = TRUE;
  15009. if(!isConnectorMismatch)
  15010. {
  15011. if(SetProfileReq.evseId == 0)
  15012. {
  15013. int tmpExistProfileQuantity;
  15014. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  15015. {
  15016. tmpExistProfileQuantity = 0;
  15017. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15018. filePtr = fopen((char*)filename, "r");
  15019. if (!filePtr)
  15020. {
  15021. DEBUG_INFO("%s not exist, create it.\n", filename);
  15022. filePtr = fopen((char*)filename, "w+");
  15023. }
  15024. else
  15025. {
  15026. //Check Charging Profile Count
  15027. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15028. char *line = NULL;
  15029. size_t len = 0;
  15030. while(getline(&line, &len, filePtr) != -1)
  15031. {
  15032. json_object *obj = NULL;
  15033. obj = json_tokener_parse(line);
  15034. if(is_error(obj))
  15035. {
  15036. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15037. }
  15038. else
  15039. {
  15040. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15041. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15042. {
  15043. tmpExistProfileQuantity += 1;
  15044. }
  15045. else
  15046. replaceableProfileCnt += 1;
  15047. }
  15048. //DEBUG_INFO("word=%s\n",word);
  15049. /*if(strstr((char*)dataLine, "id")!= NULL)
  15050. {
  15051. tmpExistProfileQuantity += 1;
  15052. }*/
  15053. }
  15054. }
  15055. fclose(filePtr);
  15056. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15057. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15058. {
  15059. isStackOverMax = TRUE;
  15060. }
  15061. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  15062. }
  15063. }
  15064. else
  15065. {
  15066. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15067. filePtr = fopen((char*)filename, "r");
  15068. if (!filePtr)
  15069. {
  15070. DEBUG_INFO("%s not exist, create it.\n", filename);
  15071. filePtr = fopen((char*)filename, "w+");
  15072. }
  15073. else
  15074. {
  15075. //Check Charging Profile Count
  15076. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15077. char *line = NULL;
  15078. size_t len = 0;
  15079. while(getline(&line, &len, filePtr) != -1)
  15080. {
  15081. json_object *obj = NULL;
  15082. obj = json_tokener_parse(line);
  15083. if(is_error(obj))
  15084. {
  15085. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  15086. }
  15087. else
  15088. {
  15089. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15090. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15091. {
  15092. existProfileQuantity += 1;
  15093. }
  15094. else
  15095. replaceableProfileCnt += 1;
  15096. }
  15097. //DEBUG_INFO("word=%s\n",word);
  15098. /*if(strstr((char*)dataLine, "id")!= NULL)
  15099. {
  15100. existProfileQuantity += 1;
  15101. }*/
  15102. }
  15103. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15104. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15105. {
  15106. isStackOverMax = TRUE;
  15107. }
  15108. }
  15109. fclose(filePtr);
  15110. }
  15111. }
  15112. }
  15113. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15114. {
  15115. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  15116. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15117. else
  15118. isConnectorMismatch = TRUE;
  15119. if(!isConnectorMismatch)
  15120. {
  15121. filePtr = fopen((char*)filename, "r");
  15122. if (!filePtr)
  15123. {
  15124. DEBUG_INFO("%s not exist, create it.\n", filename);
  15125. filePtr = fopen((char*)filename, "w+");
  15126. }
  15127. else
  15128. {
  15129. //Check Charging Profile Count
  15130. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15131. char *line = NULL;
  15132. size_t len = 0;
  15133. while(getline(&line, &len, filePtr) != -1)
  15134. {
  15135. json_object *obj = NULL;
  15136. obj = json_tokener_parse(line);
  15137. if(is_error(obj))
  15138. {
  15139. DEBUG_ERROR("Parse TxProfile from file error.\n");
  15140. }
  15141. else
  15142. {
  15143. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15144. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15145. {
  15146. existProfileQuantity += 1;
  15147. }
  15148. else
  15149. replaceableProfileCnt += 1;
  15150. }
  15151. //DEBUG_INFO("word=%s\n",word);
  15152. /*if(strstr((char*)dataLine, "id")!= NULL)
  15153. {
  15154. existProfileQuantity += 1;
  15155. }*/
  15156. }
  15157. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15158. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15159. {
  15160. isStackOverMax = TRUE;
  15161. }
  15162. }
  15163. fclose(filePtr);
  15164. if(SetProfileReq.chargingProfile.transactionId != ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId)
  15165. isTransactiodIdMismatch = TRUE;
  15166. }
  15167. }
  15168. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  15169. {
  15170. /*
  15171. * TODO:
  15172. *
  15173. */
  15174. }
  15175. else
  15176. {}
  15177. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  15178. {
  15179. FILE *fp;
  15180. char dataLine[4096]={0};
  15181. char fnametemp[128]={0};
  15182. int tmpProfileQuantity;
  15183. //Check ChargePointMaxProfile.json exit
  15184. existProfileQuantity = 0;
  15185. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  15186. {
  15187. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  15188. //Check Charging Profile Count
  15189. tmpProfileQuantity = 0;
  15190. while(fscanf(fp, "%s", dataLine) != EOF)
  15191. {
  15192. if(strstr(dataLine, "id")!= NULL)
  15193. {
  15194. existProfileQuantity += 1;
  15195. tmpProfileQuantity += 1;
  15196. }
  15197. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15198. }
  15199. fclose(fp);
  15200. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  15201. }
  15202. //Check TxDefaultProfile_%d.json
  15203. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15204. {
  15205. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15206. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15207. if((access(fnametemp,F_OK))!=-1)
  15208. {
  15209. fp = fopen(fnametemp, "r");
  15210. //Check Charging Profile Count
  15211. tmpProfileQuantity = 0;
  15212. while(fscanf(fp, "%s", dataLine) != EOF)
  15213. {
  15214. //DEBUG_INFO("word=%s\n",word);
  15215. if(strstr(dataLine, "id")!= NULL)
  15216. {
  15217. existProfileQuantity += 1;
  15218. tmpProfileQuantity += 1;
  15219. }
  15220. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15221. }
  15222. fclose(fp);
  15223. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15224. }
  15225. }
  15226. //Check TxProfile_%d.json
  15227. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15228. {
  15229. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15230. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  15231. if((access(fnametemp,F_OK))!=-1)
  15232. {
  15233. fp = fopen(fnametemp, "r");
  15234. //Check Charging Profile Count
  15235. tmpProfileQuantity = 0;
  15236. while(fscanf(fp, "%s", dataLine) != EOF)
  15237. {
  15238. if(strstr(dataLine, "id")!= NULL)
  15239. {
  15240. existProfileQuantity += 1;
  15241. tmpProfileQuantity += 1;
  15242. }
  15243. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15244. }
  15245. fclose(fp);
  15246. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15247. }
  15248. }
  15249. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  15250. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  15251. // To check total Profile quantity
  15252. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  15253. {
  15254. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15255. isProfileOverMax = TRUE;
  15256. }
  15257. else
  15258. {
  15259. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15260. isProfileOverMax = TRUE;
  15261. }
  15262. }
  15263. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  15264. }
  15265. // Profile replace or add info
  15266. if(!isLostConnectorId && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  15267. {
  15268. FILE *infile;
  15269. FILE *outfile;
  15270. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  15271. char rmFileCmd[128];
  15272. int tempchargingProfileIdInt;
  15273. int tempchargingProfileStackLevelInt;
  15274. int chkChar;
  15275. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  15276. {
  15277. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  15278. {
  15279. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  15280. }
  15281. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  15282. {
  15283. if(SetProfileReq.evseId==0)
  15284. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15285. else
  15286. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15287. }
  15288. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  15289. {
  15290. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15291. }
  15292. else
  15293. {
  15294. /*
  15295. * TODO:
  15296. *
  15297. */
  15298. }
  15299. infile = fopen ((char*)filename, "r");
  15300. outfile = fopen ((char*)tmpProfileName, "w");
  15301. chkChar = fgetc(infile);
  15302. rewind(infile);
  15303. if(chkChar == EOF)
  15304. {
  15305. // Profile is empty
  15306. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15307. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15308. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15309. fclose(infile);
  15310. fclose(outfile);
  15311. sprintf(rmFileCmd,"rm -f %s",filename);
  15312. system(rmFileCmd);
  15313. rename((char*)tmpProfileName, (char*)filename);
  15314. }
  15315. else
  15316. {
  15317. // Profile is not empty
  15318. int ChargingProfileAdded = FALSE;
  15319. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  15320. {
  15321. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  15322. json_object *tmpChargingProfile;
  15323. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  15324. if(!is_error(tmpChargingProfile))
  15325. {
  15326. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  15327. {
  15328. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  15329. {
  15330. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  15331. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  15332. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  15333. }
  15334. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15335. {
  15336. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  15337. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  15338. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  15339. }
  15340. }
  15341. }
  15342. json_object_put(tmpChargingProfile);
  15343. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  15344. {
  15345. if(ChargingProfileAdded == FALSE)
  15346. {
  15347. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15348. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15349. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15350. ChargingProfileAdded = TRUE;
  15351. }
  15352. }
  15353. else
  15354. {
  15355. fprintf(outfile,"%s\n",dataLine);
  15356. if(ChargingProfileAdded == FALSE)
  15357. {
  15358. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15359. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15360. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15361. ChargingProfileAdded = TRUE;
  15362. }
  15363. }
  15364. } // end of while loop
  15365. fclose(infile);
  15366. fclose(outfile);
  15367. sprintf(rmFileCmd,"rm -f %s",filename);
  15368. system(rmFileCmd);
  15369. rename((char*)tmpProfileName, (char*)filename);
  15370. }
  15371. }
  15372. sleep(1);
  15373. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  15374. result = PASS;
  15375. }
  15376. else
  15377. {
  15378. if(isLostConnectorId)
  15379. DEBUG_WARN("Connector id is wrong.\n");
  15380. if(isConnectorMismatch)
  15381. DEBUG_WARN("Connector id is mismatch.\n");
  15382. if(isPeriodOverMax)
  15383. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15384. if(isProfileOverMax)
  15385. DEBUG_WARN("Profile quantity is over spec.\n");
  15386. if(isTransactiodIdMismatch)
  15387. DEBUG_WARN("Transaction id is mismatch.\n");
  15388. if(isInvalidLimit)
  15389. DEBUG_WARN("Limit value is invalid.\n");
  15390. if(isStackOverMax)
  15391. DEBUG_WARN("Profile stack is over spec.\n");
  15392. if(isWrongFormat)
  15393. DEBUG_WARN("Profile format is wrong.\n");
  15394. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  15395. }
  15396. }
  15397. json_object_put(SetChargingProfile);
  15398. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  15399. {
  15400. if(SetProfileReq.evseId == 0)
  15401. {
  15402. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15403. {
  15404. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  15405. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15406. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  15407. }
  15408. }
  15409. else
  15410. {
  15411. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  15412. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15413. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  15414. }
  15415. }
  15416. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  15417. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15418. return result;
  15419. }
  15420. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  15421. {
  15422. mtrace();
  15423. int result = FAIL;
  15424. json_object *SetDisplayMessage;
  15425. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  15426. SetDisplayMessage = json_tokener_parse(payload);
  15427. if(!is_error(SetDisplayMessage))
  15428. {
  15429. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  15430. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  15431. // Required data
  15432. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  15433. {
  15434. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  15435. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  15436. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  15437. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  15438. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  15439. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  15440. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  15441. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  15442. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  15443. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  15444. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  15445. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  15446. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  15447. {
  15448. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  15449. 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")));
  15450. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  15451. 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")));
  15452. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  15453. 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")));
  15454. }
  15455. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  15456. {
  15457. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  15458. 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")));
  15459. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  15460. 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")));
  15461. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  15462. {
  15463. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  15464. 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"));
  15465. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  15466. 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"));
  15467. }
  15468. }
  15469. }
  15470. }
  15471. json_object_put(SetDisplayMessage);
  15472. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  15473. sendSetDisplayMessagesConfirmation(uuid);
  15474. // Announce CSU there is display request come from server
  15475. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  15476. return result;
  15477. }
  15478. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  15479. {
  15480. mtrace();
  15481. int result = FAIL;
  15482. json_object *SetMonitoringBase;
  15483. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  15484. SetMonitoringBase = json_tokener_parse(payload);
  15485. if(!is_error(SetMonitoringBase))
  15486. {
  15487. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  15488. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  15489. // Required data
  15490. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  15491. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  15492. }
  15493. json_object_put(SetMonitoringBase);
  15494. /*
  15495. * TODO:
  15496. * 1. Configure monitor base and response
  15497. */
  15498. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  15499. sendSetMonitoringBaseConfirmation(uuid);
  15500. return result;
  15501. }
  15502. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  15503. {
  15504. mtrace();
  15505. int result = FAIL;
  15506. json_object *SetMonitoringLevel;
  15507. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  15508. SetMonitoringLevel = json_tokener_parse(payload);
  15509. if(!is_error(SetMonitoringLevel))
  15510. {
  15511. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  15512. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  15513. // Required data
  15514. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  15515. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  15516. }
  15517. json_object_put(SetMonitoringLevel);
  15518. /*
  15519. * TODO:
  15520. * Configure monitor status and response
  15521. */
  15522. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  15523. sendSetMonitoringLevelConfirmation(uuid);
  15524. return result;
  15525. }
  15526. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  15527. {
  15528. mtrace();
  15529. int result = FAIL;
  15530. json_object *SetNetworkProfile;
  15531. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  15532. SetNetworkProfile = json_tokener_parse(payload);
  15533. if(!is_error(SetNetworkProfile))
  15534. {
  15535. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  15536. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  15537. // Required data
  15538. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  15539. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  15540. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  15541. {
  15542. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  15543. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  15544. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  15545. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  15546. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  15547. {
  15548. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  15549. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  15550. }
  15551. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  15552. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  15553. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  15554. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  15555. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  15556. {
  15557. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  15558. 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")));
  15559. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  15560. 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")));
  15561. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  15562. 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")));
  15563. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  15564. 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")));
  15565. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  15566. 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")));
  15567. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  15568. 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")));
  15569. }
  15570. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  15571. {
  15572. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  15573. {
  15574. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  15575. 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")));
  15576. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  15577. }
  15578. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  15579. {
  15580. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  15581. 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")));
  15582. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  15583. }
  15584. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  15585. {
  15586. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  15587. 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")));
  15588. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  15589. }
  15590. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  15591. 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"));
  15592. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  15593. 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")));
  15594. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  15595. 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"));
  15596. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  15597. 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")));
  15598. }
  15599. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  15600. }
  15601. }
  15602. json_object_put(SetNetworkProfile);
  15603. /*
  15604. * TODO:
  15605. * 1. Process network configuration and response
  15606. */
  15607. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  15608. {
  15609. }
  15610. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  15611. {
  15612. }
  15613. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  15614. {
  15615. }
  15616. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  15617. {
  15618. }
  15619. else
  15620. {
  15621. }
  15622. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  15623. {
  15624. }
  15625. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  15626. {
  15627. }
  15628. else
  15629. {
  15630. }
  15631. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  15632. {
  15633. }
  15634. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  15635. {
  15636. }
  15637. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  15638. {
  15639. }
  15640. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  15641. {
  15642. }
  15643. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  15644. {
  15645. }
  15646. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  15647. {
  15648. }
  15649. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  15650. {
  15651. }
  15652. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  15653. {
  15654. }
  15655. else
  15656. {
  15657. }
  15658. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  15659. {
  15660. }
  15661. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  15662. {
  15663. }
  15664. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  15665. {
  15666. }
  15667. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  15668. {
  15669. }
  15670. else
  15671. {
  15672. }
  15673. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  15674. {
  15675. }
  15676. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  15677. {
  15678. }
  15679. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  15680. {
  15681. }
  15682. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  15683. {
  15684. }
  15685. else
  15686. {
  15687. }
  15688. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  15689. sendSetNetworkProfileConfirmation(uuid);
  15690. return result;
  15691. }
  15692. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  15693. {
  15694. mtrace();
  15695. int result = FAIL;
  15696. json_object *SetVariableMonitoring;
  15697. uint8_t variableQuantity = 0;
  15698. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  15699. SetVariableMonitoring = json_tokener_parse(payload);
  15700. if(!is_error(SetVariableMonitoring))
  15701. {
  15702. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  15703. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  15704. // Required data
  15705. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  15706. {
  15707. variableQuantity++;
  15708. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  15709. {
  15710. 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"));
  15711. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  15712. }
  15713. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  15714. {
  15715. 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"));
  15716. }
  15717. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  15718. {
  15719. 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")));
  15720. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  15721. }
  15722. else
  15723. {
  15724. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  15725. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  15726. }
  15727. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  15728. {
  15729. 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"));
  15730. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  15731. }
  15732. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  15733. {
  15734. 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"));
  15735. }
  15736. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  15737. {
  15738. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  15739. {
  15740. 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")));
  15741. }
  15742. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  15743. {
  15744. 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")));
  15745. }
  15746. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  15747. {
  15748. 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)
  15749. {
  15750. 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"));
  15751. }
  15752. 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)
  15753. {
  15754. 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"));
  15755. }
  15756. }
  15757. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  15758. }
  15759. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  15760. {
  15761. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  15762. {
  15763. 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")));
  15764. }
  15765. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  15766. {
  15767. 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")));
  15768. }
  15769. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  15770. }
  15771. /*
  15772. * TODO
  15773. * Set Variables and save to DB
  15774. */
  15775. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  15776. }
  15777. }
  15778. json_object_put(SetVariableMonitoring);
  15779. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  15780. return result;
  15781. }
  15782. int handleSetVariablesRequest(char *uuid, char *payload)
  15783. {
  15784. mtrace();
  15785. int result = FAIL;
  15786. int isUnknownComponent = TRUE;
  15787. json_object *SetVariables;
  15788. DEBUG_INFO("handleSetVariablesRequest...\n");
  15789. SetVariables = json_tokener_parse(payload);
  15790. if(!is_error(SetVariables))
  15791. {
  15792. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  15793. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  15794. // Required data
  15795. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  15796. {
  15797. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  15798. {
  15799. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  15800. {
  15801. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  15802. {
  15803. 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")));
  15804. }
  15805. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  15806. {
  15807. 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")));
  15808. }
  15809. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  15810. {
  15811. 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)
  15812. {
  15813. 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"));
  15814. }
  15815. 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)
  15816. {
  15817. 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"));
  15818. }
  15819. }
  15820. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  15821. }
  15822. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  15823. {
  15824. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  15825. {
  15826. 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")));
  15827. }
  15828. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  15829. {
  15830. 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")));
  15831. }
  15832. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  15833. }
  15834. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  15835. {
  15836. 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")));
  15837. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  15838. }
  15839. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  15840. {
  15841. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  15842. }
  15843. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  15844. {
  15845. 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")));
  15846. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  15847. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  15848. {
  15849. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  15850. (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) &&
  15851. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  15852. (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))
  15853. {
  15854. isUnknownComponent = FALSE;
  15855. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  15856. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  15857. {
  15858. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  15859. break;
  15860. }
  15861. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  15862. {
  15863. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  15864. break;
  15865. }
  15866. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  15867. {
  15868. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  15869. }
  15870. else
  15871. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15872. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  15873. {
  15874. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  15875. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15876. else
  15877. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15878. }
  15879. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  15880. {
  15881. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15882. {
  15883. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15884. }
  15885. else
  15886. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  15887. }
  15888. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  15889. {
  15890. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  15891. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  15892. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  15893. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  15894. {
  15895. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "TRUE" : "FALSE");
  15896. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15897. }
  15898. }
  15899. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  15900. {
  15901. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15902. {
  15903. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15904. }
  15905. else
  15906. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15907. }
  15908. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  15909. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  15910. {
  15911. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  15912. SetOcppConnStatus(FALSE);
  15913. }
  15914. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  15915. {
  15916. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15917. {
  15918. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15919. }
  15920. else
  15921. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15922. }
  15923. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  15924. {
  15925. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  15926. {
  15927. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15928. }
  15929. else
  15930. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15931. }
  15932. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  15933. {
  15934. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  15935. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  15936. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  15937. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  15938. {
  15939. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "TRUE" : "FALSE");
  15940. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  15941. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  15942. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15943. }
  15944. }
  15945. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  15946. {
  15947. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  15948. {
  15949. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  15950. }
  15951. else
  15952. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  15953. }
  15954. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  15955. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  15956. {
  15957. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  15958. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  15959. }
  15960. break;
  15961. }
  15962. else
  15963. {
  15964. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  15965. {
  15966. isUnknownComponent = FALSE;
  15967. }
  15968. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  15969. }
  15970. }
  15971. if(isUnknownComponent == TRUE)
  15972. {
  15973. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  15974. }
  15975. }
  15976. }
  15977. }
  15978. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  15979. }
  15980. json_object_put(SetVariables);
  15981. return result;
  15982. }
  15983. int handleTriggerMessageRequest(char *uuid, char *payload)
  15984. {
  15985. mtrace();
  15986. int result = FAIL;
  15987. int connectorIdIsNULL = FALSE;
  15988. int connectorIdInt =0;
  15989. json_object *TriggerMessage;
  15990. DEBUG_INFO("handleTriggerMessageRequest\n");
  15991. TriggerMessage = json_tokener_parse(payload);
  15992. if(!is_error(TriggerMessage))
  15993. {
  15994. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  15995. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  15996. // Required data
  15997. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  15998. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  15999. // Optional data
  16000. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  16001. {
  16002. // Required data
  16003. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  16004. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  16005. // Optional data
  16006. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  16007. {
  16008. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  16009. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  16010. }
  16011. else
  16012. connectorIdIsNULL = TRUE;
  16013. }
  16014. else
  16015. connectorIdIsNULL = TRUE;
  16016. }
  16017. json_object_put(TriggerMessage);
  16018. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  16019. {
  16020. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  16021. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  16022. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  16023. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  16024. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  16025. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  16026. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  16027. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  16028. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  16029. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  16030. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  16031. {
  16032. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  16033. sendTriggerMessageConfirmation(uuid);
  16034. return TRUE;
  16035. }
  16036. else
  16037. {
  16038. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  16039. sendTriggerMessageConfirmation(uuid);
  16040. }
  16041. }
  16042. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  16043. {
  16044. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16045. sendTriggerMessageConfirmation(uuid);
  16046. return TRUE;
  16047. }
  16048. //==========================
  16049. // Trigger message
  16050. //==========================
  16051. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  16052. {
  16053. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  16054. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  16055. {
  16056. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  16057. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16058. }
  16059. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16060. }
  16061. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  16062. {
  16063. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  16064. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  16065. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  16066. }
  16067. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  16068. {
  16069. if(server_sign)
  16070. {
  16071. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16072. sendTriggerMessageConfirmation(uuid);
  16073. return TRUE;
  16074. }
  16075. else
  16076. {
  16077. if(DB_updateBootType(BootReasonEnumType_Triggered))
  16078. server_sign = FALSE;
  16079. }
  16080. }
  16081. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  16082. {
  16083. refreshStartTimer(&clientTime.Heartbeat);
  16084. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  16085. }
  16086. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  16087. {
  16088. if(connectorIdIsNULL == FALSE)
  16089. {
  16090. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16091. {
  16092. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  16093. }
  16094. }
  16095. else
  16096. {
  16097. for(int idx=0;idx< gunTotalNumber;idx++)
  16098. {
  16099. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  16100. }
  16101. }
  16102. }
  16103. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  16104. {
  16105. if(connectorIdIsNULL == FALSE)
  16106. {
  16107. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16108. {
  16109. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  16110. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  16111. }
  16112. }
  16113. else
  16114. {
  16115. for(int idx=0;idx< gunTotalNumber;idx++)
  16116. {
  16117. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  16118. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  16119. }
  16120. }
  16121. }
  16122. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  16123. {
  16124. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16125. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16126. {
  16127. 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\" &");
  16128. }
  16129. }
  16130. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  16131. {
  16132. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16133. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16134. {
  16135. 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\" &");
  16136. }
  16137. }
  16138. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  16139. {
  16140. if(connectorIdIsNULL == FALSE)
  16141. {
  16142. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  16143. {
  16144. ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  16145. }
  16146. }
  16147. else
  16148. {
  16149. for(int idx=0;idx< gunTotalNumber;idx++)
  16150. ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  16151. }
  16152. }
  16153. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  16154. {
  16155. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16156. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16157. {
  16158. 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\" &");
  16159. }
  16160. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16161. {
  16162. 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\" &");
  16163. }
  16164. }
  16165. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  16166. {
  16167. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  16168. }
  16169. return result;
  16170. }
  16171. int handleUnlockConnectorRequest(char *uuid, char *payload)
  16172. {
  16173. mtrace();
  16174. int result = FAIL;
  16175. int connectorIdInt =0;
  16176. int tempIndex = 0;
  16177. json_object *UnlockConnector;
  16178. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  16179. UnlockConnector = json_tokener_parse(payload);
  16180. if(!is_error(UnlockConnector))
  16181. {
  16182. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  16183. {
  16184. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  16185. }
  16186. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  16187. {
  16188. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  16189. }
  16190. }
  16191. json_object_put(UnlockConnector);
  16192. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  16193. if(gunTotalNumber == 0)
  16194. {
  16195. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16196. goto end;
  16197. }
  16198. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  16199. {
  16200. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16201. goto end;
  16202. }
  16203. else
  16204. {
  16205. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  16206. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  16207. //check Transaction active
  16208. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  16209. {
  16210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16211. {
  16212. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16213. }
  16214. else
  16215. {
  16216. tempIndex = connectorIdInt -1;
  16217. }
  16218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16219. {
  16220. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  16221. {
  16222. //stop Transaction
  16223. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16224. }
  16225. }
  16226. }
  16227. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  16228. {
  16229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16230. {
  16231. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16232. }
  16233. else
  16234. {
  16235. tempIndex = connectorIdInt -1;
  16236. }
  16237. for (int index = 0; index < CCS_QUANTITY; index++)
  16238. {
  16239. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  16240. {
  16241. //stop Transaction
  16242. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16243. }
  16244. }
  16245. }
  16246. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  16247. {
  16248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16249. {
  16250. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16251. }
  16252. else
  16253. {
  16254. tempIndex = connectorIdInt -1;
  16255. }
  16256. for (int index = 0; index < GB_QUANTITY; index++)
  16257. {
  16258. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  16259. {
  16260. //stop Transaction
  16261. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16262. }
  16263. }
  16264. }
  16265. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  16266. {
  16267. tempIndex = connectorIdInt -1;
  16268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16269. {
  16270. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  16271. {
  16272. //stop Transaction
  16273. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16274. }
  16275. }
  16276. }
  16277. else
  16278. {
  16279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16280. {
  16281. tempIndex = 2;
  16282. }
  16283. else
  16284. {
  16285. tempIndex = connectorIdInt-1;
  16286. }
  16287. for (int index = 0; index < AC_QUANTITY; index++)
  16288. {
  16289. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  16290. {
  16291. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16292. }
  16293. }
  16294. }
  16295. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  16296. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  16297. result = TRUE;
  16298. return result;
  16299. }
  16300. end:
  16301. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorConf = ON;
  16302. return result;
  16303. }
  16304. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  16305. {
  16306. mtrace();
  16307. int result = FAIL;
  16308. json_object *UnpublishFirmware;
  16309. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  16310. UnpublishFirmware = json_tokener_parse(payload);
  16311. if(!is_error(UnpublishFirmware))
  16312. {
  16313. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  16314. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  16315. // Required data
  16316. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  16317. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  16318. }
  16319. json_object_put(UnpublishFirmware);
  16320. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  16321. /*
  16322. * TODO:
  16323. * 1. Check unpublished status
  16324. */
  16325. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  16326. sendUnpublishFirmwareConfirmation(uuid);
  16327. return result;
  16328. }
  16329. static char UpdateFirmwarepayloadData[512]={0};
  16330. void *UpdateFirmwareProcess(void *data)
  16331. {
  16332. pthread_detach(pthread_self());
  16333. mtrace();
  16334. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  16335. int port=0;
  16336. int isSuccess = 0;
  16337. char ftpbuf[1024];
  16338. char temp[1024];
  16339. char * pch;
  16340. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  16341. json_object *UpdateFirmware;
  16342. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  16343. if(!is_error(UpdateFirmware))
  16344. {
  16345. // Required data
  16346. if(json_object_object_get(UpdateFirmware, "requestId"))
  16347. {
  16348. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  16349. }
  16350. if(json_object_object_get(UpdateFirmware, "firmware"))
  16351. {
  16352. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  16353. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  16354. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  16355. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  16356. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  16357. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  16358. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  16359. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  16360. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  16361. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  16362. }
  16363. // Optional data
  16364. if(json_object_object_get(UpdateFirmware, "retries"))
  16365. {
  16366. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  16367. }
  16368. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  16369. {
  16370. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  16371. }
  16372. }
  16373. json_object_put(UpdateFirmware);
  16374. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  16375. memset(path, 0, ARRAY_SIZE(path));
  16376. // Wait retrieveData
  16377. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  16378. {
  16379. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16380. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  16381. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16382. do
  16383. {
  16384. sleep(1);
  16385. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  16386. }
  16387. system("rm -f /mnt/*");
  16388. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  16389. {
  16390. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  16391. sprintf(ftppath,"/%s", path);
  16392. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  16393. DEBUG_INFO("protocol: %s\n",protocol);
  16394. DEBUG_INFO("host: %s\n",host);
  16395. DEBUG_INFO("path: %s\n",path);
  16396. DEBUG_INFO("ftppath: %s\n",ftppath);
  16397. int ftppathlen=strlen(ftppath);
  16398. int i=1;
  16399. char filenametemp[50];
  16400. while(i < ftppathlen)
  16401. {
  16402. int len=ftppathlen-i;
  16403. if(ftppath[len]== 47) // '/' ascll code: 47
  16404. {
  16405. DEBUG_INFO("compare '/' all right\n");
  16406. break;
  16407. }
  16408. i=i+1;
  16409. }
  16410. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16411. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  16412. filenametemp[i+1] = 0;
  16413. do
  16414. {
  16415. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16416. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16417. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16418. sleep(3);
  16419. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16420. if(!isSuccess)
  16421. {
  16422. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16423. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16424. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16425. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16426. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16427. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16428. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16429. }
  16430. else
  16431. {
  16432. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16433. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16434. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16435. }
  16436. ShmOCPP20Data->UpdateFirmware.retries--;
  16437. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16438. }
  16439. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  16440. {
  16441. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16442. memset(temp, 0, ARRAY_SIZE(temp));
  16443. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16444. int ftppathlen=strlen(ftpbuf);
  16445. int i=1;
  16446. char filenametemp[50];
  16447. while(i < ftppathlen)
  16448. {
  16449. int len=ftppathlen-i;
  16450. if(ftpbuf[len]== 47) // '/' ascll code: 47
  16451. {
  16452. DEBUG_INFO(" compare '/' all right\n");
  16453. break;
  16454. }
  16455. i=i+1;
  16456. }
  16457. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16458. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  16459. filenametemp[i+1] = 0;
  16460. strncpy(temp, ftpbuf, ftppathlen-i+1);
  16461. pch=strchr(temp,'@');
  16462. if(pch==NULL)
  16463. {
  16464. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16465. protocol, host, &port, path);
  16466. strcpy(user,"anonymous");
  16467. strcpy(password,"");
  16468. }
  16469. else
  16470. {
  16471. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  16472. protocol, user, password, host, &port, path);
  16473. }
  16474. sscanf(host,"%[^/]%s",host1, path1);
  16475. sprintf(ftppath,"%s", path1);
  16476. if(port == 0)
  16477. {
  16478. port = 21;
  16479. }
  16480. do
  16481. {
  16482. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16483. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16484. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16485. sleep(3);
  16486. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16487. if(!isSuccess)
  16488. {
  16489. //BulldogUtil.sleepMs(interval*1000);
  16490. DEBUG_INFO("Update firmware request and download file fail.\n");
  16491. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16492. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16493. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16494. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16495. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16496. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16497. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16498. }
  16499. else
  16500. {
  16501. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16502. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16503. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16504. }
  16505. ShmOCPP20Data->UpdateFirmware.retries--;
  16506. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16507. }
  16508. else
  16509. {
  16510. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16511. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16512. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16513. sleep(1);
  16514. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16515. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16516. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16517. }
  16518. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  16519. interLock.isUpdateFirmwareGoing = OFF;
  16520. pthread_exit(NULL);
  16521. }
  16522. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  16523. {
  16524. mtrace();
  16525. int result = FAIL;
  16526. pthread_t t;
  16527. sendUpdateFirmwareConfirmation(uuid);
  16528. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  16529. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  16530. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  16531. if(!interLock.isUpdateFirmwareGoing)
  16532. {
  16533. interLock.isUpdateFirmwareGoing = ON;
  16534. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  16535. sleep(1);
  16536. }
  16537. else
  16538. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  16539. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  16540. return result;
  16541. }
  16542. int handleUnknownRequest(char *uuid, char *payload)
  16543. {
  16544. mtrace();
  16545. int result = FAIL;
  16546. DEBUG_INFO("handleUnknownRequest...\n");
  16547. sendUnknownConfirmation(uuid);
  16548. result = PASS;
  16549. return result;
  16550. }
  16551. //==========================================
  16552. // Handle server response routine
  16553. //==========================================
  16554. void handleAuthorizeResponse(char *payload, int gun_index)
  16555. {
  16556. mtrace();
  16557. DEBUG_INFO("handleAuthorizeResponse...\n");
  16558. json_object *Authorize;
  16559. Authorize = json_tokener_parse(payload);
  16560. if(!is_error(Authorize))
  16561. {
  16562. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  16563. {
  16564. // Required data
  16565. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  16566. // Optional data
  16567. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  16568. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  16569. else
  16570. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  16571. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  16572. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  16573. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  16574. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  16575. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  16576. {
  16577. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  16578. {
  16579. 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));
  16580. }
  16581. }
  16582. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  16583. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  16584. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  16585. {
  16586. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  16587. 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")));
  16588. else
  16589. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  16590. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  16591. 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")));
  16592. }
  16593. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  16594. {
  16595. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  16596. 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")));
  16597. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  16598. 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")));
  16599. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  16600. 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")));
  16601. }
  16602. }
  16603. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  16604. {
  16605. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  16606. }
  16607. }
  16608. json_object_put(Authorize);
  16609. //Update idTag information to authorization cache if supported
  16610. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  16611. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  16612. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  16613. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  16614. {
  16615. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  16616. }
  16617. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  16618. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  16619. authorizeRetryTimes = 0;
  16620. }
  16621. void handleBootNotificationResponse(char *payload, int gun_index)
  16622. {
  16623. mtrace();
  16624. char statusStr[12]={0};
  16625. char currentTimeStr[30]={0};
  16626. int intervalInt = 0;
  16627. DEBUG_INFO("handleBootNotificationResponse...\n");
  16628. json_object *BootNotification;
  16629. BootNotification = json_tokener_parse(payload);
  16630. if(!is_error(BootNotification))
  16631. {
  16632. // Required data
  16633. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  16634. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  16635. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  16636. }
  16637. json_object_put(BootNotification);
  16638. DEBUG_INFO("statusStr: %s\n", statusStr);
  16639. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  16640. BootNotificationInterval = intervalInt;
  16641. //write back to ShmOCPP20Data->BootNotification
  16642. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  16643. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  16644. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  16645. {
  16646. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  16647. {
  16648. //Do nothing because the value is out of range.
  16649. }
  16650. else
  16651. {
  16652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  16653. HeartBeatWaitTime = intervalInt;
  16654. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  16655. }
  16656. server_sign = TRUE;
  16657. server_pending =FALSE;
  16658. DB_updateBootType(BootReasonEnumType_PowerUp);
  16659. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  16660. }
  16661. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  16662. {
  16663. server_pending = TRUE;
  16664. }
  16665. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  16666. srand(time(NULL));
  16667. refreshStartTimer(&clientTime.Heartbeat);
  16668. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  16669. SetOcppConnStatus(TRUE);
  16670. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  16671. }
  16672. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  16673. {
  16674. mtrace();
  16675. json_object *ClearedChargingLimit;
  16676. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  16677. ClearedChargingLimit = json_tokener_parse(payload);
  16678. if(!is_error(ClearedChargingLimit))
  16679. {
  16680. // Required data
  16681. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  16682. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  16683. }
  16684. json_object_put(ClearedChargingLimit);
  16685. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  16686. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  16687. }
  16688. void handleDataTransferResponse(char *payload, int gun_index)
  16689. {
  16690. mtrace();
  16691. json_object *DataTrans;
  16692. DEBUG_INFO("handleDataTransferResponse...\n");
  16693. DataTrans = json_tokener_parse(payload);
  16694. if(!is_error(DataTrans))
  16695. {
  16696. // Required data
  16697. if(json_object_object_get(DataTrans,"status") != NULL)
  16698. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  16699. // Optional data
  16700. if(json_object_object_get(DataTrans,"data") != NULL)
  16701. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  16702. }
  16703. json_object_put(DataTrans);
  16704. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  16705. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  16706. }
  16707. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  16708. {
  16709. mtrace();
  16710. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  16711. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  16712. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  16713. }
  16714. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  16715. {
  16716. mtrace();
  16717. json_object *Get15118EVCertificate;
  16718. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  16719. Get15118EVCertificate = json_tokener_parse(payload);
  16720. if(!is_error(Get15118EVCertificate))
  16721. {
  16722. // Required data
  16723. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  16724. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  16725. // Optional data
  16726. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  16727. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  16728. }
  16729. json_object_put(Get15118EVCertificate);
  16730. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  16731. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  16732. }
  16733. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  16734. {
  16735. mtrace();
  16736. json_object *GetCertificateStatus;
  16737. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  16738. GetCertificateStatus = json_tokener_parse(payload);
  16739. if(!is_error(GetCertificateStatus))
  16740. {
  16741. // Required data
  16742. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  16743. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  16744. // Optional data
  16745. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  16746. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  16747. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  16748. {
  16749. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  16750. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  16751. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  16752. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  16753. }
  16754. }
  16755. json_object_put(GetCertificateStatus);
  16756. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  16757. {
  16758. /*
  16759. * TODO:
  16760. * 1. If get certificate response accepted process something here
  16761. */
  16762. }
  16763. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  16764. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  16765. }
  16766. void handleHeartbeatResponse(char *payload, int gun_index)
  16767. {
  16768. mtrace();
  16769. DEBUG_INFO("handleHeartbeatResponse...\n");
  16770. json_object *Heartbeat;
  16771. Heartbeat = json_tokener_parse(payload);
  16772. if(!is_error(Heartbeat))
  16773. {
  16774. // Required data
  16775. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  16776. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  16777. }
  16778. json_object_put(Heartbeat);
  16779. if(FirstHeartBeat == OFF)
  16780. {
  16781. FirstHeartBeat = ON;
  16782. DEBUG_INFO("FirstHeartBeat \n");
  16783. }
  16784. HeartBeatWithNOResponse = 0;
  16785. refreshStartTimer(&clientTime.Heartbeat);
  16786. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  16787. }
  16788. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  16789. {
  16790. mtrace();
  16791. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  16792. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  16793. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  16794. }
  16795. void handleMeterValuesResponse(char *payload, int gun_index)
  16796. {
  16797. mtrace();
  16798. DEBUG_INFO("handleMeterValuesResponse...\n");
  16799. isQueueSendable = ON;
  16800. }
  16801. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  16802. {
  16803. mtrace();
  16804. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  16805. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  16806. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  16807. }
  16808. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  16809. {
  16810. mtrace();
  16811. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  16812. }
  16813. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  16814. {
  16815. mtrace();
  16816. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  16817. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  16818. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  16819. }
  16820. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  16821. {
  16822. mtrace();
  16823. json_object *NotifyEVChargingNeeds;
  16824. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  16825. NotifyEVChargingNeeds = json_tokener_parse(payload);
  16826. if(!is_error(NotifyEVChargingNeeds))
  16827. {
  16828. // Required data
  16829. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  16830. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  16831. }
  16832. json_object_put(NotifyEVChargingNeeds);
  16833. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  16834. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  16835. }
  16836. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  16837. {
  16838. mtrace();
  16839. json_object *NotifyEVChargingSchedule;
  16840. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  16841. NotifyEVChargingSchedule = json_tokener_parse(payload);
  16842. if(!is_error(NotifyEVChargingSchedule))
  16843. {
  16844. // Required data
  16845. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  16846. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  16847. }
  16848. json_object_put(NotifyEVChargingSchedule);
  16849. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  16850. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  16851. }
  16852. void handleNotifyEventResponse(char *payload, int gun_index)
  16853. {
  16854. mtrace();
  16855. DEBUG_INFO("handleNotifyEventResponse...\n");
  16856. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  16857. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  16858. }
  16859. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  16860. {
  16861. mtrace();
  16862. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  16863. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  16864. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  16865. }
  16866. void handleNotifyReportResponse(char *payload, int gun_index)
  16867. {
  16868. mtrace();
  16869. DEBUG_INFO("handleNotifyReportResponse...\n");
  16870. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  16871. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  16872. }
  16873. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  16874. {
  16875. mtrace();
  16876. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  16877. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  16878. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  16879. }
  16880. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  16881. {
  16882. mtrace();
  16883. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  16884. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  16885. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  16886. }
  16887. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  16888. {
  16889. mtrace();
  16890. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  16891. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  16892. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  16893. }
  16894. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  16895. {
  16896. mtrace();
  16897. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  16898. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  16899. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  16900. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  16901. }
  16902. void handleSignCertificateResponse(char *payload, int gun_index)
  16903. {
  16904. mtrace();
  16905. json_object *SignCertificate;
  16906. DEBUG_INFO("handleSignCertificateResponse...\n");
  16907. SignCertificate = json_tokener_parse(payload);
  16908. if(!is_error(SignCertificate))
  16909. {
  16910. // Required data
  16911. if(json_object_object_get(SignCertificate,"status") != NULL)
  16912. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  16913. // Optional data
  16914. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  16915. {
  16916. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  16917. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  16918. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  16919. }
  16920. }
  16921. json_object_put(SignCertificate);
  16922. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  16923. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  16924. }
  16925. void handleStatusNotificationResponse(char *payload, int gun_index)
  16926. {
  16927. mtrace();
  16928. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  16929. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  16930. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  16931. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  16932. }
  16933. void handleTransactionEventResponse(char *payload, int gun_index)
  16934. {
  16935. mtrace();
  16936. json_object *TransactionEven;
  16937. DEBUG_INFO("handleTransactionEventResponse...\n");
  16938. TransactionEven = json_tokener_parse(payload);
  16939. if(!is_error(TransactionEven))
  16940. {
  16941. // Required data
  16942. // Optional data
  16943. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  16944. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  16945. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  16946. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  16947. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  16948. {
  16949. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  16950. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  16951. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  16952. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  16953. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  16954. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  16955. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  16956. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  16957. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  16958. {
  16959. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  16960. 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")));
  16961. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  16962. 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")));
  16963. }
  16964. }
  16965. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  16966. {
  16967. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  16968. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  16969. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  16970. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  16971. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  16972. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  16973. }
  16974. }
  16975. json_object_put(TransactionEven);
  16976. isQueueSendable = ON;
  16977. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  16978. }
  16979. //==========================================
  16980. // Handle Error routine
  16981. //==========================================
  16982. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  16983. {
  16984. mtrace();
  16985. #ifdef SystemLogMessage
  16986. DEBUG_INFO("errorCode: %s\n", errorCode);
  16987. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  16988. DEBUG_INFO("errorDetails: %s\n", payload);
  16989. #endif
  16990. }
  16991. //===============================================
  16992. // Common routine
  16993. //===============================================
  16994. int initialConfigurationTable(void)
  16995. {
  16996. DEBUG_INFO("initialConfigurationTable...\n");
  16997. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  16998. DB_variableIsCreate();
  16999. DB_variableLoadFromDb();
  17000. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  17001. {
  17002. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  17003. DB_variableClear();
  17004. DB_variableIsCreate();
  17005. DB_variableLoadFromDb();
  17006. }
  17007. DB_getNetworkProfileFromDb();
  17008. return 0;
  17009. }
  17010. int TransactionMessageAttemptsGet(void)
  17011. {
  17012. return TransactionMessageAttemptsValue;
  17013. }
  17014. int FirstHeartBeatResponse(void)
  17015. {
  17016. return FirstHeartBeat;
  17017. }
  17018. int TransactionMessageRetryIntervalGet(void)
  17019. {
  17020. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17021. }
  17022. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17023. {
  17024. int result = TRUE;
  17025. char rmFileCmd[100]={0};
  17026. char FilePath[100]={0};
  17027. char ftpbuf[200];
  17028. int systemresult;
  17029. sprintf(FilePath,"/mnt/%s",filename);
  17030. system("ping 8.8.8.8 &");
  17031. if((access(FilePath,F_OK))!=-1)
  17032. {
  17033. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17034. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17035. system(rmFileCmd);
  17036. }
  17037. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17038. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17039. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17040. systemresult = system(ftpbuf);
  17041. if(systemresult != 0)
  17042. {
  17043. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  17044. result = FALSE;
  17045. }
  17046. system("pkill ping");
  17047. return result;
  17048. }
  17049. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17050. {
  17051. int result = TRUE;
  17052. char rmFileCmd[100]={0};
  17053. char FilePath[100]={0};
  17054. char ftpbuf[200];
  17055. int systemresult;
  17056. sprintf(FilePath,"/mnt/%s",filename);
  17057. system("ping 8.8.8.8 &");
  17058. if((access(FilePath,F_OK))!=-1)
  17059. {
  17060. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17061. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17062. system(rmFileCmd);
  17063. }
  17064. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17065. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17066. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17067. systemresult = system(ftpbuf);
  17068. if(systemresult != 0)
  17069. {
  17070. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17071. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17072. systemresult = system(ftpbuf);
  17073. if(systemresult != 0)
  17074. {
  17075. DEBUG_WARN("FTP download fail!\n");
  17076. result = FALSE;
  17077. }
  17078. }
  17079. system("pkill ping");
  17080. return result;
  17081. }
  17082. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17083. {
  17084. char rmFileCmd[100]={0};
  17085. char FilePath[100]={0};
  17086. char buf[512];
  17087. int systemresult = 0;
  17088. //DEBUG_INFO("filename=%s\n",filename);
  17089. //DEBUG_INFO("url=%s\n",url);
  17090. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17091. if((access(FilePath,F_OK))!=-1)
  17092. {
  17093. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17094. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17095. system(rmFileCmd);
  17096. }
  17097. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17098. if(fp == NULL)
  17099. {
  17100. DEBUG_INFO("log is NULL\n");
  17101. return FALSE;
  17102. }
  17103. else
  17104. {
  17105. fprintf(fp, "%s\n", url);
  17106. fprintf(fp, "%s\n", filename);
  17107. fclose(fp);
  17108. }
  17109. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17110. if(phpFP == NULL)
  17111. {
  17112. DEBUG_INFO("PHP upload fail.\n");
  17113. return FALSE;
  17114. }
  17115. else
  17116. {
  17117. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17118. {
  17119. if(strstr(buf, "result") != NULL)
  17120. {
  17121. sscanf(buf, "result: %d", &systemresult);
  17122. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17123. }
  17124. }
  17125. pclose(phpFP);
  17126. }
  17127. if(systemresult != 1)
  17128. {
  17129. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17130. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17131. if(phpFP == NULL)
  17132. {
  17133. DEBUG_WARN("PHP PUT upload fail.\n");
  17134. return FALSE;
  17135. }
  17136. else
  17137. {
  17138. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17139. {
  17140. if(strstr(buf, "result") != NULL)
  17141. {
  17142. sscanf(buf, "result: %d", &systemresult);
  17143. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17144. }
  17145. }
  17146. pclose(phpFP);
  17147. }
  17148. }
  17149. if(systemresult != 1)
  17150. {
  17151. DEBUG_WARN("PHP PUT upload fail.\n");
  17152. return FALSE;
  17153. }
  17154. return TRUE;
  17155. }
  17156. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17157. {
  17158. int result = FALSE;
  17159. char ftpbuf[200];
  17160. int systemresult;
  17161. /*
  17162. // Domaind name transfer to IP address
  17163. struct hostent* server;
  17164. char *IPbuffer;
  17165. server = gethostbyname(location);
  17166. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17167. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17168. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17169. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17170. systemresult = system(ftpbuf);
  17171. if(systemresult != 0)
  17172. {
  17173. DEBUG_INFO("ftpput error!\n");
  17174. }
  17175. else
  17176. {
  17177. result = TRUE;
  17178. DEBUG_INFO("ftpput OK!\n");
  17179. }
  17180. return result;
  17181. }
  17182. //=========================================
  17183. // Routine
  17184. //=========================================
  17185. int GetOcppServerURL()
  17186. {
  17187. int result = FALSE;
  17188. struct yuarel url;
  17189. char urlStr[512];
  17190. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17191. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17192. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17193. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  17194. {
  17195. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  17196. if(yuarel_parse(&url, urlStr) != -1)
  17197. {
  17198. sprintf(OcppProtocol, "%s", url.scheme);
  17199. sprintf(OcppHost, "%s", url.host);
  17200. if(url.path == NULL)
  17201. OcppTempPath[0] = '\0';
  17202. else
  17203. sprintf(OcppTempPath, "%s", url.path);
  17204. if(url.port == 0)
  17205. {
  17206. if(strcmp(OcppProtocol, "wss") == 0)
  17207. OcppPort = 443;
  17208. else
  17209. OcppPort = 80;
  17210. }
  17211. else
  17212. OcppPort = url.port;
  17213. result = TRUE;
  17214. }
  17215. }
  17216. else
  17217. {
  17218. strcpy(OcppHost,"");
  17219. }
  17220. return result;
  17221. }
  17222. int GetOcppPath()
  17223. {
  17224. int result = FALSE;
  17225. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17226. {
  17227. if(OcppTempPath == NULL)
  17228. {
  17229. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17230. }
  17231. else
  17232. {
  17233. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17234. }
  17235. result = TRUE;
  17236. }
  17237. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  17238. {
  17239. if(OcppTempPath == NULL)
  17240. {
  17241. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  17242. }
  17243. else
  17244. {
  17245. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  17246. }
  17247. result = TRUE;
  17248. }
  17249. else
  17250. {
  17251. strcpy(OcppPath,"");
  17252. }
  17253. return result;
  17254. }
  17255. int GetOcppPort()
  17256. {
  17257. return OcppPort;
  17258. }
  17259. int GetOcppConnStatus(void)
  17260. {
  17261. return ShmOCPP20Data->OcppConnStatus;
  17262. }
  17263. void SetOcppConnStatus(uint8_t status)
  17264. {
  17265. ShmOCPP20Data->OcppConnStatus = status;
  17266. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17267. }
  17268. int GetHeartBeatWithNOResponse(void)
  17269. {
  17270. return HeartBeatWithNOResponse;
  17271. }
  17272. void SetHeartBeatWithNOResponse(void)
  17273. {
  17274. HeartBeatWithNOResponse = 0;
  17275. }
  17276. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17277. void storeTempStopTransaction(int gun_index)
  17278. {
  17279. char TempStopTransaction[256];
  17280. char message[1024*20]={0};
  17281. char guid[37]={0};
  17282. json_object *TransactionEvent = json_object_new_object();
  17283. json_object *transactionInfo = json_object_new_object();
  17284. json_object *idToken = json_object_new_object();
  17285. json_object *evse = json_object_new_object();
  17286. json_object *meterValues = json_object_new_array();
  17287. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17288. DEBUG_INFO("storeTempStopTransaction...\n");
  17289. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  17290. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  17291. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  17292. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  17293. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  17294. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  17295. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  17296. // Message
  17297. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  17298. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  17299. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  17300. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  17301. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  17302. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  17303. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  17304. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  17305. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  17306. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  17307. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  17308. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  17309. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  17310. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  17311. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  17312. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  17313. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  17314. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  17315. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  17316. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  17317. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  17318. {
  17319. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  17320. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  17321. json_object_object_add(TransactionEvent, "idToken", idToken);
  17322. }
  17323. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  17324. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  17325. json_object_object_add(TransactionEvent, "evse", evse);
  17326. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  17327. {
  17328. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  17329. {
  17330. json_object *meterValue = json_object_new_object();
  17331. json_object *sampledValues = json_object_new_array();
  17332. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  17333. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  17334. {
  17335. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  17336. ((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)))
  17337. {
  17338. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)
  17339. {
  17340. json_object *sampledValue = json_object_new_object();
  17341. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  17342. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  17343. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  17344. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  17345. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  17346. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  17347. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  17348. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  17349. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  17350. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  17351. {
  17352. json_object *unitOfMeasure = json_object_new_object();
  17353. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  17354. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  17355. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  17356. }
  17357. json_object_array_add(sampledValues, sampledValue);
  17358. }
  17359. }
  17360. }
  17361. json_object_object_add(meterValue, "sampledValue", sampledValues);
  17362. json_object_array_add(meterValues, meterValue);
  17363. }
  17364. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  17365. }
  17366. random_uuid(guid);
  17367. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  17368. , guid
  17369. , "TransactionEvent"
  17370. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  17371. json_object_put(TransactionEvent);
  17372. // open file for writing
  17373. FILE *outfile;
  17374. outfile = fopen (TempStopTransaction, "w+");
  17375. //DEBUG_INFO("data = %s\n", queuedata);
  17376. fputs(message, outfile);
  17377. fputs("\n", outfile);
  17378. fclose (outfile);
  17379. }
  17380. void checkTempStopTransaction(int gun_index)
  17381. {
  17382. FILE *fptr1;
  17383. char ch;
  17384. char str[QUEUE_MESSAGE_LENGTH]={0};
  17385. char guid[37]={0};
  17386. char tempdata[65]={0};
  17387. char TempStopTransaction[256];
  17388. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17389. fptr1 = fopen(TempStopTransaction, "r");
  17390. if (!fptr1)
  17391. {
  17392. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  17393. return ;
  17394. }
  17395. ch=fgetc(fptr1);
  17396. rewind(fptr1);
  17397. if(ch!=EOF)
  17398. {
  17399. // copy all contents to the temporary file except the specific line
  17400. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17401. {
  17402. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17403. if(str[0]=='\0')
  17404. {
  17405. break;
  17406. }
  17407. strncpy(guid, str+4, 36); //copy guid
  17408. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  17409. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17410. {
  17411. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17412. }
  17413. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17414. memset(str,0,ARRAY_SIZE(str));
  17415. }
  17416. }
  17417. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17418. fclose(fptr1);
  17419. remove(TempStopTransaction); // remove the original file
  17420. }
  17421. int GetWebSocketPingInterval(void)
  17422. {
  17423. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  17424. }
  17425. int GetServerSign(void)
  17426. {
  17427. return server_sign;
  17428. }
  17429. uint8_t GetOcppSecurityProfile()
  17430. {
  17431. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  17432. }
  17433. void GetOcppChargerBoxId(uint8_t *data)
  17434. {
  17435. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17436. }
  17437. void GetOcppSecurityPassword(uint8_t *data)
  17438. {
  17439. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  17440. }
  17441. void SetServerSign(int value)
  17442. {
  17443. server_sign = value;
  17444. }
  17445. int GetBootNotificationInterval(void)
  17446. {
  17447. return BootNotificationInterval;
  17448. }
  17449. int GetInternetConn(void)
  17450. {
  17451. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17452. }
  17453. int GetBackendConnectionTimeout(void)
  17454. {
  17455. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17456. }
  17457. int isConnectorInitMode(int gun_index)
  17458. {
  17459. int tempIndex = 0;
  17460. int result = TRUE;
  17461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17463. {
  17464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17465. {
  17466. tempIndex = ((gun_index==2) ? 1: 0);
  17467. }
  17468. else
  17469. {
  17470. tempIndex = gun_index;
  17471. }
  17472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17473. {
  17474. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17475. {
  17476. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17477. } //end of the same index
  17478. }//end of for CHAdeMO_QUANTITY
  17479. }
  17480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17481. {
  17482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17483. {
  17484. tempIndex = ((gun_index==2) ? 1: 0);
  17485. }
  17486. else
  17487. {
  17488. tempIndex = gun_index;
  17489. }
  17490. for (int index = 0; index < CCS_QUANTITY; index++)
  17491. {
  17492. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17493. {
  17494. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17495. } //end of the same index
  17496. } // end of for CCS_QUANTITY
  17497. }
  17498. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17499. {
  17500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17501. {
  17502. tempIndex = ((gun_index==2) ? 1: 0);
  17503. }
  17504. else
  17505. {
  17506. tempIndex = gun_index;
  17507. }
  17508. for (int index = 0; index < GB_QUANTITY; index++)
  17509. {
  17510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17511. {
  17512. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17513. } //end of the same index
  17514. } // end of for GB_QUANTITY
  17515. }
  17516. else if(gunType[gun_index] == GUN_TYPE_DO)
  17517. {
  17518. tempIndex = gun_index;
  17519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17520. {
  17521. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17522. {
  17523. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17524. } //end of the same index
  17525. }
  17526. }
  17527. else
  17528. {
  17529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17530. {
  17531. tempIndex = 2;
  17532. }
  17533. else
  17534. {
  17535. tempIndex = gun_index;
  17536. }
  17537. for (int index = 0; index < AC_QUANTITY; index++)
  17538. {
  17539. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17540. {
  17541. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17542. }//end of the same index
  17543. }//end of for AC_QUANTITY
  17544. }
  17545. return result;
  17546. }
  17547. void refreshProcDogTimer()
  17548. {
  17549. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  17550. }
  17551. void InitialSystemValue(void)
  17552. {
  17553. localversion=0;
  17554. BootNotificationInterval = 10;
  17555. authorizeRetryTimes = 0;
  17556. GunStatusInterval = 10;
  17557. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  17558. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  17559. //Hear Beat
  17560. HeartBeatWithNOResponse = 0;
  17561. HeartBeatCountPerHour = 0;
  17562. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  17563. FirstHeartBeat = 0;
  17564. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  17565. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  17566. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17567. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17568. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17569. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17570. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17571. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17572. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17573. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17574. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17575. //Status && ConnectorPlugIn Setting
  17576. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17577. {
  17578. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17579. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17580. }
  17581. for (int index = 0; index < CCS_QUANTITY; index++)
  17582. {
  17583. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17584. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17585. }
  17586. for (int index = 0; index < GB_QUANTITY; index++)
  17587. {
  17588. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17589. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17590. }
  17591. for (int index = 0; index < AC_QUANTITY; index++)
  17592. {
  17593. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17594. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17595. }
  17596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17597. {
  17598. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17599. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17600. }
  17601. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17602. {
  17603. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  17604. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  17605. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  17606. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17607. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  17608. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  17609. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  17610. }
  17611. refreshStartTimer(&clientTime.Heartbeat);
  17612. sleep(1);
  17613. }
  17614. void LWS_Send(char *str)
  17615. {
  17616. //=====================================================
  17617. // Check InternetConn 0: disconnected, 1: connected
  17618. //====================================================
  17619. if(GetOcppConnStatus() == 0)
  17620. {
  17621. DEBUG_INFO("offline now !!!\n");
  17622. return;
  17623. }
  17624. // Only disable isWebsocketSendable operation initiated by charger
  17625. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17626. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17627. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  17628. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17629. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17630. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  17631. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  17632. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17633. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17634. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17635. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  17636. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  17637. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  17638. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  17639. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  17640. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  17641. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  17642. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  17643. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  17644. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  17645. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  17646. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17647. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17648. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17649. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  17650. {
  17651. isWebsocketSendable = OFF;
  17652. }
  17653. pthread_mutex_lock(&lock_send);
  17654. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17655. sprintf((char *)SendBuffer, "%s", str);
  17656. SendBufLen = strlen(str);
  17657. pthread_mutex_unlock(&lock_send);
  17658. lws_callback_on_writable(wsi_client);
  17659. //lws_service(context, 0);
  17660. //sleep(1);
  17661. }
  17662. void LWS_SendNow(char *str)
  17663. {
  17664. //=====================================================
  17665. // Check InternetConn 0: disconnected, 1: connected
  17666. //====================================================
  17667. if(GetOcppConnStatus() == 0)
  17668. {
  17669. DEBUG_INFO("offline now !!!\n");
  17670. return;
  17671. }
  17672. // Only disable isWebsocketSendable operation initiated by charger
  17673. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17674. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17675. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  17676. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17677. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17678. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  17679. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  17680. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17681. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17682. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17683. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  17684. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  17685. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  17686. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  17687. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  17688. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  17689. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  17690. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  17691. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  17692. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  17693. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  17694. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17695. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17696. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17697. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  17698. {
  17699. isWebsocketSendable = OFF;
  17700. }
  17701. pthread_mutex_lock(&lock_send);
  17702. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17703. sprintf((char *)SendBuffer, "%s", str);
  17704. SendBufLen = strlen(str);
  17705. pthread_mutex_unlock(&lock_send);
  17706. lws_callback_on_writable(wsi_client);
  17707. lws_service(context, 0);
  17708. //sleep(1);
  17709. }