MessageHandler.c 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *SecurityEventEnumTypeStr[] = {
  50. MACROSTR(FirmwareUpdated),
  51. MACROSTR(FailedToAuthenticateAtCsms),
  52. MACROSTR(CsmsFailedToAuthenticate),
  53. MACROSTR(SettingSystemTime),
  54. MACROSTR(StartupOfTheDevice),
  55. MACROSTR(ResetOrReboot),
  56. MACROSTR(SecurityLogWasCleared),
  57. MACROSTR(ReconfigurationOfSecurityParameters),
  58. MACROSTR(MemoryExhaustion),
  59. MACROSTR(InvalidMessages),
  60. MACROSTR(AttemptedReplayAttacks),
  61. MACROSTR(TamperDetectionActivated),
  62. MACROSTR(InvalidFirmwareSignature),
  63. MACROSTR(InvalidFirmwareSigningCertificate),
  64. MACROSTR(InvalidCsmsCertificate),
  65. MACROSTR(InvalidChargingStationCertificate),
  66. MACROSTR(InvalidTLSVersion),
  67. MACROSTR(InvalidTLSCipherSuite)
  68. };
  69. static char *CancelReservationStatusEnumTypeStr[] = {
  70. MACROSTR(Accepted),
  71. MACROSTR(Rejected)
  72. };
  73. static char *CertificateActionEnumTypeStr[] = {
  74. MACROSTR(Install),
  75. MACROSTR(Update)
  76. };
  77. static char *CertificateSignedStatusEnumTypeStr[] = {
  78. MACROSTR(Accepted),
  79. MACROSTR(Rejected)
  80. };
  81. static char *CertificateSigningUseEnumTypeStr[] = {
  82. MACROSTR(ChargingStationCertificate),
  83. MACROSTR(V2GCertificate)
  84. };
  85. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  86. MACROSTR(Accepted),
  87. MACROSTR(Rejected),
  88. MACROSTR(Scheduled)
  89. };
  90. #if 0
  91. static char *ChargingLimitSourceEnumTypeStr[] = {
  92. MACROSTR(EMS),
  93. MACROSTR(Other),
  94. MACROSTR(SO),
  95. MACROSTR(CSO)
  96. };
  97. #endif
  98. static char *ChargingProfileKindEnumTypeStr[] = {
  99. MACROSTR(Absolute),
  100. MACROSTR(Recurring),
  101. MACROSTR(Relative)
  102. };
  103. static char *ChargingProfilePurposeEnumTypeStr[] = {
  104. MACROSTR(ChargingStationExternalConstraints),
  105. MACROSTR(ChargingStationMaxProfile),
  106. MACROSTR(TxDefaultProfile),
  107. MACROSTR(TxProfile)
  108. };
  109. static char *ChargingProfileStatusEnumTypeStr[] = {
  110. MACROSTR(Accepted),
  111. MACROSTR(Rejected)
  112. };
  113. static char *ChargingRateUnitEnumTypeStr[] = {
  114. MACROSTR(W),
  115. MACROSTR(A)
  116. };
  117. static char *ChargingStateEnumTypeStr[] = {
  118. MACROSTR(Charging),
  119. MACROSTR(EVConnected),
  120. MACROSTR(SuspendedEV),
  121. MACROSTR(SuspendedEVSE),
  122. MACROSTR(Idle)
  123. };
  124. static char *ClearCacheStatusEnumTypeStr[] = {
  125. MACROSTR(Accepted),
  126. MACROSTR(Rejected)
  127. };
  128. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  129. MACROSTR(Accepted),
  130. MACROSTR(Unknown)
  131. };
  132. static char *ClearMessageStatusEnumTypeStr[] = {
  133. MACROSTR(Accepted),
  134. MACROSTR(Unknown)
  135. };
  136. static char *ClearMonitoringStatusEnumTypeStr[] = {
  137. MACROSTR(Accepted),
  138. MACROSTR(Rejected),
  139. MACROSTR(NotFound)
  140. };
  141. static char *ComponentCriterionEnumTypeStr[] = {
  142. MACROSTR(Active),
  143. MACROSTR(Available),
  144. MACROSTR(Enabled),
  145. MACROSTR(Problem)
  146. };
  147. #if 0
  148. static char *ConnectorEnumTypeStr[] = {
  149. MACROSTR(cCCS1),
  150. MACROSTR(cCCS2),
  151. MACROSTR(cG105),
  152. MACROSTR(cTesla),
  153. MACROSTR(cType1),
  154. MACROSTR(cType2),
  155. MACROSTR(s309-1P-16A),
  156. MACROSTR(s309-1P-32A),
  157. MACROSTR(s309-3P-16A),
  158. MACROSTR(s309-3P-32A),
  159. MACROSTR(sBS1361),
  160. MACROSTR(sCEE-7-7),
  161. MACROSTR(sType2),
  162. MACROSTR(sType3),
  163. MACROSTR(Other1PhMax16A),
  164. MACROSTR(Other1PhOver16A),
  165. MACROSTR(Other3Ph),
  166. MACROSTR(Pan),
  167. MACROSTR(wInductive),
  168. MACROSTR(wResonant),
  169. MACROSTR(Undetermined),
  170. MACROSTR(Unknown)
  171. };
  172. #endif
  173. static char *ConnectorStatusEnumTypeStr[] = {
  174. MACROSTR(Available),
  175. MACROSTR(Occupied),
  176. MACROSTR(Reserved),
  177. MACROSTR(Unavailable),
  178. MACROSTR(Faulted)
  179. };
  180. #if 0
  181. static char *CostKindEnumTypeStr[] = {
  182. MACROSTR(CarbonDioxideEmission),
  183. MACROSTR(RelativePricePercentage),
  184. MACROSTR(RenewableGenerationPercentage)
  185. };
  186. #endif
  187. static char *CustomerInformationStatusEnumTypeStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(Invalid)
  191. };
  192. static char *DataEnumTypeStr[] = {
  193. MACROSTR(string),
  194. MACROSTR(decimal),
  195. MACROSTR(integer),
  196. MACROSTR(dateTime),
  197. MACROSTR(boolean),
  198. MACROSTR(OptionList),
  199. MACROSTR(SequenceList),
  200. MACROSTR(MemberList)
  201. };
  202. static char *DataTransferStatusEnumTypeStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected),
  205. MACROSTR(UnknownMessageId),
  206. MACROSTR(UnknownVendorId)
  207. };
  208. static char *DeleteCertificateStatusEnumTypeStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotFound)
  212. };
  213. static char *DisplayMessageStatusEnumTypeStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(NotSupportedMessageFormat),
  216. MACROSTR(Rejected),
  217. MACROSTR(NotSupportedPriority),
  218. MACROSTR(NotSupportedState),
  219. MACROSTR(UnknownTransaction)
  220. };
  221. #if 0
  222. static char *EnergyTransferModeEnumTypeStr[] = {
  223. MACROSTR(DC),
  224. MACROSTR(AC_single_phase),
  225. MACROSTR(AC_two_phase),
  226. MACROSTR(AC_three_phase)
  227. };
  228. #endif
  229. static char *EventNotificationEnumTypeStr[] = {
  230. MACROSTR(HardWiredNotification),
  231. MACROSTR(HardWiredMonitor),
  232. MACROSTR(PreconfiguredMonitor),
  233. MACROSTR(CustomMonitor)
  234. };
  235. static char *EventTriggerEnumTypeStr[] = {
  236. MACROSTR(Alerting),
  237. MACROSTR(Delta),
  238. MACROSTR(Periodic)
  239. };
  240. static char *FirmwareStatusEnumTypeStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(DownloadScheduled),
  245. MACROSTR(DownloadPaused),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed),
  250. MACROSTR(InstallRebooting),
  251. MACROSTR(InstallScheduled),
  252. MACROSTR(InstallVerificationFailed),
  253. MACROSTR(InvalidSignature),
  254. MACROSTR(SignatureVerified)
  255. };
  256. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotSupported),
  260. MACROSTR(EmptyResultSet)
  261. };
  262. static char *GenericStatusEnumTypeStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected)
  265. };
  266. static char *GetCertificateIdUseEnumTypeStr[] = {
  267. MACROSTR(V2GRootCertificate),
  268. MACROSTR(MORootCertificate),
  269. MACROSTR(CSMSRootCertificate),
  270. MACROSTR(V2GCertificateChain),
  271. MACROSTR(ManufacturerRootCertificate)
  272. };
  273. static char *GetCertificateStatusEnumTypeStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Failed)
  276. };
  277. static char *GetChargingProfileStatusEnumTypeStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(NoProfiles)
  280. };
  281. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Unknown)
  284. };
  285. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(NotFound)
  288. };
  289. static char *GetVariableStatusEnumTypeStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected),
  292. MACROSTR(UnknownComponent),
  293. MACROSTR(UnknownVariable),
  294. MACROSTR(NotSupportedAttributeType)
  295. };
  296. static char *HashAlgorithmEnumTypeStr[] = {
  297. MACROSTR(SHA256),
  298. MACROSTR(SHA384),
  299. MACROSTR(SHA512)
  300. };
  301. static char *IdTokenEnumTypeStr[] = {
  302. MACROSTR(Central),
  303. MACROSTR(eMAID),
  304. MACROSTR(ISO14443),
  305. MACROSTR(ISO15693),
  306. MACROSTR(KeyCode),
  307. MACROSTR(Local),
  308. MACROSTR(MacAddress),
  309. MACROSTR(NoAuthorization),
  310. };
  311. static char *InstallCertificateUseEnumTypeStr[] = {
  312. MACROSTR(V2GRootCertificate),
  313. MACROSTR(MORootCertificate),
  314. MACROSTR(CSMSRootCertificate),
  315. MACROSTR(ManufacturerRootCertificate)
  316. };
  317. static char *InstallCertificateStatusEnumTypeStr[]={
  318. MACROSTR(Accepted),
  319. MACROSTR(Failed),
  320. MACROSTR(Rejected)
  321. };
  322. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  323. MACROSTR(Accepted),
  324. MACROSTR(Failed)
  325. };
  326. static char *LocationEnumTypeStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char *LogEnumTypeStr[] = {
  334. MACROSTR(DiagnosticsLog),
  335. MACROSTR(SecurityLog)
  336. };
  337. static char *LogStatusEnumTypeStr[] = {
  338. MACROSTR(Accepted),
  339. MACROSTR(Rejected),
  340. MACROSTR(AcceptedCanceled)
  341. };
  342. static char *MeasurandEnumTypeStr[] = {
  343. MACROSTR(Current.Export),
  344. MACROSTR(Current.Import),
  345. MACROSTR(Current.Offered),
  346. MACROSTR(Energy.Active.Export.Register),
  347. MACROSTR(Energy.Active.Import.Register),
  348. MACROSTR(Energy.Reactive.Export.Register),
  349. MACROSTR(Energy.Reactive.Import.Register),
  350. MACROSTR(Energy.Active.Export.Interval),
  351. MACROSTR(Energy.Active.Import.Interval),
  352. MACROSTR(Energy.Active.Net),
  353. MACROSTR(Energy.Reactive.Export.Interval),
  354. MACROSTR(Energy.Reactive.Import.Interval),
  355. MACROSTR(Energy.Reactive.Net),
  356. MACROSTR(Energy.Apparent.Net),
  357. MACROSTR(Energy.Apparent.Import),
  358. MACROSTR(Energy.Apparent.Export),
  359. MACROSTR(Frequency),
  360. MACROSTR(Power.Active.Export),
  361. MACROSTR(Power.Active.Import),
  362. MACROSTR(Power.Factor),
  363. MACROSTR(Power.Offered),
  364. MACROSTR(Power.Reactive.Export),
  365. MACROSTR(Power.Reactive.Import),
  366. MACROSTR(SoC),
  367. MACROSTR(Voltage)
  368. };
  369. static char *MessageFormatEnumTypeStr[] = {
  370. MACROSTR(ASCII),
  371. MACROSTR(HTML),
  372. MACROSTR(URI),
  373. MACROSTR(UTF8)
  374. };
  375. static char *MessagePriorityEnumTypeStr[] = {
  376. MACROSTR(AlwaysFront),
  377. MACROSTR(InFront),
  378. MACROSTR(NormalCycle)
  379. };
  380. static char *MessageStateEnumTypeStr[] = {
  381. MACROSTR(Charging),
  382. MACROSTR(Faulted),
  383. MACROSTR(Idle),
  384. MACROSTR(Unavailable)
  385. };
  386. static char *MessageTriggerEnumTypeStr[] = {
  387. MACROSTR(BootNotification),
  388. MACROSTR(LogStatusNotification),
  389. MACROSTR(FirmwareStatusNotification),
  390. MACROSTR(Heartbeat),
  391. MACROSTR(MeterValues),
  392. MACROSTR(SignChargingStationCertificate),
  393. MACROSTR(SignV2GCertificate),
  394. MACROSTR(StatusNotification),
  395. MACROSTR(TransactionEvent),
  396. MACROSTR(SignCombinedCertificate),
  397. MACROSTR(PublishFirmwareStatusNotification)
  398. };
  399. static char *MonitorEnumTypeStr[] = {
  400. MACROSTR(UpperThreshold),
  401. MACROSTR(LowerThreshold),
  402. MACROSTR(Delta),
  403. MACROSTR(Periodic),
  404. MACROSTR(PeriodicClockAligned)
  405. };
  406. static char *MonitoringBaseEnumTypeStr[] = {
  407. MACROSTR(All),
  408. MACROSTR(FactoryDefault),
  409. MACROSTR(HardWiredOnly)
  410. };
  411. static char *MonitoringCriterionEnumTypeStr[] = {
  412. MACROSTR(ThresholdMonitoring),
  413. MACROSTR(DeltaMonitoring),
  414. MACROSTR(PeriodicMonitoring)
  415. };
  416. static char *MutabilityEnumTypeStr[] = {
  417. MACROSTR(ReadOnly),
  418. MACROSTR(WriteOnly),
  419. MACROSTR(ReadWrite)
  420. };
  421. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected),
  424. MACROSTR(Processing)
  425. };
  426. static char *OCPPInterfaceEnumTypeStr[] = {
  427. MACROSTR(Wired0),
  428. MACROSTR(Wired1),
  429. MACROSTR(Wired2),
  430. MACROSTR(Wired3),
  431. MACROSTR(Wireless0),
  432. MACROSTR(Wireless1),
  433. MACROSTR(Wireless2),
  434. MACROSTR(Wireless3)
  435. };
  436. static char *OCPPTransportEnumTypeStr[] = {
  437. MACROSTR(JSON),
  438. MACROSTR(SOAP)
  439. };
  440. static char *OCPPVersionEnumTypeStr[] = {
  441. MACROSTR(OCPP12),
  442. MACROSTR(OCPP15),
  443. MACROSTR(OCPP16),
  444. MACROSTR(OCPP20)
  445. };
  446. static char *OperationalStatusEnumTypeStr[] = {
  447. MACROSTR(Inoperative),
  448. MACROSTR(Operative)
  449. };
  450. static char *PhaseEnumTypeStr[] = {
  451. MACROSTR(L1),
  452. MACROSTR(L2),
  453. MACROSTR(L3),
  454. MACROSTR(N),
  455. MACROSTR(L1-N),
  456. MACROSTR(L2-N),
  457. MACROSTR(L3-N),
  458. MACROSTR(L1-L2),
  459. MACROSTR(L2-L3),
  460. MACROSTR(L3-L1)
  461. };
  462. static char *PublishFirmwareStatusEnumTypeStr[] = {
  463. MACROSTR(Downloaded),
  464. MACROSTR(DownloadFailed),
  465. MACROSTR(Downloading),
  466. MACROSTR(DownloadScheduled),
  467. MACROSTR(DownloadPaused),
  468. MACROSTR(PublishFailed),
  469. MACROSTR(Published),
  470. MACROSTR(InvalidChecksum),
  471. MACROSTR(ChecksumVerified)
  472. };
  473. static char *ReadingContextEnumTypeStr[] = {
  474. MACROSTR(Interruption.Begin),
  475. MACROSTR(Interruption.End),
  476. MACROSTR(Other),
  477. MACROSTR(Sample.Clock),
  478. MACROSTR(Sample.Periodic),
  479. MACROSTR(Transaction.Begin),
  480. MACROSTR(Transaction.End),
  481. MACROSTR(Trigger)
  482. };
  483. #if 0
  484. static char *ReasonEnumTypeStr[] = {
  485. MACROSTR(DeAuthorized),
  486. MACROSTR(EmergencyStop),
  487. MACROSTR(EnergyLimitReached),
  488. MACROSTR(EVDisconnected),
  489. MACROSTR(GroundFault),
  490. MACROSTR(ImmediateReset),
  491. MACROSTR(Local),
  492. MACROSTR(LocalOutOfCredit),
  493. MACROSTR(MasterPass),
  494. MACROSTR(Other),
  495. MACROSTR(OvercurrentFault),
  496. MACROSTR(PowerLoss),
  497. MACROSTR(PowerQuality),
  498. MACROSTR(Reboot),
  499. MACROSTR(Remote),
  500. MACROSTR(SOCLimitReached),
  501. MACROSTR(StoppedByEV),
  502. MACROSTR(TimeLimitReached),
  503. MACROSTR(TimeLimitReached)
  504. };
  505. #endif
  506. static char *RecurrencyKindEnumTypeStr[] = {
  507. MACROSTR(Daily),
  508. MACROSTR(Weekly)
  509. };
  510. static char *RegistrationStatusEnumTypeStr[] = {
  511. MACROSTR(Accepted),
  512. MACROSTR(Pending),
  513. MACROSTR(Rejected)
  514. };
  515. static char *ReportBaseEnumTypeStr[] = {
  516. MACROSTR(ConfigurationInventory),
  517. MACROSTR(FullInventory),
  518. MACROSTR(SummaryInventory)
  519. };
  520. static char *RequestStartStopStatusEnumTypeStr[] = {
  521. MACROSTR(Accepted),
  522. MACROSTR(Rejected)
  523. };
  524. static char *ReservationUpdateStatusEnumTypeStr[] = {
  525. MACROSTR(Expired),
  526. MACROSTR(Removed)
  527. };
  528. static char *ReserveNowStatusEnumTypeStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Faulted),
  531. MACROSTR(Occupied),
  532. MACROSTR(Rejected),
  533. MACROSTR(Unavailable)
  534. };
  535. static char *ResetEnumTypeStr[] = {
  536. MACROSTR(Immediate),
  537. MACROSTR(OnIdle)
  538. };
  539. static char *ResetStatusEnumTypeStr[] = {
  540. MACROSTR(Accepted),
  541. MACROSTR(Rejected),
  542. MACROSTR(Scheduled)
  543. };
  544. static char *SetMonitoringStatusEnumTypeStr[] = {
  545. MACROSTR(Accepted),
  546. MACROSTR(UnknownComponent),
  547. MACROSTR(UnknownVariable),
  548. MACROSTR(UnsupportedMonitorType),
  549. MACROSTR(Rejected),
  550. MACROSTR(OutOfRange),
  551. MACROSTR(Duplicate)
  552. };
  553. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  554. MACROSTR(Accepted),
  555. MACROSTR(Rejected),
  556. MACROSTR(Failed)
  557. };
  558. static char *SetVariableStatusEnumTypeStr[] = {
  559. MACROSTR(Accepted),
  560. MACROSTR(Rejected),
  561. MACROSTR(InvalidValue),
  562. MACROSTR(UnknownComponent),
  563. MACROSTR(UnknownVariable),
  564. MACROSTR(NotSupportedAttributeType),
  565. MACROSTR(OutOfRange),
  566. MACROSTR(RebootRequired)
  567. };
  568. static char *TransactionEventEnumTypeStr[] = {
  569. MACROSTR(Ended),
  570. MACROSTR(Started),
  571. MACROSTR(Updated)
  572. };
  573. static char *TriggerMessageStatusEnumTypeStr[] = {
  574. MACROSTR(Accepted),
  575. MACROSTR(Rejected),
  576. MACROSTR(NotImplemented)
  577. };
  578. static char *TriggerReasonEnumTypeStr[] = {
  579. MACROSTR(Authorized),
  580. MACROSTR(CablePluggedIn),
  581. MACROSTR(ChargingRateChanged),
  582. MACROSTR(ChargingStateChanged),
  583. MACROSTR(Deauthorized),
  584. MACROSTR(EnergyLimitReached),
  585. MACROSTR(EVCommunicationLost),
  586. MACROSTR(EVConnectTimeout),
  587. MACROSTR(MeterValueClock),
  588. MACROSTR(MeterValuePeriodic),
  589. MACROSTR(TimeLimitReached),
  590. MACROSTR(Trigger),
  591. MACROSTR(UnlockCommand),
  592. MACROSTR(StopAuthorized),
  593. MACROSTR(EVDeparted),
  594. MACROSTR(EVDetected),
  595. MACROSTR(RemoteStop),
  596. MACROSTR(RemoteStart),
  597. MACROSTR(AbnormalCondition),
  598. MACROSTR(SignedDataReceived),
  599. MACROSTR(ResetCommand)
  600. };
  601. static char *UnlockStatusEnumTypeStr[] = {
  602. MACROSTR(Unlocked),
  603. MACROSTR(UnlockFailed),
  604. MACROSTR(OngoingAuthorizedTransaction),
  605. MACROSTR(UnknownConnector)
  606. };
  607. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  608. MACROSTR(DownloadOngoing),
  609. MACROSTR(NoFirmware),
  610. MACROSTR(Unpublished)
  611. };
  612. static char *UpdateEnumTypeStr[] = {
  613. MACROSTR(Differential),
  614. MACROSTR(Full)
  615. };
  616. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  617. MACROSTR(Accepted),
  618. MACROSTR(Rejected),
  619. MACROSTR(AcceptedCanceled),
  620. MACROSTR(InvalidCertificate),
  621. MACROSTR(RevokedCertificate)
  622. };
  623. static char *UpdateStatusEnumTypeStr[] = {
  624. MACROSTR(Accepted),
  625. MACROSTR(Failed),
  626. MACROSTR(VersionMismatch)
  627. };
  628. static char *UploadLogStatusEnumTypeStr[] = {
  629. MACROSTR(BadMessage),
  630. MACROSTR(Idle),
  631. MACROSTR(NotSupportedOperation),
  632. MACROSTR(PermissionDenied),
  633. MACROSTR(Uploaded),
  634. MACROSTR(UploadFailure),
  635. MACROSTR(Uploading),
  636. MACROSTR(AcceptedCanceled)
  637. };
  638. static char *VPNEnumTypeStr[] = {
  639. MACROSTR(IKEv2),
  640. MACROSTR(IPSec),
  641. MACROSTR(L2TP),
  642. MACROSTR(PPTP)
  643. };
  644. #if 0
  645. static char *ChargePointErrorCodeEnumTypeStr[] = {
  646. MACROSTR(ConnectorLockFailure),
  647. MACROSTR(EVCommunicationError),
  648. MACROSTR(GroundFailure),
  649. MACROSTR(HighTemperature),
  650. MACROSTR(InternalError),
  651. MACROSTR(LocalListConflict),
  652. MACROSTR(NoError),
  653. MACROSTR(OtherError),
  654. MACROSTR(OverCurrentFailure),
  655. MACROSTR(OverVoltage),
  656. MACROSTR(PowerMeterFailure),
  657. MACROSTR(PowerSwitchFailure),
  658. MACROSTR(ReaderFailure),
  659. MACROSTR(ResetFailure),
  660. MACROSTR(UnderVoltage),
  661. MACROSTR(WeakSignal)
  662. };
  663. #endif
  664. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  665. MACROSTR(Accepted),
  666. MACROSTR(Rejected)
  667. };
  668. static char *RemoteStartStopStatusEnumTypeStr[] = {
  669. MACROSTR(Accepted),
  670. MACROSTR(Rejected)
  671. };
  672. #if 0
  673. static char * StopTransactionReasonEnumTypeStr[] = {
  674. MACROSTR(EmergencyStop),
  675. MACROSTR(EVDisconnected),
  676. MACROSTR(HardReset),
  677. MACROSTR(Local),
  678. MACROSTR(Other),
  679. MACROSTR(PowerLoss),
  680. MACROSTR(Reboot),
  681. MACROSTR(Remote),
  682. MACROSTR(SoftReset),
  683. MACROSTR(UnlockCommand),
  684. MACROSTR(DeAuthorized)
  685. };
  686. #endif
  687. //ChargePointMaxProfile
  688. #define ChargingStationMaxProfile_JSON "/Storage/OCPP/ChargingStationMaxProfile_OCPP20.json"
  689. //TxDefaultProfile
  690. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  691. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  692. struct StatusCodeData *ShmStatusCodeData;
  693. struct PsuData *ShmPsuData ;
  694. struct OCPP20Data *ShmOCPP20Data;
  695. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  696. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  697. //===============================
  698. // Gun Total Numbers
  699. //===============================
  700. static ParsingRatedCur modelnameInfo = {0};
  701. static int gunTotalNumber = 0;
  702. static uint8_t gunType[4] = {0};
  703. //===============================
  704. // Local List Version
  705. //===============================
  706. static int localversion=0;
  707. //===============================
  708. // Variable Version
  709. //===============================
  710. static int variableVersion=8;
  711. //===============================
  712. // OCPP sign variable
  713. //===============================
  714. static int server_sign = FALSE;
  715. int server_pending = FALSE;
  716. static int BootNotificationInterval = 10;
  717. //===============================
  718. // OCPP auth variable
  719. //===============================
  720. static int authorizeRetryTimes = 0; //number of Retry times
  721. //===============================
  722. // OCPP other variables
  723. //===============================
  724. static int HeartBeatWaitTime = 10;
  725. static int FirstHeartBeat = 0;
  726. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  727. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  728. static char CurrentChargingProfileScheduleStr[30] = {0};
  729. static int isCancelUploadLog = FALSE;
  730. pthread_t th_GetLog;
  731. //========================================
  732. // OCPP status/previous related variables
  733. //========================================
  734. static int GunStatusInterval = 10;
  735. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  736. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  737. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  738. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  739. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  740. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  741. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  742. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  743. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  744. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  745. static int TransactionMessageAttemptsValue = 0;
  746. static int TransactionMessageRetryIntervalValue = 0;
  747. static struct AuthorizationData idTagQuery;
  748. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  749. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  750. //=============================================
  751. // OCPP HeartBeat Response Not Receive Counts
  752. //============================================
  753. static int HeartBeatWithNOResponse = 0;
  754. static int HeartBeatCountPerHour = 0;
  755. sqlite3 *db;
  756. int TransactionMessageAttemptsGet(void);
  757. int TransactionMessageRetryIntervalGet(void);
  758. int GetOcppConnStatus(void);
  759. void SetOcppConnStatus(uint8_t status);
  760. int setKeyValue(char *key, char *value);
  761. void OCPP_get_TableAuthlocalAllData(void);
  762. void processUnkownKey(void);
  763. struct InterLock
  764. {
  765. unsigned char isGetLogGoing:1;
  766. unsigned char isUpdateFirmwareGoing:1;
  767. }interLock;
  768. struct ClientTime
  769. {
  770. struct timespec Heartbeat;
  771. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  772. struct timespec StartTransaction;
  773. struct timespec StopTransaction;
  774. struct timespec MeterValues[CONNECTOR_QUANTITY];
  775. struct timespec SampledDataTxEnded[CONNECTOR_QUANTITY];
  776. struct timespec RemoteStartWait;
  777. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  778. }clientTime;
  779. typedef union
  780. {
  781. //Operations Initiated by Central System
  782. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  783. struct
  784. {
  785. //CsMsgValue[0]
  786. unsigned char StatusNotificationReq:1; //bit 0,
  787. unsigned char StatusNotificationConf:1; //bit 1,
  788. unsigned char TriggerMeterValueReq:1; //bit 2,
  789. unsigned char SampleMeterReq:1; //bit 3,
  790. unsigned char ClockAlignMeterReq:1; //bit 4,
  791. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  792. unsigned char isOnCharging:1; //bit 6,
  793. unsigned char TriggerTransactionEventReq:1; //bit 7
  794. }bits[CONNECTOR_QUANTITY];
  795. }CpinitiateMsg;
  796. CpinitiateMsg cpinitateMsg;
  797. //=========================================
  798. // Meter buffer process
  799. //=========================================
  800. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContextEnumType dataType)
  801. {
  802. uint32_t result = 0;
  803. char sqlCmd[8192];
  804. char zErrMsg[200];
  805. int rows, cols;
  806. char **resultData;
  807. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContextEnumType_Sample_Periodic?0:1));
  808. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  809. {
  810. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  811. }
  812. else
  813. {
  814. if(rows >= 1)
  815. {
  816. result = atoi(resultData[1]);
  817. }
  818. }
  819. return result;
  820. }
  821. int meterValueBufferClear(uint8_t gun_index)
  822. {
  823. int result = PASS;
  824. char sqlCmd[512];
  825. char *errMsg = 0;
  826. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  827. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  828. {
  829. DEBUG_INFO("SQL error: %s\n",errMsg);
  830. result = FAIL;
  831. }
  832. return result;
  833. }
  834. int meterValueBufferInsert(uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  835. {
  836. int result = PASS;
  837. char sqlCmd[8192];
  838. char *errMsg = 0;
  839. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", gun_index
  840. , transactionId
  841. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  842. , meterValue);
  843. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  844. {
  845. result = FAIL;
  846. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  847. }
  848. return result;
  849. }
  850. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  851. {
  852. int result = PASS;
  853. char sqlCmd[8192];
  854. char zErrMsg[200];
  855. int rows, cols;
  856. char **resultData;
  857. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  858. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  859. {
  860. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  861. result = FAIL;
  862. }
  863. else
  864. {
  865. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  866. {
  867. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  868. json_object_array_add(MeterValues, MeterValue);
  869. }
  870. }
  871. return result;
  872. }
  873. //=========================================
  874. // Certificate related routine
  875. //=========================================
  876. int certVerify(char *privateKey, char *cert)
  877. {
  878. int result = PASS;
  879. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  880. // Load certificate file
  881. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  882. {
  883. DEBUG_ERROR("Load certificate error!\n");
  884. result = FAIL;
  885. }
  886. // Load private key file
  887. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  888. {
  889. DEBUG_ERROR("Load private key error!\n");
  890. result = FAIL;
  891. }
  892. if(!SSL_CTX_check_private_key(ctx))
  893. {
  894. result = FAIL;
  895. }
  896. SSL_CTX_free(ctx);
  897. return result;
  898. }
  899. //==========================================
  900. // Parse certificate content
  901. //==========================================
  902. int parseCertInfo(char *certPath, int parseType, char *data)
  903. {
  904. int result = FAIL;
  905. int count = 0;
  906. int showupLine = 0;
  907. memset(data, 0, ARRAY_SIZE(data));
  908. if(access(certPath,F_OK) != -1)
  909. {
  910. char temp[512] = {0};
  911. char capturedData[256] = {0};
  912. char hashType[10] = "SHA256";
  913. FILE *fp;
  914. // Need to get hash type first
  915. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  916. fp = popen(temp, "r");
  917. if(fp)
  918. {
  919. while(fgets(temp, sizeof(temp), fp) != NULL)
  920. {
  921. if(strstr(temp, "Signature Algorithm:") != NULL)
  922. {
  923. result = PASS;
  924. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  925. sprintf((char*)hashType, "SHA256");
  926. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  927. sprintf((char*)hashType, "SHA384");
  928. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  929. sprintf((char*)hashType, "SHA512");
  930. else
  931. {
  932. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  933. result = FAIL;
  934. }
  935. break;
  936. }
  937. }
  938. }
  939. switch(parseType)
  940. {
  941. case CERT_PARSE_HashAlgorithm:
  942. sprintf((char*)data, hashType);
  943. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  944. break;
  945. case CERT_PARSE_SerialNumber:
  946. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  947. fp = popen(temp, "r");
  948. if(fp)
  949. {
  950. while(fgets(temp, sizeof(temp), fp) != NULL)
  951. {
  952. if(strstr(temp, "serial=") != NULL)
  953. {
  954. sscanf(temp, "%*[^=]=%s", capturedData);
  955. result = PASS;
  956. break;
  957. }
  958. }
  959. DEBUG_INFO("serialNumber: %s\n", capturedData);
  960. sprintf((char*)data, capturedData);
  961. }
  962. break;
  963. case CERT_PARSE_IssuerNameHash:
  964. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  965. fp = popen(temp, "r");
  966. if(fp)
  967. {
  968. while(fgets(temp, sizeof(temp), fp) != NULL)
  969. {
  970. if(strstr(temp, "SEQUENCE") != NULL)
  971. {
  972. count++;
  973. if(count==4)
  974. {
  975. sscanf(temp, "%[^:]", capturedData);
  976. showupLine = atoi(capturedData);
  977. break;
  978. }
  979. }
  980. }
  981. }
  982. if(showupLine > 0)
  983. {
  984. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  985. system(temp);
  986. }
  987. else
  988. {
  989. break;
  990. }
  991. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  992. {
  993. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  994. fp = popen(temp, "r");
  995. if(fp)
  996. {
  997. while(fgets(temp, sizeof(temp), fp) != NULL)
  998. {
  999. if(strstr(temp, "(stdin)=") != NULL)
  1000. {
  1001. sscanf(temp, "%*[^=]=%s", capturedData);
  1002. result = PASS;
  1003. break;
  1004. }
  1005. }
  1006. stringtrimspace(capturedData);
  1007. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1008. sprintf((char*)data, capturedData);
  1009. }
  1010. }
  1011. break;
  1012. case CERT_PARSE_IssuerKeyHash:
  1013. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1014. fp = popen(temp, "r");
  1015. if(fp)
  1016. {
  1017. while(fgets(temp, sizeof(temp), fp) != NULL)
  1018. {
  1019. if(strstr(temp, "BIT STRING") != NULL)
  1020. {
  1021. sscanf(temp, "%[^:]", capturedData);
  1022. showupLine = atoi(capturedData);
  1023. break;
  1024. }
  1025. }
  1026. }
  1027. if(showupLine > 0)
  1028. {
  1029. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1030. system(temp);
  1031. }
  1032. else
  1033. {
  1034. break;
  1035. }
  1036. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1037. {
  1038. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1039. fp = popen(temp, "r");
  1040. if(fp)
  1041. {
  1042. while(fgets(temp, sizeof(temp), fp) != NULL)
  1043. {
  1044. if(strstr(temp, "(stdin)=") != NULL)
  1045. {
  1046. sscanf(temp, "%*[^=]=%s", capturedData);
  1047. result = PASS;
  1048. break;
  1049. }
  1050. }
  1051. stringtrimspace(capturedData);
  1052. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1053. sprintf((char*)data, capturedData);
  1054. }
  1055. }
  1056. break;
  1057. case CERT_PARSE_OcspUrl:
  1058. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1059. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1060. fp = popen(temp, "r");
  1061. if(fp)
  1062. {
  1063. while(fgets(temp, sizeof(temp), fp) != NULL)
  1064. {
  1065. if(strstr(temp, "OCSP - URI:") != NULL)
  1066. {
  1067. //strcpy((char*)data, temp);
  1068. sscanf(temp, "%*[^:]:%s", capturedData);
  1069. sprintf((char*)data, capturedData);
  1070. DEBUG_INFO("OCSP_URI: %s\n", data);
  1071. result = PASS;
  1072. break;
  1073. }
  1074. }
  1075. }
  1076. break;
  1077. default:
  1078. DEBUG_INFO("Parse type is invalid.\n");
  1079. break;
  1080. }
  1081. pclose(fp);
  1082. }
  1083. return result;
  1084. }
  1085. //=========================================
  1086. // Get connector charging info
  1087. //=========================================
  1088. struct ChargingInfoData *getTargetChargingInfoData(uint8_t gun_index)
  1089. {
  1090. struct ChargingInfoData *targetChargingInfoData;
  1091. uint8_t tempIndex;
  1092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1093. {
  1094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1095. {
  1096. tempIndex = ((gun_index==2) ? 1: 0);
  1097. }
  1098. else
  1099. {
  1100. tempIndex = gun_index;
  1101. }
  1102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1103. {
  1104. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1105. {
  1106. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  1107. break;
  1108. }
  1109. }
  1110. }
  1111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1112. {
  1113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1114. {
  1115. tempIndex = ((gun_index==2) ? 1: 0);
  1116. }
  1117. else
  1118. {
  1119. tempIndex = gun_index;
  1120. }
  1121. for (int index = 0; index < CCS_QUANTITY; index++)
  1122. {
  1123. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1124. {
  1125. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  1126. break;
  1127. }
  1128. }
  1129. }
  1130. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1131. {
  1132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1133. {
  1134. tempIndex = ((gun_index==2) ? 1: 0);
  1135. }
  1136. else
  1137. {
  1138. tempIndex = gun_index;
  1139. }
  1140. for (int index = 0; index < GB_QUANTITY; index++)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1143. {
  1144. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. else if(gunType[gun_index] == GUN_TYPE_DO)
  1150. {
  1151. tempIndex = gun_index;
  1152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1153. {
  1154. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1155. {
  1156. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData;
  1157. break;
  1158. }
  1159. }
  1160. }
  1161. else
  1162. {
  1163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1164. {
  1165. tempIndex = 2;
  1166. }
  1167. else
  1168. {
  1169. tempIndex = gun_index;
  1170. }
  1171. for (int index = 0; index < AC_QUANTITY; index++)
  1172. {
  1173. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1174. {
  1175. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.AcChargingData[index];
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. return targetChargingInfoData;
  1181. }
  1182. //=========================================
  1183. // Save configuration
  1184. //=========================================
  1185. int runShellCmd(const char*cmd)
  1186. {
  1187. int result = FAIL;
  1188. char buf[256];
  1189. FILE *fp;
  1190. fp = popen(cmd, "r");
  1191. if(fp != NULL)
  1192. {
  1193. while(fgets(buf, sizeof(buf), fp) != NULL)
  1194. {
  1195. DEBUG_INFO("%s\n", buf);
  1196. }
  1197. result = PASS;
  1198. }
  1199. pclose(fp);
  1200. return result;
  1201. }
  1202. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1203. {
  1204. int result = PASS;
  1205. int fd,wrd;
  1206. unsigned int i,Chk;
  1207. unsigned char *ptr, *BufTmp;
  1208. int MtdBlockSize = 0x300000;
  1209. Chk=0;
  1210. ptr=(unsigned char *)UsrData;
  1211. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  1212. {
  1213. memset(BufTmp,0,MtdBlockSize);
  1214. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  1215. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  1216. Chk+=*(BufTmp+i);
  1217. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  1218. // Output configuration to file.
  1219. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  1220. if (fd < 0)
  1221. {
  1222. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  1223. free(BufTmp);
  1224. return 0;
  1225. }
  1226. wrd=write(fd, BufTmp, MtdBlockSize);
  1227. close(fd);
  1228. if(wrd<MtdBlockSize)
  1229. {
  1230. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  1231. free(BufTmp);
  1232. return 0;
  1233. }
  1234. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  1235. DEBUG_INFO("Erase /dev/mtd10.\n");
  1236. runShellCmd("flash_erase /dev/mtd10 0 0");
  1237. DEBUG_INFO("Write /dev/mtd10.\n");
  1238. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  1239. DEBUG_INFO("Erase /dev/mtd11.\n");
  1240. runShellCmd("flash_erase /dev/mtd11 0 0");
  1241. DEBUG_INFO("Write /dev/mtd11.\n");
  1242. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  1243. system("rm -f /mnt/EvseConfig.bin");
  1244. DEBUG_INFO("EvseConfig write to flash OK\n");
  1245. }
  1246. else
  1247. {
  1248. DEBUG_ERROR("alloc BlockSize NG\r\n");
  1249. result = FAIL;
  1250. }
  1251. if(BufTmp!=NULL)
  1252. free(BufTmp);
  1253. return result;
  1254. }
  1255. //=========================================
  1256. // Date time related function
  1257. //=========================================
  1258. void getNowDatetime(uint8_t *data)
  1259. {
  1260. time_t t = time(NULL);
  1261. struct tm tm = *localtime(&t);
  1262. 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);
  1263. }
  1264. //=========================================
  1265. // Sqlite3 related function
  1266. //=========================================
  1267. int DB_Initial()
  1268. {
  1269. int result = PASS;
  1270. char* errMsg = NULL;
  1271. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  1272. "idToken text UNIQUE,"
  1273. "type text,"
  1274. "status text,"
  1275. "cacheExpiryDateTime text,"
  1276. "chargingPriority integer,"
  1277. "language1 text,"
  1278. "evseId text,"
  1279. "language2 text,"
  1280. "groupIdToken_idToken text,"
  1281. "groupIdToken_type text,"
  1282. "personalMessage text);";
  1283. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  1284. "idToken text UNIQUE,"
  1285. "type text,"
  1286. "status text,"
  1287. "cacheExpiryDateTime text,"
  1288. "chargingPriority integer,"
  1289. "language1 text,"
  1290. "evseId text,"
  1291. "language2 text,"
  1292. "groupIdToken_idToken text,"
  1293. "groupIdToken_type text,"
  1294. "personalMessage text,"
  1295. "version text);";
  1296. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  1297. "componentName text NOT NULL ,"
  1298. "componentInstance text, "
  1299. "variableName text NOT NULL, "
  1300. "variableInstance text, "
  1301. "variableCharacteristicsDataType integer, "
  1302. "variableCharacteristicsUnit text, "
  1303. "variableCharacteristicsMaxLimit real,"
  1304. "variableAttributesType text, "
  1305. "variableAttributesTypeMutability text, "
  1306. "variableAttributesTypeValue text, "
  1307. "variableCharacteristicsMinLimit real,"
  1308. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  1309. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  1310. "type text);";
  1311. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  1312. "type text);";
  1313. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  1314. "slot integer UNIQUE, connectionData text);";
  1315. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  1316. "occurDatetime text,"
  1317. "message_type text,"
  1318. "message_content text)";
  1319. char *sqlMeterValueBuffer = "create table if not exists meterValuesBuffer( idx integer primary key,"
  1320. "occurDatetime text,"
  1321. "gun_index text,"
  1322. "transactionId text,"
  1323. "ReadingContext text,"
  1324. "meterValue text);";
  1325. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  1326. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  1327. {
  1328. result = FAIL;
  1329. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  1330. sqlite3_close(db);
  1331. }
  1332. else
  1333. {
  1334. DEBUG_INFO( "OCPP local database open successfully.\n");
  1335. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  1336. {
  1337. result = FAIL;
  1338. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  1339. }
  1340. else
  1341. {
  1342. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  1343. }
  1344. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  1345. {
  1346. result = FAIL;
  1347. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  1348. }
  1349. else
  1350. {
  1351. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  1352. }
  1353. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  1354. {
  1355. result = FAIL;
  1356. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  1357. }
  1358. else
  1359. {
  1360. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  1361. }
  1362. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  1363. {
  1364. result = FAIL;
  1365. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  1366. }
  1367. else
  1368. {
  1369. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  1370. }
  1371. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  1372. {
  1373. result = FAIL;
  1374. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  1375. }
  1376. else
  1377. {
  1378. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  1379. }
  1380. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  1381. {
  1382. result = FAIL;
  1383. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  1384. }
  1385. else
  1386. {
  1387. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  1388. }
  1389. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  1390. {
  1391. result = FAIL;
  1392. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  1393. }
  1394. else
  1395. {
  1396. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1397. }
  1398. // Create meter values buffer table
  1399. if(sqlite3_exec(db, sqlMeterValueBuffer, 0, 0, &errMsg) != SQLITE_OK)
  1400. {
  1401. DEBUG_INFO( "Create Table meterValuesBuffer error %s\n",errMsg);
  1402. return 0;
  1403. }
  1404. else
  1405. {
  1406. DEBUG_INFO( "Opened meterValuesBuffer table successfully\n");
  1407. }
  1408. //sqlite3_close(db);
  1409. }
  1410. return result;
  1411. }
  1412. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1413. {
  1414. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1415. return 0;
  1416. }
  1417. void DB_getListVerion()
  1418. {
  1419. char sql[256];
  1420. char* errMsg = NULL;
  1421. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1422. /* Execute SQL statement */
  1423. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1424. {
  1425. DEBUG_INFO("SQL error: %s", errMsg);
  1426. }
  1427. }
  1428. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1429. {
  1430. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1431. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1432. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1433. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1434. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1435. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1436. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1437. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1438. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1439. return 0;
  1440. }
  1441. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1442. {
  1443. char sql[256];
  1444. char* errMsg = NULL;
  1445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1446. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1447. if(isQueryFromCache)
  1448. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1449. else
  1450. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1451. /* Execute SQL statement */
  1452. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1453. {
  1454. DEBUG_INFO("SQL error: %s", errMsg);
  1455. }
  1456. }
  1457. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1458. {
  1459. for (int i = 0; i < columnCount; i++)
  1460. {
  1461. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1462. }
  1463. return 0;
  1464. }
  1465. void DB_get_TableAuthlocalAllData(void)
  1466. {
  1467. char sql[256];
  1468. char* errMsg = NULL;
  1469. sprintf(sql,"select * from ocpp20_auth_local;");
  1470. /* Execute SQL statement */
  1471. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1472. {
  1473. DEBUG_INFO("SQL error: %s", errMsg);
  1474. }
  1475. }
  1476. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1477. {
  1478. for(int i = 0; i<columnCount; i++)
  1479. {
  1480. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1481. }
  1482. return 0;
  1483. }
  1484. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1485. {
  1486. int result = PASS;
  1487. char sql[512];
  1488. char* errMsg = NULL;
  1489. 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;",
  1490. data->idToken.idToken,
  1491. data->idToken.type,
  1492. data->idTokenInfo.status,
  1493. data->idTokenInfo.cacheExpiryDateTime,
  1494. data->idTokenInfo.chargingPriority,
  1495. data->idTokenInfo.language1,
  1496. data->idTokenInfo.language2,
  1497. data->idTokenInfo.groupIdToken.idToken,
  1498. data->idTokenInfo.groupIdToken.type,
  1499. listVersion);
  1500. //* Execute SQL statement */
  1501. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1502. {
  1503. DEBUG_INFO("SQL error: %s\n", errMsg);
  1504. result = FAIL;
  1505. }
  1506. else
  1507. {
  1508. memset(sql, 0, ARRAY_SIZE(sql));
  1509. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1510. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1511. {
  1512. DEBUG_INFO("SQL error: %s\n", errMsg);
  1513. result = FAIL;
  1514. }
  1515. }
  1516. return result;
  1517. }
  1518. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1519. {
  1520. int result = PASS;
  1521. char sql[512];
  1522. char* errMsg = NULL;
  1523. 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;",
  1524. idToken->idToken,
  1525. idToken->type,
  1526. idTokenInfo->status,
  1527. idTokenInfo->cacheExpiryDateTime,
  1528. idTokenInfo->chargingPriority,
  1529. idTokenInfo->language1,
  1530. idTokenInfo->language2,
  1531. idTokenInfo->groupIdToken.idToken,
  1532. idTokenInfo->groupIdToken.type);
  1533. //* Execute SQL statement */
  1534. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1535. {
  1536. DEBUG_INFO("SQL error: %s\n", errMsg);
  1537. result = FAIL;
  1538. }
  1539. return result;
  1540. }
  1541. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1542. {
  1543. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1544. // printf("localversion=%d\n", localversion);
  1545. return 0;
  1546. }
  1547. void DB_deleteIdTag(char idTag[])
  1548. {
  1549. char sql[512];
  1550. char* errMsg = NULL;
  1551. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1552. //* Execute SQL statement */
  1553. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1554. {
  1555. DEBUG_INFO("SQL error: %s", errMsg);
  1556. }
  1557. }
  1558. int DB_cleanLocalList()
  1559. {
  1560. int result = PASS;
  1561. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1562. char *errMsg = 0;
  1563. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1564. {
  1565. DEBUG_INFO("%s\n", errMsg);
  1566. result = FAIL;
  1567. }
  1568. return result;
  1569. }
  1570. int DB_cleanLocalCache()
  1571. {
  1572. int result = PASS;
  1573. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1574. char *errMsg = 0;
  1575. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1576. {
  1577. DEBUG_INFO("%s\n", errMsg);
  1578. result = FAIL;
  1579. }
  1580. return result;
  1581. }
  1582. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1583. {
  1584. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1585. return 0;
  1586. }
  1587. void DB_getBooType()
  1588. {
  1589. char sql[256];
  1590. char* errMsg = NULL;
  1591. sprintf(sql,"select * from ocpp20_boot_type;");
  1592. /* Execute SQL statement */
  1593. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1594. {
  1595. DEBUG_INFO("SQL error: %s\n", errMsg);
  1596. }
  1597. }
  1598. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1599. {
  1600. for(int i = 0; i<columnCount; i++)
  1601. {
  1602. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1603. }
  1604. return 0;
  1605. }
  1606. int DB_updateBootType(BootReasonEnumType reason)
  1607. {
  1608. int result = PASS;
  1609. char sql[512];
  1610. char* errMsg = NULL;
  1611. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1612. //* Execute SQL statement */
  1613. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1614. {
  1615. DEBUG_INFO("SQL error: %s\n", errMsg);
  1616. result = FAIL;
  1617. }
  1618. return result;
  1619. }
  1620. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1621. {
  1622. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1623. return 0;
  1624. }
  1625. void DB_getSecurityEventType()
  1626. {
  1627. char sql[256];
  1628. char* errMsg = NULL;
  1629. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1630. /* Execute SQL statement */
  1631. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1632. {
  1633. DEBUG_INFO("SQL error: %s\n", errMsg);
  1634. }
  1635. }
  1636. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1637. {
  1638. for(int i = 0; i<columnCount; i++)
  1639. {
  1640. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1641. }
  1642. return 0;
  1643. }
  1644. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1645. {
  1646. int result = PASS;
  1647. char sql[512];
  1648. char* errMsg = NULL;
  1649. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1650. //* Execute SQL statement */
  1651. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1652. {
  1653. DEBUG_INFO("SQL error: %s\n", errMsg);
  1654. result = FAIL;
  1655. }
  1656. return result;
  1657. }
  1658. int DB_variableClear()
  1659. {
  1660. int result = PASS;
  1661. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1662. char *errMsg = 0;
  1663. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1664. {
  1665. DEBUG_INFO("%s\n", errMsg);
  1666. result = FAIL;
  1667. }
  1668. return result;
  1669. }
  1670. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1671. {
  1672. for(int i = 0; i<columnCount; i++)
  1673. {
  1674. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1675. }
  1676. return 0;
  1677. }
  1678. int DB_variableSaveToDb(struct ReportDataType *variable)
  1679. {
  1680. int result = FAIL;
  1681. char sql[4096];
  1682. char* errMsg = NULL;
  1683. 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;",
  1684. variable->component.name,
  1685. variable->component.instance,
  1686. variable->variable.name,
  1687. variable->variable.instance,
  1688. variable->variableCharacteristics.dataType,
  1689. variable->variableCharacteristics.unit,
  1690. variable->variableCharacteristics.maxLimit,
  1691. variable->variableAttribute[0].type,
  1692. variable->variableAttribute[0].mutability,
  1693. variable->variableAttribute[0].value,
  1694. variable->variableCharacteristics.minLimit);
  1695. //* Execute SQL statement */
  1696. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1697. {
  1698. DEBUG_INFO("SQL error: %s\n", errMsg);
  1699. result = FAIL;
  1700. }
  1701. return result;
  1702. }
  1703. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1704. {
  1705. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1706. if(atoi(columnValue[0]) == 0)
  1707. {
  1708. DB_updateBootType(BootReasonEnumType_PowerUp);
  1709. // Create variable table content
  1710. /* AlignedDataCtrlr Required item */
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "false");
  1717. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "true");
  1724. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1728. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1733. "Energy.Active.Import.Register,"
  1734. "Energy.Active.Import.Interval,"
  1735. "Power.Active.Import,"
  1736. "Voltage,"
  1737. "SoC,"
  1738. "Current.Offered,"
  1739. "Power.Offered");
  1740. else
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1742. "Energy.Active.Import.Register,"
  1743. "Energy.Active.Import.Interval,"
  1744. "Power.Active.Import,"
  1745. "Voltage,"
  1746. "Current.Offered");
  1747. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1752. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1756. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "true");
  1763. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  1770. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1774. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1779. "Energy.Active.Import.Register,"
  1780. "Energy.Active.Import.Interval,"
  1781. "Power.Active.Import,"
  1782. "Voltage,"
  1783. "SoC");
  1784. else
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1786. "Energy.Active.Import.Register,"
  1787. "Energy.Active.Import.Interval,"
  1788. "Power.Active.Import,"
  1789. "Voltage");
  1790. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1798. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1799. /* AuthCtrlrVariable Required item */
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
  1806. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1813. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "false");
  1820. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "false");
  1827. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true");
  1834. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true");
  1841. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1845. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1849. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1850. /* AuthCacheCtrlr Variable Required item*/
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "false");
  1857. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "true");
  1864. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "true");
  1872. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1876. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "true");
  1880. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1887. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1888. /* ClockCtrlr Variable Required item */
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1894. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1895. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1902. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1910. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1917. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1924. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1932. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1939. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1946. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1947. /* ChargingStation Required item */
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "false");
  1954. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1961. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1968. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  1975. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  1982. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  1989. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  1996. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  1997. /* Connector Required item */
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "false");
  2004. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  2011. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  2018. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  2019. /* CustomizationCtrlr Required item */
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "false");
  2026. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  2027. /* DeviceDataCtrlr Required item */
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  2035. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2043. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  2051. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2059. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2062. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  2067. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2070. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  2075. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2083. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2091. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  2092. /* DisplayMessageCtrlr Required item */
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "false");
  2099. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "false");
  2106. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2110. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  2114. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  2121. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  2128. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  2129. /* EVSE Required item */
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "false");
  2136. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  2143. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  2150. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  2157. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  2158. /* LocalAuthListCtrlr Required item */
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true");
  2165. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2169. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  2173. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "true");
  2180. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  2188. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  2196. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2200. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  2204. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  2205. /* MonitoringCtrlr Required item */
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "false");
  2212. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "false");
  2219. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2227. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2235. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2243. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2251. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  2258. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  2259. /* OCPPCommCtrlr Required item */
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  2266. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  2275. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  2282. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  2286. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  2291. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  2298. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  2305. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  2313. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "false");
  2320. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  2329. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  2338. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "true");
  2345. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  2349. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  2354. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  2361. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  2368. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  2375. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "false");
  2382. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  2386. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  2391. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.unit, "Seconds");
  2395. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.minLimit = 5;
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value, "30");
  2400. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval]);
  2401. /* ReservationCtrlr Required item */
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "true");
  2408. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "true");
  2415. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "false");
  2422. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2423. /* SampledDataCtrlr Required item */
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "true");
  2430. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "true");
  2437. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  2444. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2448. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2453. "Energy.Active.Import.Register,"
  2454. "Energy.Active.Import.Interval,"
  2455. "Power.Active.Import,"
  2456. "Voltage,"
  2457. "SoC");
  2458. else
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2460. "Energy.Active.Import.Register,"
  2461. "Energy.Active.Import.Interval,"
  2462. "Power.Active.Import,"
  2463. "Voltage");
  2464. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2472. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2476. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2480. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2484. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2489. "Energy.Active.Import.Register,"
  2490. "Energy.Active.Import.Interval,"
  2491. "Power.Active.Import,"
  2492. "Voltage,"
  2493. "SoC,"
  2494. "Current.Offered,"
  2495. "Power.Offered");
  2496. else
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2498. "Energy.Active.Import.Register,"
  2499. "Energy.Active.Import.Interval,"
  2500. "Power.Active.Import,"
  2501. "Voltage,"
  2502. "Current.Offered");
  2503. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2508. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2512. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2513. /* SecurityCtrlr Required item */
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2517. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2521. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2525. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2529. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2536. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2540. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2544. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2551. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "false");
  2558. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2562. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2566. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2567. /* SmartChargingCtrlr Required item */
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "true");
  2574. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "true");
  2581. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "false");
  2588. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2595. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2602. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2609. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "false");
  2616. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "false");
  2623. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "false");
  2630. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2634. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2638. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2645. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2646. /* TariffCostCtrlr Required item */
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "false");
  2654. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "false");
  2662. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2666. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2670. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "false");
  2678. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "false");
  2686. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2690. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2694. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2698. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2702. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2703. /* TxCtrlr Required item */
  2704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2710. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2718. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "true");
  2725. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2732. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2739. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2746. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2754. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "false");
  2761. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2762. }
  2763. else
  2764. {
  2765. // Variable name init
  2766. /* AlignedDataCtrlr Required item */
  2767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2783. /* AuthCtrlrVariable Required item */
  2784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2798. /* AuthCacheCtrlr Variable Required item */
  2799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2809. /* ClockCtrlr Variable Required item */
  2810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2828. /* ChargingStation Required item */
  2829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2843. /* Connector Required item */
  2844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2850. /* CustomizationCtrlr Required item */
  2851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2853. /* DeviceDataCtrlr Required item */
  2854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2876. /* DisplayMessageCtrlr Required item */
  2877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2887. /* EVSE Required item */
  2888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2896. /* LocalAuthListCtrlr Required item */
  2897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2911. /* MonitoringCtrlr Required item */
  2912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2930. /* OCPPCommCtrlr Required item */
  2931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  2969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  2970. /* ReservationCtrlr Required item */
  2971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2977. /* SampledDataCtrlr Required item */
  2978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2994. /* SecurityCtrlr Required item */
  2995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  3000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  3001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  3002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  3003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  3004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  3005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  3006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  3007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  3008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  3009. /* SmartChargingCtrlr Required item */
  3010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  3011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  3012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  3013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  3014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  3015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  3016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  3017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  3018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  3019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  3020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  3021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  3022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  3023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  3024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  3025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  3026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  3027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  3028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  3029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  3030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  3031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  3032. /* TariffCostCtrlr Required item */
  3033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  3034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  3035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  3036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  3037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  3038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  3039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  3040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  3041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  3042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  3043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  3044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  3045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  3046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  3047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  3048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  3049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  3050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  3051. /* TxCtrlr Required item */
  3052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  3054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  3055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  3056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  3057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  3058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  3060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  3061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  3062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  3063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  3064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  3065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  3066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  3067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  3068. }
  3069. return 0;
  3070. }
  3071. void DB_variableIsCreate()
  3072. {
  3073. char sql[512];
  3074. char* errMsg = NULL;
  3075. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  3076. /* Execute SQL statement */
  3077. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  3078. {
  3079. DEBUG_INFO("SQL error: %s\n", errMsg);
  3080. }
  3081. }
  3082. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3083. {
  3084. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  3085. {
  3086. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  3087. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  3088. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  3089. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  3090. {
  3091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  3092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  3093. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  3094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  3095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  3096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  3097. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  3098. }
  3099. }
  3100. return 0;
  3101. }
  3102. void DB_variableLoadFromDb()
  3103. {
  3104. char sql[512];
  3105. char* errMsg = NULL;
  3106. sprintf(sql,"select * from ocpp20_variable order by idx;");
  3107. /* Execute SQL statement */
  3108. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3109. {
  3110. DEBUG_INFO("SQL error: %s\n", errMsg);
  3111. }
  3112. }
  3113. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3114. {
  3115. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  3116. if(columnCount > 0)
  3117. {
  3118. for(int idx=0;idx<columnCount;idx++)
  3119. {
  3120. json_object *SetNetworkProfile;
  3121. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  3122. if(!is_error(SetNetworkProfile))
  3123. {
  3124. // Required data
  3125. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  3126. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  3127. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  3128. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  3129. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  3130. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  3131. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  3132. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  3133. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  3134. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  3135. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  3136. {
  3137. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  3138. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  3139. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  3140. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  3141. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  3142. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  3143. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  3144. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  3145. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  3146. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  3147. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  3148. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  3149. }
  3150. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  3151. {
  3152. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  3153. {
  3154. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  3155. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  3156. }
  3157. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  3158. {
  3159. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  3160. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  3161. }
  3162. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  3163. {
  3164. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  3165. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  3166. }
  3167. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  3168. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  3169. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  3170. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  3171. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  3172. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  3173. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  3174. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  3175. }
  3176. }
  3177. json_object_put(SetNetworkProfile);
  3178. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  3179. }
  3180. }
  3181. return 0;
  3182. }
  3183. void DB_getNetworkProfileFromDb()
  3184. {
  3185. char sql[512];
  3186. char* errMsg = NULL;
  3187. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  3188. /* Execute SQL statement */
  3189. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3190. {
  3191. DEBUG_INFO("SQL error: %s\n", errMsg);
  3192. }
  3193. }
  3194. int DB_addNetworkProfile(int slot, char *data)
  3195. {
  3196. int result = PASS;
  3197. char sql[512];
  3198. char* errMsg = NULL;
  3199. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  3200. slot,
  3201. data);
  3202. //* Execute SQL statement */
  3203. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  3204. {
  3205. DEBUG_INFO("SQL error: %s\n", errMsg);
  3206. result = FAIL;
  3207. }
  3208. return result;
  3209. }
  3210. int DB_deleteNetworkProfile(int slot)
  3211. {
  3212. int result = PASS;
  3213. char sql[512];
  3214. char* errMsg = NULL;
  3215. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  3216. //* Execute SQL statement */
  3217. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3218. {
  3219. DEBUG_INFO("SQL error: %s", errMsg);
  3220. result = FAIL;
  3221. }
  3222. return result;
  3223. }
  3224. int isNumber(uint8_t *string, uint8_t isFloat)
  3225. {
  3226. int result = NO;
  3227. int cntDecimal = 0;
  3228. float i;
  3229. for(int idx=0; idx<strlen((char*)string); idx++)
  3230. {
  3231. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  3232. {
  3233. return result;
  3234. }
  3235. else if(string[idx] == '.')
  3236. cntDecimal++;
  3237. if(cntDecimal>1)
  3238. return result;
  3239. }
  3240. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  3241. {
  3242. //DEBUG_INFO("%s is not pure integer!!\n", string);
  3243. }
  3244. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  3245. {
  3246. //DEBUG_INFO("%s is not float format!!\n", string);
  3247. }
  3248. else if(sscanf((char*)string, "%f", &i) != 0)
  3249. {
  3250. result = YES;
  3251. }
  3252. return result;
  3253. }
  3254. int isMatchTimeFormat(uint8_t *time)
  3255. {
  3256. int result = NO;
  3257. struct ParsingResult
  3258. {
  3259. int result;
  3260. int scanedElement;
  3261. int year;
  3262. int month;
  3263. int mday;
  3264. int hour;
  3265. int min;
  3266. int sec;
  3267. int tz_hour;
  3268. int tz_min;
  3269. float minSec;
  3270. }parsingResult;
  3271. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3272. if(strstr((char*)time, ".") != NULL)
  3273. {
  3274. // Original data with mini second
  3275. if(strstr((char*)time, "Z") != NULL)
  3276. {
  3277. // Original data with Z
  3278. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  3279. &parsingResult.year,
  3280. &parsingResult.month,
  3281. &parsingResult.mday,
  3282. &parsingResult.hour,
  3283. &parsingResult.min,
  3284. &parsingResult.sec,
  3285. &parsingResult.minSec);
  3286. }
  3287. else
  3288. {
  3289. // Original data without Z
  3290. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3291. &parsingResult.year,
  3292. &parsingResult.month,
  3293. &parsingResult.mday,
  3294. &parsingResult.hour,
  3295. &parsingResult.min,
  3296. &parsingResult.sec,
  3297. &parsingResult.minSec,
  3298. &parsingResult.tz_hour,
  3299. &parsingResult.tz_min);
  3300. }
  3301. }
  3302. else
  3303. {
  3304. // Original data without mini second
  3305. if(strstr((char*)time, "Z") != NULL)
  3306. {
  3307. // Original data with Z
  3308. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  3309. &parsingResult.year,
  3310. &parsingResult.month,
  3311. &parsingResult.mday,
  3312. &parsingResult.hour,
  3313. &parsingResult.min,
  3314. &parsingResult.sec);
  3315. }
  3316. else
  3317. {
  3318. // Original data without Z
  3319. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  3320. &parsingResult.year,
  3321. &parsingResult.month,
  3322. &parsingResult.mday,
  3323. &parsingResult.hour,
  3324. &parsingResult.min,
  3325. &parsingResult.sec,
  3326. &parsingResult.tz_hour,
  3327. &parsingResult.tz_min);
  3328. }
  3329. }
  3330. if(parsingResult.scanedElement >= 6)
  3331. {
  3332. result = YES;
  3333. }
  3334. return result;
  3335. }
  3336. int getCurrentYear()
  3337. {
  3338. int result = 0;
  3339. time_t CurrentTime;
  3340. struct tm *tm;
  3341. CurrentTime = time(NULL);
  3342. tm=localtime(&CurrentTime);
  3343. result = (tm->tm_year + 1900);
  3344. return result;
  3345. }
  3346. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  3347. {
  3348. int result = PASS;
  3349. char* errMsg = NULL;
  3350. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  3351. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  3352. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3353. {
  3354. result = FAIL;
  3355. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  3356. }
  3357. 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));
  3358. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3359. {
  3360. result = FAIL;
  3361. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  3362. }
  3363. return result;
  3364. }
  3365. //==========================================
  3366. // Check time passed since today
  3367. //==========================================
  3368. long long DiffTimebWithNow(struct timeb ST)
  3369. {
  3370. //return milli-second
  3371. struct timeb ET;
  3372. long long StartTime,StopTime;
  3373. ftime(&ET);
  3374. StartTime=(long long)ST.time;
  3375. StopTime=(long long)ET.time;
  3376. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  3377. }
  3378. int getTimePassSinceToday(uint8_t gun_index)
  3379. {
  3380. int result = -1;
  3381. static time_t lastTime[4];
  3382. time_t t;
  3383. struct tm *tmStartToday;
  3384. struct timeb tbStartToday;
  3385. t=time(NULL);
  3386. if(difftime(t, lastTime[gun_index])>0)
  3387. {
  3388. tmStartToday=localtime(&t);
  3389. tmStartToday->tm_hour = 0;
  3390. tmStartToday->tm_min = 0;
  3391. tmStartToday->tm_sec = 0;
  3392. tbStartToday.time = mktime(tmStartToday);
  3393. tbStartToday.millitm = 0;
  3394. result = DiffTimebWithNow(tbStartToday)/1000;
  3395. lastTime[gun_index] = t;
  3396. }
  3397. return result;
  3398. }
  3399. int syncDateTimeRTC(uint8_t *data)
  3400. {
  3401. struct ParsingResult
  3402. {
  3403. int result;
  3404. int scanedElement;
  3405. int year;
  3406. int month;
  3407. int mday;
  3408. int hour;
  3409. int min;
  3410. int sec;
  3411. int tz_hour;
  3412. int tz_min;
  3413. float minSec;
  3414. }result;
  3415. struct tm tmOrg;
  3416. struct tm *tmTarget;
  3417. struct timeb tbTarget;
  3418. char buf[128];
  3419. memset(&result, 0x00, sizeof(struct ParsingResult));
  3420. result.result = PASS;
  3421. if(strstr((char*)data, ".") != NULL)
  3422. {
  3423. // Original data with mini second
  3424. if(strstr((char*)data, "Z") != NULL)
  3425. {
  3426. // Original data with Z
  3427. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3428. &result.year,
  3429. &result.month,
  3430. &result.mday,
  3431. &result.hour,
  3432. &result.min,
  3433. &result.sec,
  3434. &result.minSec);
  3435. }
  3436. else
  3437. {
  3438. // Original data without Z
  3439. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3440. &result.year,
  3441. &result.month,
  3442. &result.mday,
  3443. &result.hour,
  3444. &result.min,
  3445. &result.sec,
  3446. &result.minSec,
  3447. &result.tz_hour,
  3448. &result.tz_min);
  3449. }
  3450. }
  3451. else
  3452. {
  3453. // Original data without mini second
  3454. if(strstr((char*)data, "Z") != NULL)
  3455. {
  3456. // Original data with Z
  3457. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3458. &result.year,
  3459. &result.month,
  3460. &result.mday,
  3461. &result.hour,
  3462. &result.min,
  3463. &result.sec);
  3464. }
  3465. else
  3466. {
  3467. // Original data without Z
  3468. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3469. &result.year,
  3470. &result.month,
  3471. &result.mday,
  3472. &result.hour,
  3473. &result.min,
  3474. &result.sec,
  3475. &result.tz_hour,
  3476. &result.tz_min);
  3477. }
  3478. }
  3479. tmOrg.tm_year = result.year - 1900;
  3480. tmOrg.tm_mon = result.month - 1;
  3481. tmOrg.tm_mday = result.mday;
  3482. tmOrg.tm_hour = result.hour;
  3483. tmOrg.tm_min = result.min;
  3484. tmOrg.tm_sec = result.sec;
  3485. tmOrg.tm_gmtoff = 0;
  3486. tbTarget.time = mktime(&tmOrg);
  3487. tbTarget.timezone = 0;
  3488. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3489. tmTarget = gmtime(&tbTarget.time);
  3490. 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);
  3491. //DEBUG_INFO(" org date time: %s\n", data);
  3492. //DEBUG_INFO("parse date time: %s\n", buf);
  3493. system(buf);
  3494. system("/sbin/hwclock -w --systohc");
  3495. if(result.scanedElement < 6)
  3496. result.result = FAIL;
  3497. return result.result;
  3498. }
  3499. //==========================================
  3500. // GetCompositeSchedule logic related function
  3501. //==========================================
  3502. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3503. {
  3504. //return milli-second
  3505. unsigned int StartTime,StopTime;
  3506. StartTime=(unsigned int)ST.time;
  3507. StopTime=(unsigned int)ET.time;
  3508. return (StopTime-StartTime);
  3509. }
  3510. int DiffTimebWithNowSec(struct timeb ST)
  3511. {
  3512. //return milli-second
  3513. struct timeb ET;
  3514. unsigned int StartTime,StopTime;
  3515. ftime(&ET);
  3516. StartTime=(unsigned int)ST.time;
  3517. StopTime=(unsigned int)ET.time;
  3518. return (StopTime-StartTime);
  3519. }
  3520. int getStartStop(uint8_t *start, uint8_t *stop)
  3521. {
  3522. struct ParsingResult
  3523. {
  3524. int result;
  3525. int scanedElement;
  3526. int year;
  3527. int month;
  3528. int mday;
  3529. int hour;
  3530. int min;
  3531. int sec;
  3532. int tz_hour;
  3533. int tz_min;
  3534. float minSec;
  3535. };
  3536. struct ParsingResult parseStart;
  3537. struct ParsingResult parseStop;
  3538. int result = -1;
  3539. struct tm tmStart;
  3540. struct timeb tbStart;
  3541. struct tm tmStop;
  3542. struct timeb tbStop;
  3543. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3544. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3545. // Scan start & stop date time
  3546. if(strstr((char*)start, ".") != NULL)
  3547. {
  3548. // Original data with mini second
  3549. if(strstr((char*)start, "Z") != NULL)
  3550. {
  3551. // Original data with Z
  3552. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3553. &parseStart.year,
  3554. &parseStart.month,
  3555. &parseStart.mday,
  3556. &parseStart.hour,
  3557. &parseStart.min,
  3558. &parseStart.sec,
  3559. &parseStart.minSec);
  3560. }
  3561. else
  3562. {
  3563. // Original data without Z
  3564. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3565. &parseStart.year,
  3566. &parseStart.month,
  3567. &parseStart.mday,
  3568. &parseStart.hour,
  3569. &parseStart.min,
  3570. &parseStart.sec,
  3571. &parseStart.minSec,
  3572. &parseStart.tz_hour,
  3573. &parseStart.tz_min);
  3574. }
  3575. }
  3576. else
  3577. {
  3578. // Original data without mini second
  3579. if(strstr((char*)start, "Z") != NULL)
  3580. {
  3581. // Original data with Z
  3582. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3583. &parseStart.year,
  3584. &parseStart.month,
  3585. &parseStart.mday,
  3586. &parseStart.hour,
  3587. &parseStart.min,
  3588. &parseStart.sec);
  3589. }
  3590. else
  3591. {
  3592. // Original data without Z
  3593. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3594. &parseStart.year,
  3595. &parseStart.month,
  3596. &parseStart.mday,
  3597. &parseStart.hour,
  3598. &parseStart.min,
  3599. &parseStart.sec,
  3600. &parseStart.tz_hour,
  3601. &parseStart.tz_min);
  3602. }
  3603. }
  3604. if(strstr((char*)stop, ".") != NULL)
  3605. {
  3606. // Original data with mini second
  3607. if(strstr((char*)stop, "Z") != NULL)
  3608. {
  3609. // Original data with Z
  3610. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3611. &parseStop.year,
  3612. &parseStop.month,
  3613. &parseStop.mday,
  3614. &parseStop.hour,
  3615. &parseStop.min,
  3616. &parseStop.sec,
  3617. &parseStop.minSec);
  3618. }
  3619. else
  3620. {
  3621. // Original data without Z
  3622. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3623. &parseStop.year,
  3624. &parseStop.month,
  3625. &parseStop.mday,
  3626. &parseStop.hour,
  3627. &parseStop.min,
  3628. &parseStop.sec,
  3629. &parseStop.minSec,
  3630. &parseStop.tz_hour,
  3631. &parseStop.tz_min);
  3632. }
  3633. }
  3634. else
  3635. {
  3636. // Original data without mini second
  3637. if(strstr((char*)stop, "Z") != NULL)
  3638. {
  3639. // Original data with Z
  3640. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3641. &parseStop.year,
  3642. &parseStop.month,
  3643. &parseStop.mday,
  3644. &parseStop.hour,
  3645. &parseStop.min,
  3646. &parseStop.sec);
  3647. }
  3648. else
  3649. {
  3650. // Original data without Z
  3651. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3652. &parseStop.year,
  3653. &parseStop.month,
  3654. &parseStop.mday,
  3655. &parseStop.hour,
  3656. &parseStop.min,
  3657. &parseStop.sec,
  3658. &parseStop.tz_hour,
  3659. &parseStop.tz_min);
  3660. }
  3661. }
  3662. // Calculate date time difference
  3663. if((parseStart.scanedElement >=6) &&
  3664. (parseStop.scanedElement >=6))
  3665. {
  3666. //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);
  3667. //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);
  3668. tmStart.tm_year = parseStart.year - 1900;
  3669. tmStart.tm_mon = parseStart.month - 1;
  3670. tmStart.tm_mday = parseStart.mday;
  3671. tmStart.tm_hour = parseStart.hour;
  3672. tmStart.tm_min = parseStart.min;
  3673. tmStart.tm_sec = parseStart.sec;
  3674. tmStart.tm_gmtoff = 0;
  3675. tbStart.time = mktime(&tmStart);
  3676. tbStart.timezone = 0;
  3677. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3678. tmStop.tm_year = parseStop.year - 1900;
  3679. tmStop.tm_mon = parseStop.month - 1;
  3680. tmStop.tm_mday = parseStop.mday;
  3681. tmStop.tm_hour = parseStop.hour;
  3682. tmStop.tm_min = parseStop.min;
  3683. tmStop.tm_sec = parseStop.sec;
  3684. tmStop.tm_gmtoff = 0;
  3685. tbStop.time = mktime(&tmStop);
  3686. tbStop.timezone = 0;
  3687. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3688. result = DiffTimebSec(tbStart, tbStop);
  3689. //DEBUG_INFO("getStartStop(): %d\n", result);
  3690. }
  3691. else
  3692. {
  3693. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3694. }
  3695. return result;
  3696. }
  3697. int isOvertNow(uint8_t *start)
  3698. {
  3699. int result = NO;
  3700. struct ParsingResult
  3701. {
  3702. int result;
  3703. int scanedElement;
  3704. int year;
  3705. int month;
  3706. int mday;
  3707. int hour;
  3708. int min;
  3709. int sec;
  3710. int tz_hour;
  3711. int tz_min;
  3712. float minSec;
  3713. }parsingResult;
  3714. struct tm tmStart;
  3715. struct timeb tbStart;
  3716. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3717. if(strstr((char*)start, ".") != NULL)
  3718. {
  3719. // Original data with mini second
  3720. if(strstr((char*)start, "Z") != NULL)
  3721. {
  3722. // Original data with Z
  3723. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3724. &parsingResult.year,
  3725. &parsingResult.month,
  3726. &parsingResult.mday,
  3727. &parsingResult.hour,
  3728. &parsingResult.min,
  3729. &parsingResult.sec,
  3730. &parsingResult.minSec);
  3731. }
  3732. else
  3733. {
  3734. // Original data without Z
  3735. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3736. &parsingResult.year,
  3737. &parsingResult.month,
  3738. &parsingResult.mday,
  3739. &parsingResult.hour,
  3740. &parsingResult.min,
  3741. &parsingResult.sec,
  3742. &parsingResult.minSec,
  3743. &parsingResult.tz_hour,
  3744. &parsingResult.tz_min);
  3745. }
  3746. }
  3747. else
  3748. {
  3749. // Original data without mini second
  3750. if(strstr((char*)start, "Z") != NULL)
  3751. {
  3752. // Original data with Z
  3753. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3754. &parsingResult.year,
  3755. &parsingResult.month,
  3756. &parsingResult.mday,
  3757. &parsingResult.hour,
  3758. &parsingResult.min,
  3759. &parsingResult.sec);
  3760. }
  3761. else
  3762. {
  3763. // Original data without Z
  3764. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3765. &parsingResult.year,
  3766. &parsingResult.month,
  3767. &parsingResult.mday,
  3768. &parsingResult.hour,
  3769. &parsingResult.min,
  3770. &parsingResult.sec,
  3771. &parsingResult.tz_hour,
  3772. &parsingResult.tz_min);
  3773. }
  3774. }
  3775. if(parsingResult.scanedElement >= 6)
  3776. {
  3777. tmStart.tm_year = parsingResult.year - 1900;
  3778. tmStart.tm_mon = parsingResult.month - 1;
  3779. tmStart.tm_mday = parsingResult.mday;
  3780. tmStart.tm_hour = parsingResult.hour;
  3781. tmStart.tm_min = parsingResult.min;
  3782. tmStart.tm_sec = parsingResult.sec;
  3783. tmStart.tm_gmtoff = 0;
  3784. tbStart.time = mktime(&tmStart);
  3785. tbStart.timezone = 0;
  3786. tbStart.millitm = 0;
  3787. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3788. if(DiffTimebWithNowSec(tbStart) <= 0)
  3789. result = NO;
  3790. else
  3791. result = YES;
  3792. }
  3793. else
  3794. {
  3795. DEBUG_WARN("Start date parsing error.\n");
  3796. }
  3797. return result;
  3798. }
  3799. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3800. {
  3801. struct ParsingResult
  3802. {
  3803. int result;
  3804. int scanedElement;
  3805. int year;
  3806. int month;
  3807. int mday;
  3808. int hour;
  3809. int min;
  3810. int sec;
  3811. int tz_hour;
  3812. int tz_min;
  3813. float minSec;
  3814. };
  3815. struct ParsingResult parseStart;
  3816. struct ParsingResult parseStop;
  3817. int result = -1;
  3818. struct tm tmStart;
  3819. struct timeb tbStart;
  3820. struct tm tmStop;
  3821. struct timeb tbStop;
  3822. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3823. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3824. // Scan start & stop date time
  3825. if(strstr((char*)start, ".") != NULL)
  3826. {
  3827. // Original data with mini second
  3828. if(strstr((char*)start, "Z") != NULL)
  3829. {
  3830. // Original data with Z
  3831. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3832. &parseStart.year,
  3833. &parseStart.month,
  3834. &parseStart.mday,
  3835. &parseStart.hour,
  3836. &parseStart.min,
  3837. &parseStart.sec,
  3838. &parseStart.minSec);
  3839. }
  3840. else
  3841. {
  3842. // Original data without Z
  3843. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3844. &parseStart.year,
  3845. &parseStart.month,
  3846. &parseStart.mday,
  3847. &parseStart.hour,
  3848. &parseStart.min,
  3849. &parseStart.sec,
  3850. &parseStart.minSec,
  3851. &parseStart.tz_hour,
  3852. &parseStart.tz_min);
  3853. }
  3854. }
  3855. else
  3856. {
  3857. // Original data without mini second
  3858. if(strstr((char*)start, "Z") != NULL)
  3859. {
  3860. // Original data with Z
  3861. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3862. &parseStart.year,
  3863. &parseStart.month,
  3864. &parseStart.mday,
  3865. &parseStart.hour,
  3866. &parseStart.min,
  3867. &parseStart.sec);
  3868. }
  3869. else
  3870. {
  3871. // Original data without Z
  3872. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3873. &parseStart.year,
  3874. &parseStart.month,
  3875. &parseStart.mday,
  3876. &parseStart.hour,
  3877. &parseStart.min,
  3878. &parseStart.sec,
  3879. &parseStart.tz_hour,
  3880. &parseStart.tz_min);
  3881. }
  3882. }
  3883. if(strstr((char*)stop, ".") != NULL)
  3884. {
  3885. // Original data with mini second
  3886. if(strstr((char*)stop, "Z") != NULL)
  3887. {
  3888. // Original data with Z
  3889. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3890. &parseStop.year,
  3891. &parseStop.month,
  3892. &parseStop.mday,
  3893. &parseStop.hour,
  3894. &parseStop.min,
  3895. &parseStop.sec,
  3896. &parseStop.minSec);
  3897. }
  3898. else
  3899. {
  3900. // Original data without Z
  3901. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3902. &parseStop.year,
  3903. &parseStop.month,
  3904. &parseStop.mday,
  3905. &parseStop.hour,
  3906. &parseStop.min,
  3907. &parseStop.sec,
  3908. &parseStop.minSec,
  3909. &parseStop.tz_hour,
  3910. &parseStop.tz_min);
  3911. }
  3912. }
  3913. else
  3914. {
  3915. // Original data without mini second
  3916. if(strstr((char*)stop, "Z") != NULL)
  3917. {
  3918. // Original data with Z
  3919. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3920. &parseStop.year,
  3921. &parseStop.month,
  3922. &parseStop.mday,
  3923. &parseStop.hour,
  3924. &parseStop.min,
  3925. &parseStop.sec);
  3926. }
  3927. else
  3928. {
  3929. // Original data without Z
  3930. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3931. &parseStop.year,
  3932. &parseStop.month,
  3933. &parseStop.mday,
  3934. &parseStop.hour,
  3935. &parseStop.min,
  3936. &parseStop.sec,
  3937. &parseStop.tz_hour,
  3938. &parseStop.tz_min);
  3939. }
  3940. }
  3941. // Calculate date time difference
  3942. if((parseStart.scanedElement >=6) &&
  3943. (parseStop.scanedElement >=6))
  3944. {
  3945. //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);
  3946. //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);
  3947. tmStart.tm_year = parseStart.year - 1900;
  3948. tmStart.tm_mon = parseStart.month - 1;
  3949. tmStart.tm_mday = parseStart.mday;
  3950. tmStart.tm_hour = parseStart.hour;
  3951. tmStart.tm_min = parseStart.min;
  3952. tmStart.tm_sec = parseStart.sec;
  3953. tmStart.tm_gmtoff = 0;
  3954. tbStart.time = mktime(&tmStart);
  3955. tbStart.timezone = 0;
  3956. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3957. tmStop.tm_year = parseStop.year - 1900;
  3958. tmStop.tm_mon = parseStop.month - 1;
  3959. tmStop.tm_mday = parseStop.mday;
  3960. tmStop.tm_hour = parseStop.hour;
  3961. tmStop.tm_min = parseStop.min;
  3962. tmStop.tm_sec = parseStop.sec;
  3963. tmStop.tm_gmtoff = 0;
  3964. tbStop.time = mktime(&tmStop);
  3965. tbStop.timezone = 0;
  3966. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3967. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  3968. //DEBUG_INFO("getStartStop(): %d\n", result);
  3969. }
  3970. else
  3971. {
  3972. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3973. }
  3974. return result;
  3975. }
  3976. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3977. {
  3978. FILE *fp;
  3979. char profileFileName[128];
  3980. char *line = NULL;
  3981. size_t len = 0;
  3982. time_t CurrentTime;
  3983. struct tm *tmComposite;
  3984. struct ChargingProfileType maxProfile;
  3985. struct ChargingProfileType compositeProfile;
  3986. uint8_t limitMax=0;
  3987. int compositePeriodIdx = 0;
  3988. CurrentTime = time(NULL);
  3989. tmComposite=localtime(&CurrentTime);
  3990. 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);
  3991. if(isUnitA)
  3992. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3993. else
  3994. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3995. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3997. {
  3998. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3999. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4000. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4001. }
  4002. compositeProfile.id = 0;
  4003. compositeProfile.stackLevel = 99 ;
  4004. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  4005. maxProfile.id = -1;
  4006. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4007. system("rm -f /tmp/*.json");
  4008. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4009. // Search max profile
  4010. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4011. if((access(profileFileName, F_OK))!=-1)
  4012. {
  4013. fp = fopen(profileFileName, "r");
  4014. while(getline(&line, &len, fp) != -1)
  4015. {
  4016. json_object *obj = NULL;
  4017. obj = json_tokener_parse(line);
  4018. if(is_error(obj))
  4019. {
  4020. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4021. }
  4022. else
  4023. {
  4024. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4025. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4026. )
  4027. {
  4028. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4029. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4030. )
  4031. {
  4032. struct tm tmFrom, tmTo;
  4033. struct timeb tbFrom, tbTo;
  4034. 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) &&
  4035. (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))
  4036. {
  4037. tmFrom.tm_year -= 1900;
  4038. tmFrom.tm_mon -= 1;
  4039. tbFrom.time = mktime(&tmFrom);
  4040. tmTo.tm_year -= 1900;
  4041. tmTo.tm_mon -= 1;
  4042. tbTo.time = mktime(&tmTo);
  4043. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4044. {
  4045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4046. {
  4047. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4048. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4049. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4050. }
  4051. if(maxProfile.id == -1)
  4052. DEBUG_INFO("MaxProfile found.\n");
  4053. else
  4054. DEBUG_INFO("MaxProfile updated.\n");
  4055. // Required item
  4056. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4057. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4058. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4059. if(isUnitA)
  4060. {
  4061. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4062. 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++)
  4063. {
  4064. 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"));
  4065. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4066. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4067. {
  4068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4069. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4070. else
  4071. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4072. }
  4073. else
  4074. {
  4075. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4076. }*/
  4077. 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")));
  4078. }
  4079. }
  4080. else
  4081. {
  4082. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4083. 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++)
  4084. {
  4085. 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"));
  4086. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4087. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4088. {
  4089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4090. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4091. else
  4092. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4093. }
  4094. else
  4095. {
  4096. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4097. }*/
  4098. 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));
  4099. }
  4100. }
  4101. // Optional item
  4102. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4103. {
  4104. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4105. }
  4106. else
  4107. {
  4108. sprintf((char*)maxProfile.validFrom, " ");
  4109. }
  4110. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4111. {
  4112. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4113. }
  4114. else
  4115. {
  4116. sprintf((char*)maxProfile.validTo, " ");
  4117. }
  4118. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4119. {
  4120. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4121. }
  4122. else
  4123. {
  4124. sprintf((char*)maxProfile.recurrencyKind, " ");
  4125. }
  4126. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4127. {
  4128. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4129. }
  4130. else
  4131. {
  4132. sprintf((char*)maxProfile.transactionId, " ");
  4133. }
  4134. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4135. {
  4136. 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"));
  4137. }
  4138. else
  4139. {
  4140. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4141. }
  4142. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4143. {
  4144. 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")));
  4145. }
  4146. else
  4147. {
  4148. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4149. }
  4150. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4151. {
  4152. 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"));
  4153. }
  4154. else
  4155. {
  4156. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4157. }
  4158. }
  4159. }
  4160. }
  4161. else
  4162. {
  4163. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4164. {
  4165. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4166. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4167. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4168. }
  4169. if(maxProfile.id == -1)
  4170. DEBUG_INFO("MaxProfile found.\n");
  4171. else
  4172. DEBUG_INFO("MaxProfile updated.\n");
  4173. // Required item
  4174. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4175. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4176. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4177. if(isUnitA)
  4178. {
  4179. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4180. 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++)
  4181. {
  4182. 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"));
  4183. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4184. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4185. {
  4186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4187. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4188. else
  4189. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4190. }
  4191. else
  4192. {
  4193. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4194. }*/
  4195. 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")));
  4196. }
  4197. }
  4198. else
  4199. {
  4200. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4201. 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++)
  4202. {
  4203. 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"));
  4204. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4205. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4206. {
  4207. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4208. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4209. else
  4210. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4211. }
  4212. else
  4213. {
  4214. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4215. }*/
  4216. 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));
  4217. }
  4218. }
  4219. // Optional item
  4220. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4221. {
  4222. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4223. }
  4224. else
  4225. {
  4226. sprintf((char*)maxProfile.validFrom, " ");
  4227. }
  4228. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4229. {
  4230. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4231. }
  4232. else
  4233. {
  4234. sprintf((char*)maxProfile.validTo, " ");
  4235. }
  4236. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4237. {
  4238. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4239. }
  4240. else
  4241. {
  4242. sprintf((char*)maxProfile.recurrencyKind, " ");
  4243. }
  4244. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4245. {
  4246. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4247. }
  4248. else
  4249. {
  4250. sprintf((char*)maxProfile.transactionId, " ");
  4251. }
  4252. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4253. {
  4254. 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"));
  4255. }
  4256. else
  4257. {
  4258. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4259. }
  4260. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4261. {
  4262. 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")));
  4263. }
  4264. else
  4265. {
  4266. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4267. }
  4268. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4269. {
  4270. 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"));
  4271. }
  4272. else
  4273. {
  4274. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4275. }
  4276. }
  4277. }
  4278. }
  4279. json_object_put(obj);
  4280. }
  4281. fclose(fp);
  4282. /*
  4283. if(maxProfile.id !=-1)
  4284. {
  4285. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4286. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4287. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4288. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4289. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4290. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4291. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4292. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4293. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4294. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4295. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4296. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4297. {
  4298. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4299. {
  4300. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4301. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4302. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4303. }
  4304. }
  4305. }
  4306. else
  4307. DEBUG_INFO("MaxProfile not found.\n");
  4308. DEBUG_INFO("------------------------------------\n");*/
  4309. }
  4310. if(maxProfile.id != -1)
  4311. {
  4312. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4313. {
  4314. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4315. {
  4316. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4317. 0:
  4318. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4319. }
  4320. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4321. {
  4322. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4323. {
  4324. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4325. 0:
  4326. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4327. if(idxPeriod > 0)
  4328. {
  4329. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4330. {
  4331. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4332. }
  4333. }
  4334. }
  4335. }
  4336. }
  4337. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4338. {
  4339. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4340. {
  4341. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  4342. }
  4343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4344. {
  4345. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4346. {
  4347. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  4348. if(idxPeriod > 0)
  4349. {
  4350. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4351. {
  4352. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4353. }
  4354. }
  4355. }
  4356. }
  4357. }
  4358. else
  4359. {
  4360. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4361. {
  4362. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4363. {
  4364. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4365. 0:
  4366. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4367. }
  4368. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4369. {
  4370. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4371. {
  4372. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4373. 0:
  4374. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4375. if(idxPeriod > 0)
  4376. {
  4377. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4378. {
  4379. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4380. }
  4381. }
  4382. }
  4383. }
  4384. }
  4385. else
  4386. {
  4387. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4388. {
  4389. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4390. 0:
  4391. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4392. }
  4393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4394. {
  4395. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4396. {
  4397. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4398. 0:
  4399. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4400. if(idxPeriod > 0)
  4401. {
  4402. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4403. {
  4404. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4405. }
  4406. }
  4407. }
  4408. }
  4409. }
  4410. }
  4411. /*
  4412. DEBUG_INFO("MaxProfile after align.\n");
  4413. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4414. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4415. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4416. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4417. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4418. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4419. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4420. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4421. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4422. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4423. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4424. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4425. {
  4426. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4427. {
  4428. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4429. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4430. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4431. }
  4432. }
  4433. DEBUG_INFO("------------------------------------\n");*/
  4434. }
  4435. // Find each profile period quantity
  4436. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4437. {
  4438. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4439. limitMax = idx+1;
  4440. }
  4441. if(maxProfile.id != -1)
  4442. {
  4443. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4444. {
  4445. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4446. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4447. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4448. {
  4449. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4450. {
  4451. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4452. compositePeriodIdx++;
  4453. }
  4454. else
  4455. {
  4456. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4457. }
  4458. }
  4459. }
  4460. }
  4461. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4462. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4463. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4464. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4465. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4466. {
  4467. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4468. {
  4469. compositeProfile.id = 1;
  4470. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4471. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4472. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4473. }
  4474. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4475. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4476. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4477. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4478. }
  4479. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4480. if(line)
  4481. free(line);
  4482. }
  4483. void checkCompositeSchedule(uint8_t evseId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4484. {
  4485. FILE *fp;
  4486. char profileFileName[128];
  4487. char *line = NULL;
  4488. size_t len = 0;
  4489. time_t CurrentTime;
  4490. struct tm *tmComposite;
  4491. struct ChargingProfileType maxProfile;
  4492. struct ChargingProfileType defaultTxProfile;
  4493. struct ChargingProfileType txProfile;
  4494. struct ChargingProfileType compositeProfile;
  4495. struct ChargingSchedulePeriodType tmpPeriod;
  4496. uint8_t limitMax=0;
  4497. uint8_t limitDef=0;
  4498. uint8_t limitTx=0;
  4499. int compositePeriodIdx = 0;
  4500. CurrentTime = time(NULL);
  4501. tmComposite=localtime(&CurrentTime);
  4502. 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);
  4503. if(isUnitA)
  4504. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4505. else
  4506. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4507. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4508. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4509. {
  4510. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4511. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4512. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4513. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4514. }
  4515. compositeProfile.id = 0;
  4516. compositeProfile.stackLevel = 99 ;
  4517. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4518. maxProfile.id = -1;
  4519. defaultTxProfile.id = -1;
  4520. txProfile.id = -1;
  4521. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4522. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4523. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4524. system("rm -f /tmp/*.json");
  4525. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4526. /*
  4527. * Search valid charging profile
  4528. */
  4529. //DEBUG_INFO("====================================\n");
  4530. // Search tx profile
  4531. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", evseId);
  4532. if((access(profileFileName, F_OK))!=-1)
  4533. {
  4534. fp = fopen(profileFileName, "r");
  4535. while(getline(&line, &len, fp) != -1)
  4536. {
  4537. json_object *obj = NULL;
  4538. obj = json_tokener_parse(line);
  4539. if(is_error(obj))
  4540. {
  4541. DEBUG_ERROR("Parse txProfile from file error.\n");
  4542. }
  4543. else
  4544. {
  4545. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4546. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4547. )
  4548. {
  4549. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4550. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4551. )
  4552. {
  4553. struct tm tmFrom, tmTo;
  4554. struct timeb tbFrom, tbTo;
  4555. 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) &&
  4556. (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))
  4557. {
  4558. tmFrom.tm_year -= 1900;
  4559. tmFrom.tm_mon -= 1;
  4560. tbFrom.time = mktime(&tmFrom);
  4561. tmTo.tm_year -= 1900;
  4562. tmTo.tm_mon -= 1;
  4563. tbTo.time = mktime(&tmTo);
  4564. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4565. {
  4566. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4567. {
  4568. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4569. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4570. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4571. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4572. }
  4573. if(txProfile.id == -1)
  4574. DEBUG_INFO("TxProfile found.\n");
  4575. else
  4576. DEBUG_INFO("TxProfile updated.\n");
  4577. // Required item
  4578. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4579. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4580. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4581. if(isUnitA)
  4582. {
  4583. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4584. 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++)
  4585. {
  4586. 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"));
  4587. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4588. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4589. {
  4590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4591. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4592. else
  4593. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4594. }
  4595. else
  4596. {
  4597. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4598. }*/
  4599. 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")));
  4600. }
  4601. }
  4602. else
  4603. {
  4604. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4605. 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++)
  4606. {
  4607. 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"));
  4608. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4609. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4610. {
  4611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4612. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4613. else
  4614. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4615. }
  4616. else
  4617. {
  4618. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4619. }*/
  4620. 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));
  4621. }
  4622. }
  4623. // Optional item
  4624. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4625. {
  4626. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4627. }
  4628. else
  4629. {
  4630. sprintf((char*)txProfile.validFrom, " ");
  4631. }
  4632. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4633. {
  4634. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4635. }
  4636. else
  4637. {
  4638. sprintf((char*)txProfile.validTo, " ");
  4639. }
  4640. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4641. {
  4642. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4643. }
  4644. else
  4645. {
  4646. sprintf((char*)txProfile.recurrencyKind, " ");
  4647. }
  4648. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4649. {
  4650. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4651. }
  4652. else
  4653. {
  4654. sprintf((char*)txProfile.transactionId, " ");
  4655. }
  4656. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4657. {
  4658. 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"));
  4659. }
  4660. else
  4661. {
  4662. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4663. }
  4664. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4665. {
  4666. 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")));
  4667. }
  4668. else
  4669. {
  4670. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4671. }
  4672. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4673. {
  4674. 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"));
  4675. }
  4676. else
  4677. {
  4678. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4679. }
  4680. }
  4681. }
  4682. }
  4683. else
  4684. {
  4685. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4686. {
  4687. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4688. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4689. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4690. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4691. }
  4692. if(txProfile.id == -1)
  4693. DEBUG_INFO("TxProfile found.\n");
  4694. else
  4695. DEBUG_INFO("TxProfile updated.\n");
  4696. // Required item
  4697. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4698. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4699. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4700. if(isUnitA)
  4701. {
  4702. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4703. 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++)
  4704. {
  4705. 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"));
  4706. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4707. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4708. {
  4709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4710. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4711. else
  4712. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4713. }
  4714. else
  4715. {
  4716. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4717. }*/
  4718. 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")));
  4719. }
  4720. }
  4721. else
  4722. {
  4723. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4724. 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++)
  4725. {
  4726. 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"));
  4727. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4728. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4729. {
  4730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4731. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4732. else
  4733. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4734. }
  4735. else
  4736. {
  4737. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4738. }*/
  4739. 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));
  4740. }
  4741. }
  4742. // Optional item
  4743. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4744. {
  4745. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4746. }
  4747. else
  4748. {
  4749. sprintf((char*)txProfile.validFrom, " ");
  4750. }
  4751. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4752. {
  4753. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4754. }
  4755. else
  4756. {
  4757. sprintf((char*)txProfile.validTo, " ");
  4758. }
  4759. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4760. {
  4761. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4762. }
  4763. else
  4764. {
  4765. sprintf((char*)txProfile.recurrencyKind, " ");
  4766. }
  4767. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4768. {
  4769. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4770. }
  4771. else
  4772. {
  4773. sprintf((char*)txProfile.transactionId, " ");
  4774. }
  4775. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4776. {
  4777. 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"));
  4778. }
  4779. else
  4780. {
  4781. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4782. }
  4783. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4784. {
  4785. 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")));
  4786. }
  4787. else
  4788. {
  4789. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4790. }
  4791. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4792. {
  4793. 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"));
  4794. }
  4795. else
  4796. {
  4797. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4798. }
  4799. }
  4800. }
  4801. }
  4802. json_object_put(obj);
  4803. }
  4804. fclose(fp);
  4805. /*
  4806. if(txProfile.id != -1)
  4807. {
  4808. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4815. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4820. {
  4821. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4822. {
  4823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4826. }
  4827. }
  4828. }
  4829. else
  4830. DEBUG_INFO("TxProfile not found.\n");*/
  4831. }
  4832. // Search default tx profile
  4833. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", evseId);
  4834. if((access(profileFileName, F_OK))==-1)
  4835. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4836. if((access(profileFileName, F_OK))!=-1)
  4837. {
  4838. fp = fopen(profileFileName, "r");
  4839. while(getline(&line, &len, fp) != -1)
  4840. {
  4841. json_object *obj = NULL;
  4842. obj = json_tokener_parse(line);
  4843. if(is_error(obj))
  4844. {
  4845. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4846. }
  4847. else
  4848. {
  4849. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  4850. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  4851. )
  4852. {
  4853. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4854. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4855. )
  4856. {
  4857. struct tm tmFrom, tmTo;
  4858. struct timeb tbFrom, tbTo;
  4859. 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) &&
  4860. (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))
  4861. {
  4862. tmFrom.tm_year -= 1900;
  4863. tmFrom.tm_mon -= 1;
  4864. tbFrom.time = mktime(&tmFrom);
  4865. tmTo.tm_year -= 1900;
  4866. tmTo.tm_mon -= 1;
  4867. tbTo.time = mktime(&tmTo);
  4868. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4869. {
  4870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4871. {
  4872. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4873. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4874. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4875. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4876. }
  4877. if(defaultTxProfile.id == -1)
  4878. DEBUG_INFO("TxDefaultProfile found.\n");
  4879. else
  4880. DEBUG_INFO("TxDefaultProfile updated.\n");
  4881. // Required item
  4882. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4883. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4884. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4885. if(isUnitA)
  4886. {
  4887. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4888. 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++)
  4889. {
  4890. 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"));
  4891. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4892. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4893. {
  4894. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4895. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4896. else
  4897. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4898. }
  4899. else
  4900. {
  4901. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4902. }*/
  4903. 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")));
  4904. }
  4905. }
  4906. else
  4907. {
  4908. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4909. 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++)
  4910. {
  4911. 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"));
  4912. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4913. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4914. {
  4915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4916. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4917. else
  4918. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4919. }
  4920. else
  4921. {
  4922. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4923. }*/
  4924. 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));
  4925. }
  4926. }
  4927. // Optional item
  4928. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4929. {
  4930. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4931. }
  4932. else
  4933. {
  4934. sprintf((char*)defaultTxProfile.validFrom, " ");
  4935. }
  4936. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4937. {
  4938. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4939. }
  4940. else
  4941. {
  4942. sprintf((char*)defaultTxProfile.validTo, " ");
  4943. }
  4944. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4945. {
  4946. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4947. }
  4948. else
  4949. {
  4950. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4951. }
  4952. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4953. {
  4954. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4955. }
  4956. else
  4957. {
  4958. sprintf((char*)defaultTxProfile.transactionId, " ");
  4959. }
  4960. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4961. {
  4962. 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"));
  4963. }
  4964. else
  4965. {
  4966. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4967. }
  4968. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4969. {
  4970. 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")));
  4971. }
  4972. else
  4973. {
  4974. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4975. }
  4976. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4977. {
  4978. 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"));
  4979. }
  4980. else
  4981. {
  4982. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4983. }
  4984. }
  4985. }
  4986. }
  4987. else
  4988. {
  4989. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4990. {
  4991. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4992. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4993. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4994. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4995. }
  4996. if(defaultTxProfile.id == -1)
  4997. DEBUG_INFO("TxDefaultProfile found.\n");
  4998. else
  4999. DEBUG_INFO("TxDefaultProfile updated.\n");
  5000. // Required item
  5001. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5002. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5003. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5004. if(isUnitA)
  5005. {
  5006. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5007. 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++)
  5008. {
  5009. 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"));
  5010. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5011. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5012. {
  5013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5014. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5015. else
  5016. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5017. }
  5018. else
  5019. {
  5020. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5021. }*/
  5022. 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")));
  5023. }
  5024. }
  5025. else
  5026. {
  5027. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5028. 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++)
  5029. {
  5030. 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"));
  5031. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5032. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5033. {
  5034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5035. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5036. else
  5037. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5038. }
  5039. else
  5040. {
  5041. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5042. }*/
  5043. 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));
  5044. }
  5045. }
  5046. // Optional item
  5047. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5048. {
  5049. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5050. }
  5051. else
  5052. {
  5053. sprintf((char*)defaultTxProfile.validFrom, " ");
  5054. }
  5055. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5056. {
  5057. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5058. }
  5059. else
  5060. {
  5061. sprintf((char*)defaultTxProfile.validTo, " ");
  5062. }
  5063. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5064. {
  5065. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5066. }
  5067. else
  5068. {
  5069. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5070. }
  5071. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5072. {
  5073. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5074. }
  5075. else
  5076. {
  5077. sprintf((char*)defaultTxProfile.transactionId, " ");
  5078. }
  5079. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5080. {
  5081. 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"));
  5082. }
  5083. else
  5084. {
  5085. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5086. }
  5087. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5088. {
  5089. 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")));
  5090. }
  5091. else
  5092. {
  5093. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5094. }
  5095. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5096. {
  5097. 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"));
  5098. }
  5099. else
  5100. {
  5101. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5102. }
  5103. }
  5104. }
  5105. }
  5106. json_object_put(obj);
  5107. }
  5108. fclose(fp);
  5109. /*
  5110. if(defaultTxProfile.id != -1)
  5111. {
  5112. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5113. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5114. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5115. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5116. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5117. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5118. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5119. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5120. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5121. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5122. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5123. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5124. {
  5125. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5126. {
  5127. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5128. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5129. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5130. }
  5131. }
  5132. }
  5133. else
  5134. DEBUG_INFO("TxDefaultProfile not found.\n");
  5135. DEBUG_INFO("------------------------------------\n");*/
  5136. }
  5137. // Search max profile
  5138. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  5139. if((access(profileFileName, F_OK))!=-1)
  5140. {
  5141. fp = fopen(profileFileName, "r");
  5142. while(getline(&line, &len, fp) != -1)
  5143. {
  5144. json_object *obj = NULL;
  5145. obj = json_tokener_parse(line);
  5146. if(is_error(obj))
  5147. {
  5148. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  5149. }
  5150. else
  5151. {
  5152. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  5153. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  5154. )
  5155. {
  5156. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5157. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5158. )
  5159. {
  5160. struct tm tmFrom, tmTo;
  5161. struct timeb tbFrom, tbTo;
  5162. 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) &&
  5163. (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))
  5164. {
  5165. tmFrom.tm_year -= 1900;
  5166. tmFrom.tm_mon -= 1;
  5167. tbFrom.time = mktime(&tmFrom);
  5168. tmTo.tm_year -= 1900;
  5169. tmTo.tm_mon -= 1;
  5170. tbTo.time = mktime(&tmTo);
  5171. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5172. {
  5173. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5174. {
  5175. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5176. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5177. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5178. }
  5179. if(maxProfile.id == -1)
  5180. DEBUG_INFO("MaxProfile found.\n");
  5181. else
  5182. DEBUG_INFO("MaxProfile updated.\n");
  5183. // Required item
  5184. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5185. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5186. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5187. if(isUnitA)
  5188. {
  5189. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5190. 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++)
  5191. {
  5192. 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"));
  5193. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5194. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5195. {
  5196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5197. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5198. else
  5199. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5200. }
  5201. else
  5202. {
  5203. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5204. }*/
  5205. 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")));
  5206. }
  5207. }
  5208. else
  5209. {
  5210. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5211. 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++)
  5212. {
  5213. 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"));
  5214. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5215. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5216. {
  5217. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5218. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5219. else
  5220. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5221. }
  5222. else
  5223. {
  5224. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5225. }*/
  5226. 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));
  5227. }
  5228. }
  5229. // Optional item
  5230. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5231. {
  5232. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5233. }
  5234. else
  5235. {
  5236. sprintf((char*)maxProfile.validFrom, " ");
  5237. }
  5238. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5239. {
  5240. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5241. }
  5242. else
  5243. {
  5244. sprintf((char*)maxProfile.validTo, " ");
  5245. }
  5246. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5247. {
  5248. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5249. }
  5250. else
  5251. {
  5252. sprintf((char*)maxProfile.recurrencyKind, " ");
  5253. }
  5254. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5255. {
  5256. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5257. }
  5258. else
  5259. {
  5260. sprintf((char*)maxProfile.transactionId, " ");
  5261. }
  5262. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5263. {
  5264. 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"));
  5265. }
  5266. else
  5267. {
  5268. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5269. }
  5270. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5271. {
  5272. 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")));
  5273. }
  5274. else
  5275. {
  5276. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5277. }
  5278. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5279. {
  5280. 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"));
  5281. }
  5282. else
  5283. {
  5284. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5285. }
  5286. }
  5287. }
  5288. }
  5289. else
  5290. {
  5291. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5292. {
  5293. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5294. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5295. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5296. }
  5297. if(maxProfile.id == -1)
  5298. DEBUG_INFO("MaxProfile found.\n");
  5299. else
  5300. DEBUG_INFO("MaxProfile updated.\n");
  5301. // Required item
  5302. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5303. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5304. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5305. if(isUnitA)
  5306. {
  5307. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5308. 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++)
  5309. {
  5310. 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"));
  5311. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5312. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5313. {
  5314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5315. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5316. else
  5317. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5318. }
  5319. else
  5320. {
  5321. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5322. }*/
  5323. 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")));
  5324. }
  5325. }
  5326. else
  5327. {
  5328. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5329. 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++)
  5330. {
  5331. 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"));
  5332. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5333. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  5334. {
  5335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5336. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5337. else
  5338. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5339. }
  5340. else
  5341. {
  5342. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  5343. }*/
  5344. 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));
  5345. }
  5346. }
  5347. // Optional item
  5348. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5349. {
  5350. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5351. }
  5352. else
  5353. {
  5354. sprintf((char*)maxProfile.validFrom, " ");
  5355. }
  5356. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5357. {
  5358. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5359. }
  5360. else
  5361. {
  5362. sprintf((char*)maxProfile.validTo, " ");
  5363. }
  5364. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5365. {
  5366. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5367. }
  5368. else
  5369. {
  5370. sprintf((char*)maxProfile.recurrencyKind, " ");
  5371. }
  5372. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5373. {
  5374. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5375. }
  5376. else
  5377. {
  5378. sprintf((char*)maxProfile.transactionId, " ");
  5379. }
  5380. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5381. {
  5382. 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"));
  5383. }
  5384. else
  5385. {
  5386. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5387. }
  5388. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5389. {
  5390. 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")));
  5391. }
  5392. else
  5393. {
  5394. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5395. }
  5396. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5397. {
  5398. 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"));
  5399. }
  5400. else
  5401. {
  5402. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5403. }
  5404. }
  5405. }
  5406. }
  5407. json_object_put(obj);
  5408. }
  5409. fclose(fp);
  5410. /*
  5411. if(maxProfile.id !=-1)
  5412. {
  5413. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5414. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5415. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5416. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5417. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5418. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5419. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5420. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5421. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5422. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5423. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5424. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5425. {
  5426. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5427. {
  5428. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5429. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5430. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5431. }
  5432. }
  5433. }
  5434. else
  5435. DEBUG_INFO("MaxProfile not found.\n");
  5436. DEBUG_INFO("------------------------------------\n");*/
  5437. }
  5438. /*
  5439. * Align found profile start schedule & periods
  5440. */
  5441. //DEBUG_INFO("====================================\n");
  5442. /*
  5443. // For local test usage, force modify found profile start schedule info
  5444. 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);
  5445. 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);
  5446. 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);
  5447. */
  5448. if(txProfile.id != -1)
  5449. {
  5450. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5451. {
  5452. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5453. {
  5454. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5455. 0:
  5456. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5457. }
  5458. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5459. {
  5460. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5461. {
  5462. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5463. 0:
  5464. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5465. if(idxPeriod > 0)
  5466. {
  5467. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5468. {
  5469. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5470. }
  5471. }
  5472. }
  5473. }
  5474. }
  5475. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5476. {
  5477. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5478. {
  5479. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5480. 0:
  5481. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5482. }
  5483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5484. {
  5485. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5486. {
  5487. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5488. 0:
  5489. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5490. if(idxPeriod > 0)
  5491. {
  5492. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5493. {
  5494. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5495. }
  5496. }
  5497. }
  5498. }
  5499. }
  5500. else
  5501. {
  5502. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5503. {
  5504. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5505. {
  5506. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5507. 0:
  5508. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5509. }
  5510. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5511. {
  5512. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5513. {
  5514. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5515. 0:
  5516. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5517. if(idxPeriod > 0)
  5518. {
  5519. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5520. {
  5521. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5522. }
  5523. }
  5524. }
  5525. }
  5526. }
  5527. else
  5528. {
  5529. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5530. {
  5531. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5532. 0:
  5533. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5534. }
  5535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5536. {
  5537. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5538. {
  5539. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5540. 0:
  5541. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5542. if(idxPeriod > 0)
  5543. {
  5544. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5545. {
  5546. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5547. }
  5548. }
  5549. }
  5550. }
  5551. }
  5552. }
  5553. /*
  5554. DEBUG_INFO("txProfile after align.\n");
  5555. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5556. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5557. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5558. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5559. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5560. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5561. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5562. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5563. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5564. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5565. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5566. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5567. {
  5568. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5569. {
  5570. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5571. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5572. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5573. }
  5574. }*/
  5575. }
  5576. if(defaultTxProfile.id != -1)
  5577. {
  5578. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5579. {
  5580. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5581. {
  5582. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5583. 0:
  5584. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5585. }
  5586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5587. {
  5588. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5589. {
  5590. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5591. 0:
  5592. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5593. if(idxPeriod > 0)
  5594. {
  5595. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5596. {
  5597. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5598. }
  5599. }
  5600. }
  5601. }
  5602. }
  5603. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5604. {
  5605. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5606. {
  5607. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5608. 0:
  5609. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5610. }
  5611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5612. {
  5613. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5614. {
  5615. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5616. 0:
  5617. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5618. if(idxPeriod > 0)
  5619. {
  5620. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5621. {
  5622. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5623. }
  5624. }
  5625. }
  5626. }
  5627. }
  5628. else
  5629. {
  5630. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5631. {
  5632. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5633. {
  5634. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5635. 0:
  5636. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5637. }
  5638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5639. {
  5640. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5641. {
  5642. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5643. 0:
  5644. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5645. if(idxPeriod > 0)
  5646. {
  5647. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5648. {
  5649. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5650. }
  5651. }
  5652. }
  5653. }
  5654. }
  5655. else
  5656. {
  5657. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5658. {
  5659. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5660. 0:
  5661. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5662. }
  5663. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5664. {
  5665. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5666. {
  5667. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5668. 0:
  5669. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5670. if(idxPeriod > 0)
  5671. {
  5672. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5673. {
  5674. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5675. }
  5676. }
  5677. }
  5678. }
  5679. }
  5680. }
  5681. /*
  5682. DEBUG_INFO("defaultTxProfile after align.\n");
  5683. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5684. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5685. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5686. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5687. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5688. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5689. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5690. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5691. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5692. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5693. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5694. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5695. {
  5696. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5697. {
  5698. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5699. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5700. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5701. }
  5702. }
  5703. DEBUG_INFO("------------------------------------\n");*/
  5704. }
  5705. if(maxProfile.id != -1)
  5706. {
  5707. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5708. {
  5709. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5710. {
  5711. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5712. 0:
  5713. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5714. }
  5715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5716. {
  5717. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5718. {
  5719. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5720. 0:
  5721. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5722. if(idxPeriod > 0)
  5723. {
  5724. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5725. {
  5726. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5727. }
  5728. }
  5729. }
  5730. }
  5731. }
  5732. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5733. {
  5734. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5735. {
  5736. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5737. 0:
  5738. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5739. }
  5740. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5741. {
  5742. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5743. {
  5744. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5745. 0:
  5746. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5747. if(idxPeriod > 0)
  5748. {
  5749. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5750. {
  5751. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5752. }
  5753. }
  5754. }
  5755. }
  5756. }
  5757. else
  5758. {
  5759. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5760. {
  5761. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5762. {
  5763. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5764. 0:
  5765. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5766. }
  5767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5768. {
  5769. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5770. {
  5771. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5772. 0:
  5773. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5774. if(idxPeriod > 0)
  5775. {
  5776. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5777. {
  5778. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5779. }
  5780. }
  5781. }
  5782. }
  5783. }
  5784. else
  5785. {
  5786. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5787. {
  5788. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5789. 0:
  5790. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5791. }
  5792. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5793. {
  5794. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5795. {
  5796. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5797. 0:
  5798. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5799. if(idxPeriod > 0)
  5800. {
  5801. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5802. {
  5803. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5804. }
  5805. }
  5806. }
  5807. }
  5808. }
  5809. }
  5810. /*
  5811. DEBUG_INFO("MaxProfile after align.\n");
  5812. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5813. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5814. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5815. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5816. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5817. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5818. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5819. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5820. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5821. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5822. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5823. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5824. {
  5825. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5826. {
  5827. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5828. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5829. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5830. }
  5831. }
  5832. DEBUG_INFO("------------------------------------\n");*/
  5833. }
  5834. /*
  5835. * Merge to conposite schedule
  5836. */
  5837. //DEBUG_INFO("====================================\n");
  5838. // Find each profile period quantity
  5839. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5840. {
  5841. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5842. limitMax = idx+1;
  5843. }
  5844. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5845. {
  5846. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5847. limitDef = idx+1;
  5848. }
  5849. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5850. {
  5851. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5852. limitTx = idx+1;
  5853. }
  5854. // TxProfile found, composite schedule based on it
  5855. if(txProfile.id != -1)
  5856. {
  5857. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  5858. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  5859. {
  5860. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  5861. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  5862. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  5863. {
  5864. if(maxProfile.id != -1)
  5865. {
  5866. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5867. {
  5868. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  5869. {
  5870. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5871. {
  5872. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5873. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5874. 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);
  5875. }
  5876. else
  5877. {
  5878. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5879. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5880. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  5881. }
  5882. }
  5883. if(idxMaxPeriod == (limitMax-1))
  5884. {
  5885. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5886. {
  5887. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5888. {
  5889. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5890. compositePeriodIdx++;
  5891. }
  5892. else
  5893. {
  5894. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5895. }
  5896. }
  5897. }
  5898. }
  5899. }
  5900. else
  5901. {
  5902. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5903. {
  5904. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5905. compositePeriodIdx++;
  5906. }
  5907. else
  5908. {
  5909. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5910. }
  5911. }
  5912. }
  5913. if(idxTxPeriod == (limitTx-1))
  5914. {
  5915. if(defaultTxProfile.id != -1)
  5916. {
  5917. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  5918. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5919. {
  5920. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  5921. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5922. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  5923. {
  5924. if(maxProfile.id != -1)
  5925. {
  5926. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5927. {
  5928. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5929. {
  5930. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5931. {
  5932. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5933. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5934. 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);
  5935. }
  5936. else
  5937. {
  5938. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5939. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5940. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5941. }
  5942. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5943. {
  5944. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5945. {
  5946. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5947. compositePeriodIdx++;
  5948. }
  5949. else
  5950. {
  5951. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5952. }
  5953. }
  5954. // Delete duplicate period
  5955. if(compositePeriodIdx > 1)
  5956. {
  5957. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5958. {
  5959. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5960. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5961. compositePeriodIdx -= 1;
  5962. }
  5963. }
  5964. }
  5965. else
  5966. {
  5967. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5968. {
  5969. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5970. compositePeriodIdx++;
  5971. }
  5972. else
  5973. {
  5974. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5975. }
  5976. break;
  5977. }
  5978. }
  5979. }
  5980. else
  5981. {
  5982. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5983. {
  5984. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5985. compositePeriodIdx++;
  5986. }
  5987. else
  5988. {
  5989. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5990. }
  5991. }
  5992. }
  5993. }
  5994. }
  5995. }
  5996. }
  5997. }
  5998. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  5999. else if(defaultTxProfile.id != -1)
  6000. {
  6001. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  6002. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6003. {
  6004. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  6005. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6006. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  6007. {
  6008. if(maxProfile.id != -1)
  6009. {
  6010. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6011. {
  6012. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6013. {
  6014. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6015. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6016. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6017. {
  6018. 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);
  6019. }
  6020. else
  6021. {
  6022. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6023. }
  6024. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6025. {
  6026. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6027. {
  6028. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6029. compositePeriodIdx++;
  6030. }
  6031. else
  6032. {
  6033. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6034. }
  6035. }
  6036. // Delete duplicate period
  6037. if(compositePeriodIdx > 1)
  6038. {
  6039. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6040. {
  6041. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6042. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6043. compositePeriodIdx -= 1;
  6044. }
  6045. }
  6046. }
  6047. else
  6048. {
  6049. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6050. {
  6051. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6052. compositePeriodIdx++;
  6053. }
  6054. else
  6055. {
  6056. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6057. }
  6058. break;
  6059. }
  6060. }
  6061. }
  6062. else
  6063. {
  6064. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6065. {
  6066. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6067. compositePeriodIdx++;
  6068. }
  6069. else
  6070. {
  6071. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6072. }
  6073. }
  6074. }
  6075. }
  6076. }
  6077. // Fill other period by MaxProfile
  6078. if(maxProfile.id != -1)
  6079. {
  6080. if(compositePeriodIdx==0)
  6081. {
  6082. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  6083. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  6084. {
  6085. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6086. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6087. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6088. {
  6089. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6090. {
  6091. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6092. compositePeriodIdx++;
  6093. }
  6094. else
  6095. {
  6096. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6097. }
  6098. }
  6099. }
  6100. }
  6101. else
  6102. {
  6103. int lastCompositePeriodIdx = compositePeriodIdx;
  6104. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6105. {
  6106. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6107. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6108. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6109. {
  6110. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  6111. {
  6112. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  6113. {
  6114. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6115. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6116. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  6117. }
  6118. else
  6119. {
  6120. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6121. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6122. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  6123. }
  6124. }
  6125. if(tmpPeriod.limit != -1)
  6126. {
  6127. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  6128. {
  6129. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  6130. {
  6131. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6132. compositePeriodIdx++;
  6133. }
  6134. else
  6135. {
  6136. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6137. }
  6138. }
  6139. // Delete duplicate period
  6140. if(compositePeriodIdx > 1)
  6141. {
  6142. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6143. {
  6144. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6145. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6146. compositePeriodIdx -= 1;
  6147. }
  6148. }
  6149. }
  6150. }
  6151. }
  6152. }
  6153. }
  6154. if(compositeProfile.chargingSchedule[idxSchedule].duration < durationReq)
  6155. {
  6156. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6157. {
  6158. if((idxPeriod >= 0) && (compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1))
  6159. {
  6160. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = compositeProfile.chargingSchedule[idxSchedule].duration;
  6161. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  6162. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].numberPhases;
  6163. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  6164. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6165. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6166. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6167. DEBUG_INFO("------------------------------------------------\n");
  6168. break;
  6169. }
  6170. }
  6171. }
  6172. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  6173. DEBUG_INFO("Connector-%d composite schedule ready.\n", evseId);
  6174. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  6175. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  6176. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  6177. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6178. {
  6179. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  6180. {
  6181. compositeProfile.id = 1;
  6182. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6183. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6184. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6185. }
  6186. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  6187. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  6188. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  6189. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  6190. }
  6191. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  6192. if(line)
  6193. free(line);
  6194. ShmOCPP20Data->CSUMsg.bits[(evseId==0?0:evseId-1)].ChargingProfileConf = ON;
  6195. }
  6196. //==========================================
  6197. // Init all share memory
  6198. //==========================================
  6199. int InitShareMemory()
  6200. {
  6201. int result = PASS;
  6202. int MeterSMId;
  6203. //creat ShmSysConfigAndInfo
  6204. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  6205. {
  6206. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  6207. result = FAIL;
  6208. }
  6209. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6210. {
  6211. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  6212. result = FAIL;
  6213. }
  6214. else
  6215. {}
  6216. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  6217. {
  6218. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  6219. result = FAIL;
  6220. }
  6221. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6222. {
  6223. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  6224. result = FAIL;
  6225. }
  6226. else
  6227. {}
  6228. //creat ShmPsuData
  6229. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  6230. {
  6231. DEBUG_ERROR("shmget ShmPsuData NG\n");
  6232. result = FAIL;
  6233. }
  6234. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6235. {
  6236. DEBUG_ERROR("shmat ShmPsuData NG\n");
  6237. result = FAIL;
  6238. }
  6239. else
  6240. {}
  6241. //creat ShmOCPP20Data
  6242. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  6243. {
  6244. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  6245. result = FAIL;
  6246. }
  6247. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6248. {
  6249. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  6250. result = FAIL;
  6251. }
  6252. else
  6253. {}
  6254. /****************************** For Initial Settings************************************************/
  6255. /*
  6256. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  6257. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  6258. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  6259. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  6260. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  6261. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  6262. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  6263. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  6264. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  6265. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  6266. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  6267. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  6268. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  6269. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  6270. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  6271. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  6272. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  6273. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  6274. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  6275. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  6276. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  6277. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  6278. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  6279. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  6280. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  6281. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  6282. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  6283. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  6284. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  6285. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  6286. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  6287. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  6288. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  6289. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  6290. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  6291. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  6292. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  6293. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  6294. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  6295. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  6296. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  6297. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  6298. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  6299. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  6300. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  6301. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  6302. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  6303. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  6304. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  6305. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  6306. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  6307. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  6308. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  6309. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  6310. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  6311. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  6312. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  6313. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  6314. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  6315. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  6316. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  6317. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  6318. */
  6319. return result;
  6320. }
  6321. int ProcessShareMemory()
  6322. {
  6323. int result = PASS;
  6324. if(InitShareMemory() == FAIL)
  6325. {
  6326. DEBUG_ERROR("InitShareMemory NG\n");
  6327. if(ShmStatusCodeData!=NULL)
  6328. {
  6329. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  6330. }
  6331. result = FAIL;
  6332. }
  6333. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  6334. {
  6335. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  6336. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6337. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  6338. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  6339. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  6340. ) // 'D' means DC
  6341. {
  6342. // DO series
  6343. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  6344. {
  6345. gunTotalNumber += 1;
  6346. gunType[gun_index] = GUN_TYPE_DO;
  6347. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6348. {
  6349. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  6350. {
  6351. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6352. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6353. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  6354. }
  6355. }
  6356. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6357. {
  6358. case Gun_Type_Chademo:
  6359. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  6360. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  6361. {
  6362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6363. {
  6364. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6365. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6366. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  6367. }
  6368. }
  6369. break;
  6370. case Gun_Type_CCS_2:
  6371. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  6372. for (int index = 0; index < CCS_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6375. {
  6376. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6377. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6378. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  6379. }
  6380. }
  6381. break;
  6382. case Gun_Type_GB:
  6383. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  6384. for (int index = 0; index < GB_QUANTITY; index++)
  6385. {
  6386. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6387. {
  6388. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6389. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6390. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  6391. }
  6392. }
  6393. break;
  6394. case Gun_Type_AC:
  6395. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  6396. for (int index = 0; index < AC_QUANTITY; index++)
  6397. {
  6398. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6399. {
  6400. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6401. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6402. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  6403. }
  6404. }
  6405. break;
  6406. default:
  6407. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  6408. break;
  6409. }
  6410. }
  6411. }
  6412. else
  6413. {
  6414. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  6415. {
  6416. gunTotalNumber += 1;
  6417. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6418. {
  6419. case Gun_Type_Chademo:
  6420. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  6421. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  6422. break;
  6423. case Gun_Type_CCS_2:
  6424. gunType[gun_index] = GUN_TYPE_CCS;
  6425. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  6426. break;
  6427. case Gun_Type_GB:
  6428. gunType[gun_index] = GUN_TYPE_GBT;
  6429. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  6430. break;
  6431. case Gun_Type_AC:
  6432. gunType[gun_index] = GUN_TYPE_AC;
  6433. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  6434. break;
  6435. default:
  6436. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  6437. break;
  6438. }
  6439. }
  6440. }
  6441. }
  6442. else
  6443. {
  6444. DEBUG_ERROR("Model name parsing fail.\n");
  6445. result = FAIL;
  6446. }
  6447. if(result != PASS)sleep(5);
  6448. return result;
  6449. }
  6450. //---------------------common routine---------------------------//
  6451. void checkNetworkProfile(void)
  6452. {
  6453. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  6454. json_object *priority;
  6455. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  6456. if(!is_error(priority))
  6457. {
  6458. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  6459. {
  6460. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  6461. {
  6462. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  6463. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  6464. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  6465. {
  6466. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  6467. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  6468. break;
  6469. }
  6470. }
  6471. }
  6472. }
  6473. json_object_put(priority);
  6474. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  6475. }
  6476. void checkRemoteStart(uint8_t evseIdx)
  6477. {
  6478. uint8_t tempIndex;
  6479. int isAllowStart = TRUE;
  6480. char cmdBuf[512];
  6481. //check Transaction active
  6482. if(gunType[evseIdx-1] == GUN_TYPE_CHAdeMO)
  6483. {
  6484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6485. {
  6486. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6487. }
  6488. else
  6489. {
  6490. tempIndex = (evseIdx-1);
  6491. }
  6492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6495. {
  6496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6497. {
  6498. //Reserved
  6499. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  6500. }
  6501. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6502. {
  6503. //Reserved
  6504. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  6505. isAllowStart = FALSE;
  6506. }
  6507. else
  6508. {
  6509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6510. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6511. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6512. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6513. {
  6514. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  6515. isAllowStart = FALSE;
  6516. }
  6517. }//END FOR ELSE
  6518. }
  6519. }// END FOR CHAdeMO_QUANTITY
  6520. }
  6521. else if(gunType[evseIdx-1] == GUN_TYPE_CCS)
  6522. {
  6523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6524. {
  6525. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6526. }
  6527. else
  6528. {
  6529. tempIndex = (evseIdx-1);
  6530. }
  6531. for (int index = 0; index < CCS_QUANTITY; index++)
  6532. {
  6533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6534. {
  6535. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6536. {
  6537. //Reserved
  6538. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  6539. }
  6540. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6541. {
  6542. //Reserved
  6543. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  6544. isAllowStart = FALSE;
  6545. }
  6546. else
  6547. {
  6548. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6549. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6550. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6551. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6552. {
  6553. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  6554. isAllowStart = FALSE;
  6555. }
  6556. }// END FOR ELSE
  6557. }
  6558. }// END FOR CCS_QUANTITY
  6559. }
  6560. else if(gunType[evseIdx-1] == GUN_TYPE_GBT)
  6561. {
  6562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6563. {
  6564. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6565. }
  6566. else
  6567. {
  6568. tempIndex = (evseIdx-1);
  6569. }
  6570. for (int index = 0; index < GB_QUANTITY; index++)
  6571. {
  6572. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6573. {
  6574. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6575. {
  6576. //Reserved
  6577. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6578. }
  6579. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6580. {
  6581. //Reserved
  6582. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6583. isAllowStart = FALSE;
  6584. }
  6585. else
  6586. {
  6587. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6588. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6589. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6590. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6591. {
  6592. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6593. isAllowStart = FALSE;
  6594. }
  6595. }// END FOR ELSE
  6596. }
  6597. } // END FOR GB_QUANTITY
  6598. }
  6599. else if(gunType[evseIdx-1] == GUN_TYPE_DO)
  6600. {
  6601. tempIndex = (evseIdx-1);
  6602. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6605. {
  6606. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6607. {
  6608. //Reserved
  6609. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6610. }
  6611. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6612. {
  6613. //Reserved
  6614. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6615. isAllowStart = FALSE;
  6616. }
  6617. else
  6618. {
  6619. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6620. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6621. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6622. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6623. {
  6624. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6625. isAllowStart = FALSE;
  6626. }
  6627. }// END FOR ELSE
  6628. }
  6629. } // END FOR GB_QUANTITY
  6630. }
  6631. else
  6632. {
  6633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6634. {
  6635. tempIndex = 2;
  6636. }
  6637. else
  6638. {
  6639. tempIndex = (evseIdx-1);
  6640. }
  6641. for (int index = 0; index < AC_QUANTITY; index++)
  6642. {
  6643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6644. {
  6645. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6646. {
  6647. //Reserved
  6648. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6649. }
  6650. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6651. {
  6652. //Reserved
  6653. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6654. isAllowStart = FALSE;
  6655. }
  6656. else
  6657. {
  6658. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6659. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6660. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6661. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6662. {
  6663. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6664. isAllowStart = FALSE;
  6665. }
  6666. }//END FOR ELSE
  6667. }
  6668. }// END FOR AC_QUANTITY
  6669. }
  6670. if(isAllowStart == TRUE)
  6671. {
  6672. if(ShmOCPP20Data->RequestStartTransaction[evseIdx -1].chargingProfile.id > 0)
  6673. {
  6674. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6675. {
  6676. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdx);
  6677. system(cmdBuf);
  6678. }
  6679. }
  6680. ShmOCPP20Data->CsMsg.bits[evseIdx-1].RequestStartTransactionReq = ON;
  6681. }
  6682. }
  6683. void CheckSystemValue(void)
  6684. {
  6685. char filenmae[100]={0};
  6686. char str[100]={0};
  6687. int tempIndex = 0;
  6688. //===============================
  6689. // EVSE operation check
  6690. //===============================
  6691. //===============================
  6692. // Heartbeat check
  6693. //===============================
  6694. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6695. {
  6696. //parameter for test
  6697. sendHeartbeatRequest(0);
  6698. //==============================================
  6699. // Reset Waiting Time
  6700. //==============================================
  6701. HeartBeatWithNOResponse += 1;
  6702. }
  6703. //===============================
  6704. // CSU Trigger Authorize Request
  6705. //===============================
  6706. if(isWebsocketSendable &&
  6707. (server_sign == TRUE) &&
  6708. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6709. (authorizeRetryTimes < 3))
  6710. {
  6711. sendAuthorizeRequest(0);
  6712. authorizeRetryTimes = authorizeRetryTimes + 1;
  6713. if(authorizeRetryTimes < 3)
  6714. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6715. }
  6716. else if((server_sign == TRUE) &&
  6717. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6718. (authorizeRetryTimes >= 3))
  6719. {
  6720. authorizeRetryTimes = 0;
  6721. SetOcppConnStatus(FALSE);
  6722. server_sign = FALSE;
  6723. }
  6724. else if((server_sign == FALSE) &&
  6725. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6726. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6727. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6728. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6729. {
  6730. sendAuthorizeRequest(0);
  6731. }
  6732. //===============================
  6733. // NotifyMonitoringReportRequest
  6734. //===============================
  6735. if(isWebsocketSendable &&
  6736. (server_sign == TRUE) &&
  6737. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6738. {
  6739. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6740. {
  6741. if((strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0) ||
  6742. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0) ||
  6743. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0))
  6744. {
  6745. /*for(uint8_t idxVarMonitoring=0; idxVarMonitoring<10; idxVarMonitoring++)
  6746. {
  6747. if(strcmp((char*)ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].variableMonitoring[idxVarMonitoring].type, (char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion]))
  6748. {
  6749. strcpy(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxVarMonitoring].component, ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].
  6750. }
  6751. }*/
  6752. }
  6753. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6754. {
  6755. /*
  6756. * TODO:
  6757. * 1. Report component that are ThresholdMonitoring
  6758. */
  6759. }
  6760. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6761. {
  6762. /*
  6763. * TODO:
  6764. * 1. Report component that are DeltaMonitoring
  6765. */
  6766. }
  6767. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6768. {
  6769. /*
  6770. * TODO:
  6771. * 1. Report component that are PeriodicMonitoring
  6772. */
  6773. }
  6774. else
  6775. {
  6776. /*
  6777. * TODO:
  6778. * 1. Process unknown criteria condition
  6779. */
  6780. }
  6781. }
  6782. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6783. }
  6784. if(isWebsocketSendable &&
  6785. (server_sign == TRUE) &&
  6786. (ShmOCPP20Data->GetReport.requestId > 0))
  6787. {
  6788. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6789. {
  6790. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6791. {
  6792. /*
  6793. * TODO:
  6794. * 1. Report component that are active
  6795. */
  6796. }
  6797. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6798. {
  6799. /*
  6800. * TODO:
  6801. * 1. Report component that are available
  6802. */
  6803. }
  6804. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6805. {
  6806. /*
  6807. * TODO:
  6808. * 1. Report component that are enable
  6809. */
  6810. }
  6811. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6812. {
  6813. /*
  6814. * TODO:
  6815. * 1. Report component that are problem
  6816. */
  6817. }
  6818. else
  6819. {
  6820. /*
  6821. * TODO:
  6822. * 1. Process unknown criteria condition
  6823. */
  6824. }
  6825. }
  6826. ShmOCPP20Data->GetReport.requestId = 0;
  6827. }
  6828. if(isWebsocketSendable &&
  6829. (server_sign == TRUE) &&
  6830. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6831. {
  6832. uint8_t reportIdx = 0;
  6833. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6834. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6835. {
  6836. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6837. {
  6838. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6839. {
  6840. 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))
  6841. {
  6842. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6843. reportIdx++;
  6844. }
  6845. }
  6846. else
  6847. {
  6848. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6849. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6850. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6851. else
  6852. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6853. sendNotifyReportRequest();
  6854. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6855. reportIdx = 0;
  6856. idx_var--;
  6857. }
  6858. }
  6859. }
  6860. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6861. {
  6862. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6863. {
  6864. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6865. {
  6866. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6867. reportIdx++;
  6868. }
  6869. else
  6870. {
  6871. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6872. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6873. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6874. else
  6875. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6876. sendNotifyReportRequest();
  6877. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6878. reportIdx = 0;
  6879. idx_var--;
  6880. }
  6881. }
  6882. }
  6883. else
  6884. {
  6885. /*
  6886. * TODO:
  6887. * 1. Fill out summary inventory to response message, currently not support
  6888. */
  6889. }
  6890. if(reportIdx > 0)
  6891. {
  6892. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6893. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6894. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6895. else
  6896. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6897. sendNotifyReportRequest();
  6898. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6899. reportIdx = 0;
  6900. }
  6901. ShmOCPP20Data->GetBaseReport.requestId = 0;
  6902. }
  6903. if(isWebsocketSendable &&
  6904. (server_sign == TRUE) &&
  6905. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  6906. {
  6907. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  6908. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  6909. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  6910. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  6911. else
  6912. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  6913. sendNotifyEventRequest();
  6914. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  6915. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  6916. }
  6917. if(isWebsocketSendable &&
  6918. (server_sign == TRUE) &&
  6919. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  6920. {
  6921. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  6922. {
  6923. /*
  6924. * TODO:
  6925. * 1.
  6926. */
  6927. }
  6928. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  6929. {
  6930. /*
  6931. * TODO:
  6932. * 1.
  6933. */
  6934. }
  6935. else
  6936. {
  6937. /*
  6938. * TODO:
  6939. * 1.
  6940. */
  6941. }
  6942. sendGet15118EVCertificateRequest();
  6943. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  6944. }
  6945. if(isWebsocketSendable &&
  6946. (server_sign == TRUE) &&
  6947. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  6948. {
  6949. sendSecurityEventNotificationRequest();
  6950. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  6951. }
  6952. if(isWebsocketSendable &&
  6953. (server_sign == TRUE) &&
  6954. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  6955. {
  6956. sendNotifyCustomerInformationRequest();
  6957. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  6958. }
  6959. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6960. {
  6961. // ClockAlign MeterValue
  6962. 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))
  6963. {
  6964. //check Transaction active
  6965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6966. {
  6967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6968. {
  6969. tempIndex = ((gun_index==2) ? 1: 0);
  6970. }
  6971. else
  6972. {
  6973. tempIndex = gun_index;
  6974. }
  6975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6976. {
  6977. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6978. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6979. {
  6980. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6981. }
  6982. }// End for CHAdeMO
  6983. }
  6984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6985. {
  6986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6987. {
  6988. tempIndex = ((gun_index==2) ? 1: 0);
  6989. }
  6990. else
  6991. {
  6992. tempIndex = gun_index;
  6993. }
  6994. for (int index = 0; index < CCS_QUANTITY; index++)
  6995. {
  6996. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6997. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6998. {
  6999. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7000. }
  7001. } // End for CCS
  7002. }
  7003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7006. {
  7007. tempIndex = ((gun_index==2) ? 1: 0);
  7008. }
  7009. else
  7010. {
  7011. tempIndex = gun_index;
  7012. }
  7013. for (int index = 0; index < GB_QUANTITY; index++)
  7014. {
  7015. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7016. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7017. {
  7018. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7019. }
  7020. }// End for GB
  7021. }
  7022. else if(gunType[gun_index] == GUN_TYPE_DO)
  7023. {
  7024. tempIndex = gun_index;
  7025. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7026. {
  7027. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7028. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7029. {
  7030. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7031. }
  7032. }
  7033. }
  7034. else
  7035. {
  7036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7037. {
  7038. tempIndex = 2;
  7039. }
  7040. else
  7041. {
  7042. tempIndex = gun_index;
  7043. }
  7044. for (int index = 0; index < AC_QUANTITY; index++)
  7045. {
  7046. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7047. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7048. {
  7049. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7050. }
  7051. }//End for AC
  7052. }
  7053. }
  7054. }
  7055. //===============================
  7056. // Each connector operation check
  7057. //===============================
  7058. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  7059. {
  7060. //==========================================
  7061. // Check remote start without connector id
  7062. //==========================================
  7063. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  7064. {
  7065. int evseIdInt = -1;
  7066. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  7067. {
  7068. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  7069. {
  7070. evseIdInt = (gun_index+1);
  7071. DEBUG_INFO("Detect connector of evse-%02d connected ready to start.\n", evseIdInt);
  7072. checkRemoteStart(evseIdInt);
  7073. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7074. break;
  7075. }
  7076. }
  7077. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  7078. {
  7079. DEBUG_WARN("Remote start request without evse id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  7080. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7081. }
  7082. }
  7083. //==========================================
  7084. // csu trigger DataTransferReq
  7085. //==========================================
  7086. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  7087. {
  7088. sendDataTransferRequest(gun_index);
  7089. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  7090. }
  7091. //==============================================
  7092. // Charger status notification & Transaction event report
  7093. //==============================================
  7094. //--- Check Mode Change ---//
  7095. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7097. {
  7098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7099. {
  7100. tempIndex = ((gun_index==2) ? 1: 0);
  7101. }
  7102. else
  7103. {
  7104. tempIndex = gun_index;
  7105. }
  7106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7107. {
  7108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7109. {
  7110. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  7111. {
  7112. //if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7113. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7114. /*if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7115. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7116. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7117. {
  7118. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7119. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7120. else
  7121. {
  7122. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7123. {
  7124. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7125. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7126. }
  7127. }
  7128. }*/
  7129. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  7130. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  7131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7132. {
  7133. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7134. if((access(filenmae,F_OK))!=-1)
  7135. {
  7136. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7137. sprintf(str,"rm -f %s",filenmae);
  7138. system(str);
  7139. }
  7140. }
  7141. }
  7142. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7143. #if 1 // for TempStopTransaction
  7144. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7145. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7146. {
  7147. checkTempStopTransaction(gun_index);
  7148. }
  7149. #endif
  7150. }
  7151. }
  7152. }
  7153. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7154. {
  7155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7156. {
  7157. tempIndex = ((gun_index==2) ? 1: 0);
  7158. }
  7159. else
  7160. {
  7161. tempIndex = gun_index;
  7162. }
  7163. for (int index = 0; index < CCS_QUANTITY; index++)
  7164. {
  7165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7166. {
  7167. 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]*/ )
  7168. {
  7169. //if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7170. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7171. /*if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7172. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7173. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7174. {
  7175. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7176. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7177. else
  7178. {
  7179. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7180. {
  7181. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7182. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7183. }
  7184. }
  7185. }*/
  7186. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  7187. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  7188. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7189. {
  7190. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7191. if((access(filenmae,F_OK))!=-1)
  7192. {
  7193. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7194. sprintf(str,"rm -f %s",filenmae);
  7195. system(str);
  7196. }
  7197. }
  7198. }
  7199. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7200. #if 1 // for TempStopTransaction
  7201. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7202. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7203. {
  7204. checkTempStopTransaction(gun_index);
  7205. }
  7206. #endif
  7207. }
  7208. }
  7209. }
  7210. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7211. {
  7212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7213. {
  7214. tempIndex = ((gun_index==2) ? 1: 0);
  7215. }
  7216. else
  7217. {
  7218. tempIndex = gun_index;
  7219. }
  7220. for (int index = 0; index < GB_QUANTITY; index++)
  7221. {
  7222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7223. {
  7224. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  7225. {
  7226. //if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7227. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7228. /*if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7229. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7230. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]))
  7231. {
  7232. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7233. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7234. else
  7235. {
  7236. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7237. {
  7238. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7239. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7240. }
  7241. }
  7242. }*/
  7243. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  7244. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  7245. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7246. {
  7247. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7248. if((access(filenmae,F_OK))!=-1)
  7249. {
  7250. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7251. sprintf(str,"rm -f %s",filenmae);
  7252. system(str);
  7253. }
  7254. }
  7255. }
  7256. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7257. #if 1 // for TempStopTransaction
  7258. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7259. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7260. {
  7261. checkTempStopTransaction(gun_index);
  7262. }
  7263. #endif
  7264. }
  7265. }
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_DO)
  7268. {
  7269. tempIndex = gun_index;
  7270. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7271. {
  7272. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7273. {
  7274. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  7275. {
  7276. //if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_AUTHORIZING)
  7277. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7278. /*if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  7279. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  7280. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]))
  7281. {
  7282. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  7283. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7284. else
  7285. {
  7286. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7287. {
  7288. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7289. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7290. }
  7291. }
  7292. }*/
  7293. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  7294. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  7295. 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
  7296. {
  7297. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7298. if((access(filenmae,F_OK))!=-1)
  7299. {
  7300. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7301. sprintf(str,"rm -f %s",filenmae);
  7302. system(str);
  7303. }
  7304. }
  7305. }
  7306. 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);
  7307. #if 1 // for TempStopTransaction
  7308. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  7309. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7310. {
  7311. checkTempStopTransaction(gun_index);
  7312. }
  7313. #endif
  7314. }
  7315. }
  7316. }
  7317. else
  7318. {
  7319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7320. {
  7321. tempIndex = 2;
  7322. }
  7323. else
  7324. {
  7325. tempIndex = gun_index;
  7326. }
  7327. for (int index = 0; index < AC_QUANTITY; index++)
  7328. {
  7329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7330. {
  7331. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  7332. {
  7333. //if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7334. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7335. /*if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7336. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7337. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) && (AcPreviousSystemStatus[index] != 99))
  7338. {
  7339. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7340. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7341. else
  7342. {
  7343. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7344. {
  7345. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7346. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7347. }
  7348. }
  7349. }*/
  7350. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  7351. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  7352. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7353. {
  7354. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7355. if((access(filenmae,F_OK))!=-1)
  7356. {
  7357. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7358. sprintf(str,"rm -f %s",filenmae);
  7359. system(str);
  7360. }
  7361. }
  7362. }
  7363. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7364. #if 1 // for TempStopTransaction
  7365. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7366. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7367. {
  7368. checkTempStopTransaction(gun_index);
  7369. }
  7370. #endif
  7371. }
  7372. }// END
  7373. }
  7374. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  7375. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  7376. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  7377. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  7378. {
  7379. sendStatusNotificationRequest(gun_index);
  7380. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  7381. }
  7382. //==============================================
  7383. // CSU Trigger or timer timeout refresh Smart Charging Profile
  7384. //==============================================
  7385. if((ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON) ||
  7386. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value))))
  7387. {
  7388. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  7389. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  7390. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  7391. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  7392. }
  7393. //==============================================
  7394. // CSU transaction event
  7395. //==============================================
  7396. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  7397. {
  7398. sendTransactionEventRequest(gun_index);
  7399. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  7400. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  7401. //storeTempStopTransaction(gun_index);
  7402. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  7403. }
  7404. //==============================================
  7405. // Meter report
  7406. //==============================================
  7407. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  7408. {
  7409. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger, FALSE);
  7410. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  7411. }
  7412. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  7413. {
  7414. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock, FALSE);
  7415. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  7416. }
  7417. // Sample period MeterValue
  7418. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0) &&
  7419. (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)))
  7420. {
  7421. //check Transaction active
  7422. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7423. {
  7424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7425. {
  7426. tempIndex = ((gun_index==2) ? 1: 0);
  7427. }
  7428. else
  7429. {
  7430. tempIndex = gun_index;
  7431. }
  7432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7433. {
  7434. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7435. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7436. {
  7437. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7438. {
  7439. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7440. }
  7441. }
  7442. }// End for CHAdeMO
  7443. }
  7444. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7445. {
  7446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7447. {
  7448. tempIndex = ((gun_index==2) ? 1: 0);
  7449. }
  7450. else
  7451. {
  7452. tempIndex = gun_index;
  7453. }
  7454. for (int index = 0; index < CCS_QUANTITY; index++)
  7455. {
  7456. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7457. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7458. {
  7459. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7460. {
  7461. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7462. }
  7463. }
  7464. } // End for CCS
  7465. }
  7466. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7467. {
  7468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7469. {
  7470. tempIndex = ((gun_index==2) ? 1: 0);
  7471. }
  7472. else
  7473. {
  7474. tempIndex = gun_index;
  7475. }
  7476. for (int index = 0; index < GB_QUANTITY; index++)
  7477. {
  7478. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7479. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7480. {
  7481. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7482. {
  7483. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7484. }
  7485. }
  7486. }// End for GB
  7487. }
  7488. else if(gunType[gun_index] == GUN_TYPE_DO)
  7489. {
  7490. tempIndex = gun_index;
  7491. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7492. {
  7493. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7494. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7495. {
  7496. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7497. {
  7498. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7499. }
  7500. }
  7501. }
  7502. }
  7503. else
  7504. {
  7505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7506. {
  7507. tempIndex = 2;
  7508. }
  7509. else
  7510. {
  7511. tempIndex = gun_index;
  7512. }
  7513. for (int index = 0; index < AC_QUANTITY; index++)
  7514. {
  7515. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7516. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7517. {
  7518. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7519. {
  7520. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7521. }
  7522. }
  7523. }//End for AC
  7524. }
  7525. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7526. {
  7527. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7528. {
  7529. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, FALSE);
  7530. }
  7531. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7532. }
  7533. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  7534. }
  7535. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value) > 0) &&
  7536. (getDiffSecNow(clientTime.SampledDataTxEnded[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value)>3)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value)- 1):3)))
  7537. {
  7538. //check Transaction active
  7539. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7540. {
  7541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7542. {
  7543. tempIndex = ((gun_index==2) ? 1: 0);
  7544. }
  7545. else
  7546. {
  7547. tempIndex = gun_index;
  7548. }
  7549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7550. {
  7551. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7552. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7553. {
  7554. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7555. {
  7556. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7557. }
  7558. }
  7559. }// End for CHAdeMO
  7560. }
  7561. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7562. {
  7563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7564. {
  7565. tempIndex = ((gun_index==2) ? 1: 0);
  7566. }
  7567. else
  7568. {
  7569. tempIndex = gun_index;
  7570. }
  7571. for (int index = 0; index < CCS_QUANTITY; index++)
  7572. {
  7573. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7574. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7575. {
  7576. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7577. {
  7578. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7579. }
  7580. }
  7581. } // End for CCS
  7582. }
  7583. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7584. {
  7585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7586. {
  7587. tempIndex = ((gun_index==2) ? 1: 0);
  7588. }
  7589. else
  7590. {
  7591. tempIndex = gun_index;
  7592. }
  7593. for (int index = 0; index < GB_QUANTITY; index++)
  7594. {
  7595. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7596. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7597. {
  7598. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7599. {
  7600. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7601. }
  7602. }
  7603. }// End for GB
  7604. }
  7605. else if(gunType[gun_index] == GUN_TYPE_DO)
  7606. {
  7607. tempIndex = gun_index;
  7608. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7609. {
  7610. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7611. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7612. {
  7613. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7614. {
  7615. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7616. }
  7617. }
  7618. }
  7619. }
  7620. else
  7621. {
  7622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7623. {
  7624. tempIndex = 2;
  7625. }
  7626. else
  7627. {
  7628. tempIndex = gun_index;
  7629. }
  7630. for (int index = 0; index < AC_QUANTITY; index++)
  7631. {
  7632. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7633. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7634. {
  7635. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7636. {
  7637. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7638. }
  7639. }
  7640. }//End for AC
  7641. }
  7642. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7643. {
  7644. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7645. {
  7646. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, TRUE);
  7647. }
  7648. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7649. }
  7650. refreshStartTimer(&clientTime.SampledDataTxEnded[gun_index]);
  7651. }
  7652. //==============================================
  7653. // Check Connector reserved
  7654. //==============================================
  7655. //===============================
  7656. // Check if Reserve is expired
  7657. //===============================
  7658. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  7659. {
  7660. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  7661. {
  7662. DEBUG_INFO("reserve expired.\n");
  7663. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  7664. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  7665. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  7666. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  7667. }
  7668. }//END OF Check if Reserve is expired
  7669. //==========================================
  7670. // csu trigger FirmwareStatusNotificationReq
  7671. //==========================================
  7672. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  7673. {
  7674. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  7675. }
  7676. //==========================================
  7677. // csu cleared charging limit request
  7678. //==========================================
  7679. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  7680. {
  7681. sendClearedChargingLimitRequest(gun_index);
  7682. }
  7683. //==========================================
  7684. // csu trigger CancelReservationConf
  7685. //==========================================
  7686. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  7687. {
  7688. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  7689. }
  7690. //==========================================
  7691. // csu notify EV charging need request
  7692. //==========================================
  7693. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  7694. {
  7695. sendNotifyEVChargingNeedsRequest(gun_index);
  7696. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  7697. }
  7698. //==========================================
  7699. // csu notify EV charging schedule request
  7700. //==========================================
  7701. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  7702. {
  7703. sendNotifyEVChargingScheduleRequest(gun_index);
  7704. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  7705. }
  7706. //==========================================
  7707. // csu trigger ChangeAvailabilityConf
  7708. //==========================================
  7709. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  7710. {
  7711. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  7712. }
  7713. //==========================================
  7714. // csu trigger UnlockConnectorConf
  7715. //==========================================
  7716. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  7717. {
  7718. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  7719. }
  7720. //==========================================
  7721. // csu trigger ReserveNowConf
  7722. //==========================================
  7723. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  7724. {
  7725. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  7726. }
  7727. //==========================================
  7728. // csu trigger ReserveNowConf
  7729. //==========================================
  7730. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  7731. {
  7732. sendReservationStatusUpdateRequest(gun_index);
  7733. }
  7734. //==========================================
  7735. // csu trigger LogStatusNotificationReq
  7736. //==========================================
  7737. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  7738. {
  7739. if(isCancelUploadLog == TRUE)
  7740. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7741. else
  7742. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  7743. }
  7744. //==========================================
  7745. // csu trigger SignCertificateReq
  7746. //==========================================
  7747. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7748. {
  7749. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7750. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7751. {
  7752. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7753. }
  7754. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7755. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7756. {
  7757. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7758. }
  7759. }
  7760. }
  7761. }
  7762. //==========================================
  7763. // send request routine
  7764. //==========================================
  7765. int sendAuthorizeRequest(int gun_index)
  7766. {
  7767. mtrace();
  7768. int result = FAIL;
  7769. char message[4096]={0};
  7770. char guid[37];
  7771. char tempdata[128]={0};
  7772. json_object *Authorize = json_object_new_object();
  7773. json_object *idToken = json_object_new_object();
  7774. DEBUG_INFO("sendAuthorizeRequest...\n");
  7775. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7776. //Local Authorize
  7777. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7778. {
  7779. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7780. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7781. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7782. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7783. result = PASS;
  7784. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7785. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7786. authorizeRetryTimes = 0;
  7787. return result;
  7788. }
  7789. 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)) ||
  7790. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7791. {
  7792. // Query idtag from cache
  7793. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7794. // Query idtag from list
  7795. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7796. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7797. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7798. {
  7799. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7800. {
  7801. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7802. }
  7803. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7804. {
  7805. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7806. }
  7807. // Return authorize result if does not connect to server
  7808. if(!ShmOCPP20Data->OcppConnStatus)
  7809. {
  7810. DEBUG_INFO("Local Authorization Fail.\n");
  7811. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7812. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7813. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7814. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7815. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7816. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7817. authorizeRetryTimes = 0;
  7818. return result;
  7819. }
  7820. }
  7821. else
  7822. {
  7823. DEBUG_INFO("Local Authorization get result.\n");
  7824. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7825. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7826. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7827. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7828. else
  7829. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7830. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7831. result = PASS;
  7832. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7833. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7834. authorizeRetryTimes = 0;
  7835. return result;
  7836. }
  7837. }
  7838. //get data from shared memory
  7839. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7840. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  7841. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  7842. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  7843. {
  7844. memset(&ShmOCPP20Data->Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  7845. int parseCertResult = FAIL;
  7846. json_object *iso15118CertificateHashData = json_object_new_array();
  7847. // Read CERTIFICATE_PnCAuth file content
  7848. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  7849. {
  7850. memset(ShmOCPP20Data->Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.certificate));
  7851. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  7852. char *line = NULL;
  7853. size_t len = 0;
  7854. while(getline(&line, &len, fp) != -1)
  7855. {
  7856. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  7857. strcat((char *)ShmOCPP20Data->Authorize.certificate, line);
  7858. }
  7859. fclose(fp);
  7860. }
  7861. if(strlen((char*)ShmOCPP20Data->Authorize.certificate) > 0)
  7862. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  7863. char parseData[512] = {0};
  7864. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  7865. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  7866. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  7867. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  7868. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  7869. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  7870. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  7871. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  7872. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  7873. strcpy((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  7874. for(int idx=0; idx < 4; idx++)
  7875. {
  7876. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  7877. {
  7878. json_object *OCSPRequestDataType = json_object_new_object();
  7879. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  7880. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  7881. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  7882. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  7883. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  7884. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  7885. parseCertResult = PASS;
  7886. }
  7887. }
  7888. if(parseCertResult == PASS)
  7889. {
  7890. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  7891. }
  7892. else
  7893. {
  7894. sprintf((char*)ShmOCPP20Data->Authorize.Response_certificateStatus, "NoCertificateAvailable");
  7895. sprintf((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Invalid");
  7896. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON;
  7897. }
  7898. }
  7899. json_object_object_add(Authorize, "idToken", idToken);
  7900. random_uuid(guid);
  7901. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  7902. json_object_put(Authorize);
  7903. LWS_Send(message);
  7904. sprintf(tempdata, "Authorize,%d", gun_index);
  7905. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7906. {
  7907. result = PASS;
  7908. }
  7909. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7910. return result;
  7911. }
  7912. int sendBootNotificationRequest()
  7913. {
  7914. mtrace();
  7915. int result = FAIL;
  7916. char message[4096]={0};
  7917. char guid[37]={0};
  7918. char tempdata[128]={0};
  7919. json_object *BootNotification = json_object_new_object();
  7920. json_object *chargingStation = json_object_new_object();
  7921. json_object *modem = json_object_new_object();
  7922. DEBUG_INFO("sendBootNotificationRequest...\n");
  7923. // Fill BootNotification fields
  7924. DB_getBooType();
  7925. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  7926. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7927. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7928. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  7929. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  7930. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  7931. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  7932. {
  7933. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  7934. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  7935. json_object_object_add(chargingStation, "modem", modem);
  7936. }
  7937. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  7938. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  7939. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  7940. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  7941. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  7942. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  7943. random_uuid(guid);
  7944. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  7945. json_object_put(BootNotification);
  7946. LWS_Send(message);
  7947. sprintf(tempdata, "BootNotification,0");
  7948. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7949. {
  7950. result = PASS;
  7951. }
  7952. return result;
  7953. }
  7954. int sendClearedChargingLimitRequest(int gun_index)
  7955. {
  7956. mtrace();
  7957. int result = FAIL;
  7958. char message[4096]={0};
  7959. char guid[37]={0};
  7960. char tempdata[128]={0};
  7961. json_object *ClearedChargingLimit = json_object_new_object();
  7962. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  7963. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  7964. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  7965. random_uuid(guid);
  7966. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  7967. json_object_put(ClearedChargingLimit);
  7968. LWS_Send(message);
  7969. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  7970. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7971. {
  7972. result = PASS;
  7973. }
  7974. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  7975. return result;
  7976. }
  7977. int sendDataTransferRequest(int gun_index)
  7978. {
  7979. mtrace();
  7980. char message[1000]={0};
  7981. char guid[37]={0};
  7982. char tempdata[65]={0};
  7983. int result = FAIL;
  7984. DEBUG_INFO("sendDataTransferRequest...\n");
  7985. random_uuid(guid);
  7986. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  7987. MESSAGE_TYPE_CALL,
  7988. guid,
  7989. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  7990. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  7991. ShmOCPP20Data->DataTransfer[gun_index].data);
  7992. LWS_Send(message);
  7993. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  7994. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7995. {
  7996. result = PASS;
  7997. }
  7998. return result;
  7999. }
  8000. int sendFirmwareStatusNotificationRequest(char *status)
  8001. {
  8002. mtrace();
  8003. int result = FAIL;
  8004. char message[110]={0};
  8005. char guid[37]={0};
  8006. char tempdata[65]={0};
  8007. json_object *FirmwareStatusNotification = json_object_new_object();
  8008. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  8009. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  8010. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  8011. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  8012. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  8013. random_uuid(guid);
  8014. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8015. json_object_put(FirmwareStatusNotification);
  8016. LWS_SendNow(message);
  8017. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  8018. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8019. {
  8020. result = PASS;
  8021. }
  8022. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  8023. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  8024. //record status
  8025. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  8026. {
  8027. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  8028. }
  8029. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  8030. {
  8031. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  8032. }
  8033. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  8034. {
  8035. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  8036. }
  8037. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  8038. {
  8039. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  8040. }
  8041. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  8042. {
  8043. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  8044. }
  8045. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  8046. {
  8047. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  8048. }
  8049. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  8050. {
  8051. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  8052. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8053. }
  8054. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  8055. {
  8056. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  8057. }
  8058. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  8059. {
  8060. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  8061. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8062. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8063. }
  8064. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  8065. {
  8066. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  8067. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8068. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8069. }
  8070. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  8071. {
  8072. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  8073. }
  8074. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  8075. {
  8076. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  8077. }
  8078. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  8079. {
  8080. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  8081. }
  8082. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  8083. {
  8084. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  8085. }
  8086. return result;
  8087. }
  8088. int sendGet15118EVCertificateRequest()
  8089. {
  8090. mtrace();
  8091. int result = FAIL;
  8092. char message[4096]={0};
  8093. char guid[37]={0};
  8094. char tempdata[128]={0};
  8095. json_object *Get15118EVCertificate = json_object_new_object();
  8096. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  8097. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  8098. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  8099. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  8100. random_uuid(guid);
  8101. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  8102. json_object_put(Get15118EVCertificate);
  8103. LWS_Send(message);
  8104. sprintf(tempdata, "Get15118EVCertificate,0");
  8105. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8106. {
  8107. result = PASS;
  8108. }
  8109. return result;
  8110. }
  8111. int sendGetCertificateStatusRequest()
  8112. {
  8113. mtrace();
  8114. int result = FAIL;
  8115. char message[4096]={0};
  8116. char guid[37]={0};
  8117. char tempdata[128]={0};
  8118. json_object *GetCertificateStatus = json_object_new_object();
  8119. json_object *ocspRequestData = json_object_new_object();
  8120. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  8121. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  8122. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  8123. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  8124. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  8125. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  8126. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  8127. random_uuid(guid);
  8128. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  8129. json_object_put(GetCertificateStatus);
  8130. LWS_Send(message);
  8131. sprintf(tempdata, "GetCertificateStatus,0");
  8132. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8133. {
  8134. result = PASS;
  8135. }
  8136. return result;
  8137. }
  8138. int sendHeartbeatRequest()
  8139. {
  8140. mtrace();
  8141. int result = FAIL;
  8142. char message[40096]={0};
  8143. char guid[37]={0};
  8144. char tempdata[128]={0};
  8145. DEBUG_INFO("sendHeartbeatRequest...\n");
  8146. random_uuid(guid);
  8147. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  8148. , MESSAGE_TYPE_CALL
  8149. , guid );
  8150. LWS_Send(message);
  8151. sprintf(tempdata, "Heartbeat,%d", 0);
  8152. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8153. {
  8154. result = PASS;
  8155. }
  8156. return result;
  8157. }
  8158. int sendLogStatusNotificationRequest(char *status)
  8159. {
  8160. mtrace();
  8161. int result = FAIL;
  8162. char message[4096]={0};
  8163. char guid[37]={0};
  8164. char tempdata[128]={0};
  8165. json_object *LogStatusNotification = json_object_new_object();
  8166. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8167. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  8168. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  8169. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  8170. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  8171. random_uuid(guid);
  8172. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8173. json_object_put(LogStatusNotification);
  8174. LWS_SendNow(message);
  8175. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8176. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8177. {
  8178. result = PASS;
  8179. }
  8180. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  8181. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  8182. //record status
  8183. if(strcmp(status,"BadMessage")==0)
  8184. {
  8185. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  8186. }
  8187. else if(strcmp(status,"Idle")==0)
  8188. {
  8189. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  8190. }
  8191. else if(strcmp(status,"NotSupportedOperation")==0)
  8192. {
  8193. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  8194. }
  8195. else if(strcmp(status,"PermissionDenied")==0)
  8196. {
  8197. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  8198. }
  8199. else if(strcmp(status,"Uploaded")==0)
  8200. {
  8201. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  8202. }
  8203. else if(strcmp(status,"UploadFailure")==0)
  8204. {
  8205. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  8206. }
  8207. else if(strcmp(status,"Uploading")==0)
  8208. {
  8209. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  8210. }
  8211. return result;
  8212. }
  8213. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType, uint8_t isSampledDataTxEnd)
  8214. {
  8215. mtrace();
  8216. int result = FAIL;
  8217. char guid[37]={0};
  8218. char tempdata[65]={0};
  8219. int tempIndex = 0;
  8220. DEBUG_INFO("sendMeterValuesRequest...\n");
  8221. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  8222. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  8223. //set value
  8224. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  8225. //UTC Date time
  8226. struct timeval tmnow;
  8227. struct tm *tm;
  8228. char buf[28];//, usec_buf[6];
  8229. gettimeofday(&tmnow, NULL);
  8230. time_t t;
  8231. t = time(NULL);
  8232. /*UTC time and date*/
  8233. tm = gmtime(&t);
  8234. if(dataType == ReadingContextEnumType_Sample_Clock)
  8235. {
  8236. struct tm *tmTarget;
  8237. struct timeb tbTarget;
  8238. tbTarget.time = mktime(tm);
  8239. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  8240. tmTarget = gmtime(&tbTarget.time);
  8241. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  8242. }
  8243. else
  8244. {
  8245. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8246. }
  8247. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  8248. struct ChargingInfoData *targetChargingInfoData = getTargetChargingInfoData(gun_index);
  8249. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  8250. //idx_sample=0;
  8251. //********************************(1)Current.Import L1************************************************/
  8252. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8253. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8254. (dataType == ReadingContextEnumType_Trigger))
  8255. {
  8256. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8257. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrent*100))/100.0;
  8258. if(gunType[gun_index] == GUN_TYPE_AC)
  8259. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8260. else
  8261. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8262. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  8263. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8264. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8265. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  8266. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  8267. }
  8268. //idx_sample=1;
  8269. //********************************(2)Energy.Active.Import.Register ************************************************/
  8270. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8271. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8272. (dataType == ReadingContextEnumType_Trigger))
  8273. {
  8274. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8275. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(targetChargingInfoData->PowerConsumption*100))/100.0;
  8276. if(gunType[gun_index] == GUN_TYPE_AC)
  8277. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8278. else
  8279. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8280. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  8281. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  8282. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8283. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  8284. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8285. }
  8286. //idx_sample=2;
  8287. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  8288. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8289. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8290. (dataType == ReadingContextEnumType_Trigger))
  8291. {
  8292. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8293. if(dataType == ReadingContextEnumType_Sample_Clock)
  8294. {
  8295. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousClockPowerConsumption[gun_index]);
  8296. periousClockPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8297. }
  8298. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  8299. {
  8300. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  8301. periousPeriodicPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8302. }
  8303. else
  8304. {
  8305. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  8306. }
  8307. if(gunType[gun_index] == GUN_TYPE_AC)
  8308. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8309. else
  8310. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8311. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  8312. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  8313. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8314. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  8315. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8316. }
  8317. //idx_sample=3;
  8318. //********************************(4)Power.Active.Import************************************************/
  8319. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8320. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8321. (dataType == ReadingContextEnumType_Trigger))
  8322. {
  8323. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8324. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(targetChargingInfoData->PresentChargingPower*100))/100.0;
  8325. if(gunType[gun_index] == GUN_TYPE_AC)
  8326. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8327. else
  8328. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8329. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  8330. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  8331. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8332. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  8333. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  8334. }
  8335. //idx_sample=4;
  8336. //***********************************************(5)VOLTAGE L1******************************************************/
  8337. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8338. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8339. (dataType == ReadingContextEnumType_Trigger))
  8340. {
  8341. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8342. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltage*100))/100.0;
  8343. if(gunType[gun_index] == GUN_TYPE_AC)
  8344. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8345. else
  8346. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8347. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8348. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8349. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8350. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8351. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8352. }
  8353. //***********************************************(6)SOC******************************************************/
  8354. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8355. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8356. (dataType == ReadingContextEnumType_Trigger))
  8357. {
  8358. 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))
  8359. {
  8360. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = targetChargingInfoData->EvBatterySoc;
  8361. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8362. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8363. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8364. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8365. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8366. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8367. }
  8368. }
  8369. //********************************(7)Current.Import L2************************************************/
  8370. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8371. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8372. (dataType == ReadingContextEnumType_Trigger))
  8373. {
  8374. // Only for AC 3 phase
  8375. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8376. {
  8377. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL2*100))/100.0;
  8378. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8379. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8380. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8381. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8382. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8383. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8384. }
  8385. }
  8386. //********************************(8)Current.Import L3************************************************/
  8387. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8388. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8389. (dataType == ReadingContextEnumType_Trigger))
  8390. {
  8391. // Only for AC 3 phase
  8392. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8393. {
  8394. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL3*100))/100.0;
  8395. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8396. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8397. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8398. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8399. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8400. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8401. }
  8402. }
  8403. //***********************************************(9)VOLTAGE L2******************************************************/
  8404. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8405. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8406. (dataType == ReadingContextEnumType_Trigger))
  8407. {
  8408. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8409. {
  8410. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL2*100))/100.0;
  8411. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8412. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8413. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8414. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8415. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8416. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8417. }
  8418. }
  8419. //***********************************************(10)VOLTAGE L3******************************************************/
  8420. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8421. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8422. (dataType == ReadingContextEnumType_Trigger))
  8423. {
  8424. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8425. {
  8426. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL3*100))/100.0;
  8427. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8428. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8429. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8430. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8431. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8432. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8433. }
  8434. }
  8435. //***********************************************(11)Current.Offered******************************************************/
  8436. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8437. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8438. (dataType == ReadingContextEnumType_Trigger))
  8439. {
  8440. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8441. if(gunType[gun_index] == GUN_TYPE_AC)
  8442. {
  8443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8444. {
  8445. tempIndex = 2;
  8446. }
  8447. else
  8448. {
  8449. tempIndex = gun_index;
  8450. }
  8451. for (int index = 0; index < AC_QUANTITY; index++)
  8452. {
  8453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8454. {
  8455. uint16_t currentOffer;
  8456. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8457. {
  8458. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8459. }
  8460. else
  8461. {
  8462. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8463. }
  8464. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8465. }
  8466. }
  8467. }
  8468. else
  8469. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t)(targetChargingInfoData->AvailableChargingCurrent/10);
  8470. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8471. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8472. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8473. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8474. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8475. }
  8476. //***********************************************(12)Power.Offered******************************************************/
  8477. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8478. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8479. (dataType == ReadingContextEnumType_Trigger))
  8480. {
  8481. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8482. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t)(targetChargingInfoData->AvailableChargingPower*100);
  8483. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8484. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8485. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8486. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8487. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8488. }
  8489. // Message create ====================================================================================================
  8490. random_uuid(guid);
  8491. json_object *MeterValueReq = json_object_new_object();
  8492. json_object *meterValues = json_object_new_array();
  8493. json_object *sampledValues = json_object_new_array();
  8494. json_object *sampledValuesBuffer = json_object_new_array();
  8495. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8496. {
  8497. json_object *meterValue = json_object_new_object();
  8498. json_object *MeterValueBuffer = json_object_new_object();
  8499. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8500. {
  8501. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8502. {
  8503. json_object *sampledValue = json_object_new_object();
  8504. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8505. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8506. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8507. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8508. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8509. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8510. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8511. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8512. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8513. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8514. {
  8515. json_object *signedMeterValue = json_object_new_object();
  8516. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8517. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8518. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8519. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8520. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8521. }
  8522. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8523. {
  8524. json_object *unitOfMeasure = json_object_new_object();
  8525. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8526. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8527. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8528. }
  8529. json_object_array_add(sampledValues, sampledValue);
  8530. // For StopTxn data
  8531. if((isSampledDataTxEnd == TRUE) &&
  8532. (((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand ) != NULL) && (strlen((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value) > 0)) ||
  8533. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL) && (strlen((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value) > 0))))
  8534. {
  8535. json_object *sampledValue = json_object_new_object();
  8536. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8537. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8538. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8539. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8540. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8541. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8542. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8543. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8544. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8545. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8546. {
  8547. json_object *signedMeterValue = json_object_new_object();
  8548. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8549. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8550. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8551. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8552. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8553. }
  8554. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8555. {
  8556. json_object *unitOfMeasure = json_object_new_object();
  8557. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8558. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8559. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8560. }
  8561. json_object_array_add(sampledValuesBuffer, sampledValue);
  8562. }
  8563. }
  8564. }
  8565. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8566. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8567. json_object_array_add(meterValues, meterValue);
  8568. // For StopTxn data
  8569. if((isSampledDataTxEnd == TRUE) && (dataType != ReadingContextEnumType_Trigger) &&
  8570. (json_object_array_length(sampledValuesBuffer) > 0))
  8571. {
  8572. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8573. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  8574. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  8575. meterValueBufferInsert(gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8576. json_object_put(MeterValueBuffer);
  8577. }
  8578. else
  8579. {
  8580. json_object_put(sampledValuesBuffer);
  8581. json_object_put(MeterValueBuffer);
  8582. }
  8583. idxMeter++;
  8584. }
  8585. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8586. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8587. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8588. ,MESSAGE_TYPE_CALL
  8589. ,guid
  8590. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8591. json_object_put(MeterValueReq);
  8592. if((dataType != ReadingContextEnumType_Trigger) &&
  8593. (dataType != ReadingContextEnumType_Sample_Clock))
  8594. {
  8595. // Transaction meter value send by TransactionEvent message
  8596. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8597. if(isSampledDataTxEnd != TRUE)
  8598. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8599. result = PASS;
  8600. }
  8601. else
  8602. {
  8603. // Put request guid to hash map
  8604. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8605. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8606. {
  8607. result = PASS;
  8608. }
  8609. if((dataType != ReadingContextEnumType_Trigger) &&
  8610. (dataType != ReadingContextEnumType_Sample_Clock))
  8611. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8612. else
  8613. {
  8614. if(FirstHeartBeat)
  8615. LWS_Send(queuedata);
  8616. }
  8617. }
  8618. return result;
  8619. }
  8620. int sendNotifyChargingLimitRequest(int gun_index)
  8621. {
  8622. mtrace();
  8623. int result = FAIL;
  8624. char message[4096]={0};
  8625. char guid[37]={0};
  8626. char tempdata[128]={0};
  8627. json_object *NotifyChargingLimit = json_object_new_object();
  8628. json_object *chargingLimit = json_object_new_object();
  8629. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8630. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8631. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8632. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8633. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8634. random_uuid(guid);
  8635. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8636. json_object_put(NotifyChargingLimit);
  8637. LWS_Send(message);
  8638. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8639. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8640. {
  8641. result = PASS;
  8642. }
  8643. return result;
  8644. }
  8645. int sendNotifyCustomerInformationRequest()
  8646. {
  8647. mtrace();
  8648. int result = FAIL;
  8649. char message[4096]={0};
  8650. char guid[37]={0};
  8651. char tempdata[128]={0};
  8652. json_object *NotifyCustomerInformation = json_object_new_object();
  8653. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8654. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8655. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8656. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8657. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8658. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8659. random_uuid(guid);
  8660. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8661. json_object_put(NotifyCustomerInformation);
  8662. LWS_Send(message);
  8663. sprintf(tempdata, "NotifyCustomerInformation,0");
  8664. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8665. {
  8666. result = PASS;
  8667. }
  8668. return result;
  8669. }
  8670. int sendNotifyDisplayMessagesRequest()
  8671. {
  8672. mtrace();
  8673. int result = FAIL;
  8674. char message[4096]={0};
  8675. char guid[37]={0};
  8676. char tempdata[128]={0};
  8677. json_object *NotifyDisplayMessages = json_object_new_object();
  8678. json_object *messageInfos = json_object_new_array();
  8679. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8680. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8681. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8682. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8683. {
  8684. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8685. {
  8686. json_object *messageInfo = json_object_new_object();
  8687. json_object *message = json_object_new_object();
  8688. json_object *display = json_object_new_object();
  8689. json_object *evse = json_object_new_object();
  8690. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8691. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8692. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8693. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8694. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8695. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8696. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8697. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8698. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8699. json_object_object_add(messageInfo, "message", message);
  8700. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8701. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8702. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8703. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8704. json_object_object_add(display, "evse",evse);
  8705. json_object_object_add(messageInfo, "evse", display);
  8706. json_object_array_add(messageInfos, messageInfo);
  8707. }
  8708. }
  8709. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8710. random_uuid(guid);
  8711. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8712. json_object_put(NotifyDisplayMessages);
  8713. LWS_Send(message);
  8714. sprintf(tempdata, "NotifyDisplayMessages,0");
  8715. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8716. {
  8717. result = PASS;
  8718. }
  8719. return result;
  8720. }
  8721. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8722. {
  8723. mtrace();
  8724. int result = FAIL;
  8725. char message[4096]={0};
  8726. char guid[37]={0};
  8727. char tempdata[128]={0};
  8728. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8729. json_object *chargingNeeds = json_object_new_object();
  8730. json_object *acChargingParameters = json_object_new_object();
  8731. json_object *dcChargingParameters = json_object_new_object();
  8732. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8733. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8734. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8735. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8736. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8737. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8738. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8739. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8740. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8741. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8742. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8743. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8744. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8745. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8746. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8747. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8748. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8749. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8750. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8751. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8752. random_uuid(guid);
  8753. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8754. json_object_put(NotifyEVChargingNeeds);
  8755. LWS_Send(message);
  8756. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8757. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8758. {
  8759. result = PASS;
  8760. }
  8761. return result;
  8762. }
  8763. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8764. {
  8765. mtrace();
  8766. int result = FAIL;
  8767. char message[4096]={0};
  8768. char guid[37]={0};
  8769. char tempdata[128]={0};
  8770. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8771. json_object *chargingSchedule = json_object_new_object();
  8772. json_object *periods = json_object_new_array();
  8773. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8774. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8775. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8776. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8777. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8778. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8779. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8780. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8781. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8782. {
  8783. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8784. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8785. {
  8786. json_object *Period = json_object_new_object();
  8787. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8788. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8789. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8790. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8791. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8792. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8793. json_object_array_add(periods, Period);
  8794. }
  8795. }
  8796. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8797. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8798. random_uuid(guid);
  8799. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8800. json_object_put(NotifyEVChargingSchedule);
  8801. LWS_Send(message);
  8802. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8803. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8804. {
  8805. result = PASS;
  8806. }
  8807. return result;
  8808. }
  8809. int sendNotifyEventRequest()
  8810. {
  8811. mtrace();
  8812. int result = FAIL;
  8813. char message[4096]={0};
  8814. char guid[37]={0};
  8815. char tempdata[128]={0};
  8816. json_object *NotifyEvent = json_object_new_object();
  8817. json_object *eventDatas = json_object_new_array();
  8818. DEBUG_INFO("sendNotifyEventRequest...\n");
  8819. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8820. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8821. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8822. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8823. {
  8824. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8825. {
  8826. json_object *eventData = json_object_new_object();
  8827. json_object *component = json_object_new_object();
  8828. json_object *evse = json_object_new_object();
  8829. json_object *variable = json_object_new_object();
  8830. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8831. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8832. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8833. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8834. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8835. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8836. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8837. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8838. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8839. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8840. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8841. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8842. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8843. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8844. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8845. json_object_object_add(component, "evse",evse);
  8846. json_object_object_add(eventData, "component", component);
  8847. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8848. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8849. json_object_object_add(eventData, "variable", variable);
  8850. json_object_array_add(eventDatas, eventData);
  8851. }
  8852. }
  8853. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8854. random_uuid(guid);
  8855. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8856. json_object_put(NotifyEvent);
  8857. LWS_Send(message);
  8858. sprintf(tempdata, "NotifyEvent,0");
  8859. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8860. {
  8861. result = PASS;
  8862. }
  8863. return result;
  8864. }
  8865. int sendNotifyMonitoringReportRequest()
  8866. {
  8867. mtrace();
  8868. int result = FAIL;
  8869. char message[4096]={0};
  8870. char guid[37]={0};
  8871. char tempdata[128]={0};
  8872. json_object *NotifyMonitoringReport = json_object_new_object();
  8873. json_object *monitors = json_object_new_array();
  8874. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8875. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8876. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8877. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8878. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8879. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8880. {
  8881. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8882. {
  8883. json_object *monitor = json_object_new_object();
  8884. json_object *component = json_object_new_object();
  8885. json_object *evse = json_object_new_object();
  8886. json_object *variable = json_object_new_object();
  8887. json_object *variableMonitorings = json_object_new_array();
  8888. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8889. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8890. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8891. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8892. json_object_object_add(component, "evse",evse);
  8893. json_object_object_add(monitor, "component", component);
  8894. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8895. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8896. json_object_object_add(monitor, "variable", variable);
  8897. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8898. {
  8899. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8900. {
  8901. json_object *variableMonitoring = json_object_new_object();
  8902. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8903. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8904. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8905. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8906. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8907. json_object_array_add(variableMonitorings, variableMonitoring);
  8908. }
  8909. }
  8910. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8911. json_object_array_add(monitors, monitor);
  8912. }
  8913. }
  8914. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8915. random_uuid(guid);
  8916. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8917. json_object_put(NotifyMonitoringReport);
  8918. LWS_Send(message);
  8919. sprintf(tempdata, "NotifyMonitoringReport,0");
  8920. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8921. {
  8922. result = PASS;
  8923. }
  8924. return result;
  8925. }
  8926. int sendNotifyReportRequest()
  8927. {
  8928. mtrace();
  8929. int result = FAIL;
  8930. char message[4096]={0};
  8931. char guid[37]={0};
  8932. char tempdata[128]={0};
  8933. json_object *NotifyReport = json_object_new_object();
  8934. json_object *reportDatas = json_object_new_array();
  8935. DEBUG_INFO("sendNotifyReportRequest...\n");
  8936. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8937. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8938. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8939. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8940. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8941. {
  8942. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8943. {
  8944. json_object *reportData = json_object_new_object();
  8945. json_object *component = json_object_new_object();
  8946. json_object *evse = json_object_new_object();
  8947. json_object *variable = json_object_new_object();
  8948. json_object *variableAttributes = json_object_new_array();
  8949. json_object *variableCharacteristics = json_object_new_object();
  8950. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8951. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8952. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8953. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8954. json_object_object_add(component, "evse",evse);
  8955. json_object_object_add(reportData, "component", component);
  8956. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8957. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8958. json_object_object_add(reportData, "variable",variable);
  8959. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  8960. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  8961. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  8962. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  8963. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  8964. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  8965. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  8966. {
  8967. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  8968. {
  8969. json_object *variableAttribute = json_object_new_object();
  8970. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  8971. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  8972. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  8973. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  8974. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  8975. json_object_array_add(variableAttributes, variableAttribute);
  8976. }
  8977. }
  8978. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  8979. json_object_array_add(reportDatas, reportData);
  8980. }
  8981. }
  8982. json_object_object_add(NotifyReport, "reportData", reportDatas);
  8983. random_uuid(guid);
  8984. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  8985. json_object_put(NotifyReport);
  8986. LWS_SendNow(message);
  8987. sprintf(tempdata, "NotifyReport,0");
  8988. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8989. {
  8990. result = PASS;
  8991. }
  8992. return result;
  8993. }
  8994. int sendPublishFirmwareStatusNotificationRequest()
  8995. {
  8996. mtrace();
  8997. int result = FAIL;
  8998. char message[4096]={0};
  8999. char guid[37]={0};
  9000. char tempdata[128]={0};
  9001. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  9002. json_object *locations = json_object_new_array();
  9003. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  9004. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  9005. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  9006. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  9007. {
  9008. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  9009. }
  9010. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  9011. random_uuid(guid);
  9012. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  9013. json_object_put(PublishFirmwareStatusNotification);
  9014. LWS_Send(message);
  9015. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  9016. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9017. {
  9018. result = PASS;
  9019. }
  9020. return result;
  9021. }
  9022. int sendReportChargingProfilesRequest(int gun_index)
  9023. {
  9024. mtrace();
  9025. int result = FAIL;
  9026. char message[4096]={0};
  9027. char guid[37]={0};
  9028. char tempdata[128]={0};
  9029. json_object *ReportChargingProfiles = json_object_new_object();
  9030. json_object *chargingProfiles = json_object_new_array();
  9031. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  9032. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  9033. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  9034. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  9035. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  9036. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  9037. {
  9038. json_object *chargingProfile = json_object_new_object();
  9039. json_object *chargingSchedules = json_object_new_array();
  9040. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  9041. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  9042. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  9043. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  9044. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  9045. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  9046. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  9047. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  9048. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  9049. {
  9050. json_object *chargingSchedule = json_object_new_object();
  9051. json_object *chargingSchedulePeriods = json_object_new_array();
  9052. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  9053. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  9054. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  9055. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  9056. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  9057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  9058. {
  9059. json_object *chargingSchedulePeriod = json_object_new_object();
  9060. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  9061. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  9062. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  9063. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  9064. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  9065. }
  9066. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  9067. json_object_array_add(chargingSchedules, chargingSchedule);
  9068. }
  9069. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  9070. json_object_array_add(chargingProfiles, chargingProfile);
  9071. }
  9072. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  9073. random_uuid(guid);
  9074. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9075. json_object_put(ReportChargingProfiles);
  9076. LWS_Send(message);
  9077. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  9078. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9079. {
  9080. result = PASS;
  9081. }
  9082. return result;
  9083. }
  9084. int sendReservationStatusUpdateRequest(int gun_index)
  9085. {
  9086. mtrace();
  9087. int result = FAIL;
  9088. char message[4096]={0};
  9089. char guid[37]={0};
  9090. char tempdata[128]={0};
  9091. json_object *ReservationStatusUpdate = json_object_new_object();
  9092. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  9093. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  9094. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  9095. random_uuid(guid);
  9096. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  9097. json_object_put(ReservationStatusUpdate);
  9098. LWS_Send(message);
  9099. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  9100. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9101. {
  9102. result = PASS;
  9103. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  9104. }
  9105. return result;
  9106. }
  9107. int sendSecurityEventNotificationRequest()
  9108. {
  9109. mtrace();
  9110. int result = FAIL;
  9111. char message[4096]={0};
  9112. char guid[37]={0};
  9113. char tempdata[128]={0};
  9114. struct timeval tmnow;
  9115. struct tm *tm;
  9116. char buf[28];//, usec_buf[6];
  9117. json_object *SecurityEventNotification = json_object_new_object();
  9118. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  9119. DB_getSecurityEventType();
  9120. gettimeofday(&tmnow, NULL);
  9121. time_t t;
  9122. t = time(NULL);
  9123. /*UTC time and date*/
  9124. tm = gmtime(&t);
  9125. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9126. #if 0 // remove temporally
  9127. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9128. strcat(buf,".");
  9129. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9130. strcat(buf,usec_buf);
  9131. #endif
  9132. printf("%s",buf);
  9133. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  9134. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9135. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9136. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9137. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9138. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9139. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9140. random_uuid(guid);
  9141. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9142. json_object_put(SecurityEventNotification);
  9143. LWS_Send(message);
  9144. sprintf(tempdata, "SecurityEventNotification,0");
  9145. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9146. {
  9147. result = PASS;
  9148. }
  9149. return result;
  9150. }
  9151. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9152. {
  9153. mtrace();
  9154. int result = FAIL;
  9155. char message[4096]={0};
  9156. char guid[37]={0};
  9157. char tempdata[128]={0};
  9158. json_object *SignCertificate = json_object_new_object();
  9159. DEBUG_INFO("sendSignCertificateRequest...\n");
  9160. // Read csr file content
  9161. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9162. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?CSR_V2G:CSR_CP),"r");
  9163. char *line = NULL;
  9164. size_t len = 0;
  9165. while(getline(&line, &len, fp) != -1)
  9166. {
  9167. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9168. {
  9169. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9170. }
  9171. }
  9172. fclose(fp);
  9173. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9174. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9175. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9176. random_uuid(guid);
  9177. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9178. json_object_put(SignCertificate);
  9179. LWS_Send(message);
  9180. sprintf(tempdata, "SignCertificate,0");
  9181. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9182. {
  9183. result = PASS;
  9184. }
  9185. return result;
  9186. }
  9187. int sendStatusNotificationRequest(int gun_index)
  9188. {
  9189. mtrace();
  9190. int result = FAIL;
  9191. char message[600]={0};
  9192. char guid[37];
  9193. int currentStatus = 0;
  9194. struct timeval tmnow;
  9195. struct tm *tm;
  9196. char buf[28];//, usec_buf[6];
  9197. char tempdata[65]={0};
  9198. int tempIndex = 0;
  9199. uint8_t isStateChanged = TRUE;
  9200. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9201. gettimeofday(&tmnow, NULL);
  9202. time_t t;
  9203. t = time(NULL);
  9204. /*UTC time and date*/
  9205. tm = gmtime(&t);
  9206. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9207. #if 0 // remove temporally
  9208. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9209. strcat(buf,".");
  9210. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9211. strcat(buf,usec_buf);
  9212. #endif
  9213. printf("%s",buf);
  9214. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9215. ShmOCPP20Data->StatusNotification[gun_index].connectorId = 1;
  9216. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9217. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9218. /*
  9219. enum _SYSTEM_STATUS
  9220. {
  9221. S_BOOTING = 0,
  9222. S_IDLE, = 1
  9223. S_AUTHORIZING, =2
  9224. S_REASSIGN_CHECK, =3
  9225. S_REASSIGN, =4
  9226. S_PRECHARGE, =5
  9227. S_PREPARING_FOR_EV, =6
  9228. S_PREPARING_FOR_EVSE, =7
  9229. S_CHARGING, =8
  9230. S_TERMINATING, =9
  9231. S_COMPLETE, =10
  9232. S_ALARM, =11
  9233. S_FAULT =12
  9234. }
  9235. */
  9236. //check Transaction active
  9237. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9238. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9239. {
  9240. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9241. {
  9242. tempIndex = ((gun_index==2) ? 1: 0);
  9243. }
  9244. else
  9245. {
  9246. tempIndex = gun_index;
  9247. }
  9248. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9249. {
  9250. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9251. {
  9252. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9253. {
  9254. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9255. {
  9256. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9257. }
  9258. else
  9259. {
  9260. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9261. }
  9262. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9263. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9264. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9265. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9266. }
  9267. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9268. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9269. ) //S_PRECHARGE
  9270. {
  9271. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9272. }
  9273. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9274. {
  9275. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9276. }
  9277. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9278. {
  9279. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9280. }
  9281. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9282. {
  9283. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9284. }
  9285. 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
  9286. {
  9287. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9288. }
  9289. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9290. {
  9291. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9292. }
  9293. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9294. {
  9295. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9296. }
  9297. } //end of the same index
  9298. }//end of for CHAdeMO_QUANTITY
  9299. }
  9300. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9301. {
  9302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9303. {
  9304. tempIndex = ((gun_index==2) ? 1: 0);
  9305. }
  9306. else
  9307. {
  9308. tempIndex = gun_index;
  9309. }
  9310. for (int index = 0; index < CCS_QUANTITY; index++)
  9311. {
  9312. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9313. {
  9314. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9315. {
  9316. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9317. {
  9318. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9319. }
  9320. else
  9321. {
  9322. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9323. }
  9324. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9325. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9326. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9327. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9328. }
  9329. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9330. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9331. ) //S_PRECHARGE
  9332. {
  9333. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9334. }
  9335. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9336. {
  9337. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9338. }
  9339. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9340. {
  9341. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9342. }
  9343. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9344. {
  9345. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9346. }
  9347. 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
  9348. {
  9349. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9350. }
  9351. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9352. {
  9353. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9354. }
  9355. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9356. {
  9357. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9358. }
  9359. } //end of the same index
  9360. } // end of for CCS_QUANTITY
  9361. }
  9362. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9363. {
  9364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9365. {
  9366. tempIndex = ((gun_index==2) ? 1: 0);
  9367. }
  9368. else
  9369. {
  9370. tempIndex = gun_index;
  9371. }
  9372. for (int index = 0; index < GB_QUANTITY; index++)
  9373. {
  9374. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9375. {
  9376. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9377. {
  9378. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9379. {
  9380. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9381. }
  9382. else
  9383. {
  9384. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9385. }
  9386. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9387. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9388. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9389. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9390. }
  9391. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9392. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9393. ) //S_PRECHARGE
  9394. {
  9395. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9396. }
  9397. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9398. {
  9399. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9400. }
  9401. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9402. {
  9403. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9404. }
  9405. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9406. {
  9407. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9408. }
  9409. 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
  9410. {
  9411. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9412. }
  9413. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9414. {
  9415. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9416. }
  9417. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9418. {
  9419. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9420. }
  9421. } //end of the same index
  9422. } // end of for GB_QUANTITY
  9423. }
  9424. else if(gunType[gun_index] == GUN_TYPE_DO)
  9425. {
  9426. tempIndex = gun_index;
  9427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9428. {
  9429. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9430. {
  9431. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9432. {
  9433. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9434. {
  9435. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9436. }
  9437. else
  9438. {
  9439. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9440. }
  9441. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9442. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9443. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9444. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9445. }
  9446. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9447. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9448. ) //S_PRECHARGE
  9449. {
  9450. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9451. }
  9452. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9453. {
  9454. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9455. }
  9456. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9457. {
  9458. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9459. }
  9460. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9461. {
  9462. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9463. }
  9464. 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
  9465. {
  9466. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9467. }
  9468. 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
  9469. {
  9470. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9471. }
  9472. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9473. {
  9474. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9475. }
  9476. } //end of the same index
  9477. }
  9478. }
  9479. else
  9480. {
  9481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9482. {
  9483. tempIndex = 2;
  9484. }
  9485. else
  9486. {
  9487. tempIndex = gun_index;
  9488. }
  9489. for (int index = 0; index < AC_QUANTITY; index++)
  9490. {
  9491. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9492. {
  9493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9494. {
  9495. 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))
  9496. {
  9497. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9498. }
  9499. else
  9500. {
  9501. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9502. }
  9503. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9504. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9505. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9506. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9507. }
  9508. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9509. {
  9510. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9511. }
  9512. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9513. {
  9514. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9515. }
  9516. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9517. {
  9518. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9519. }
  9520. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9521. {
  9522. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9523. }
  9524. 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
  9525. {
  9526. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9527. }
  9528. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9529. {
  9530. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9531. }
  9532. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9533. {
  9534. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9535. }
  9536. }//end of the same index
  9537. }//end of for AC_QUANTITY
  9538. }
  9539. //it's option
  9540. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9541. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9542. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9543. {
  9544. isStateChanged = FALSE;
  9545. }
  9546. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9547. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9548. random_uuid(guid);
  9549. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9550. , MESSAGE_TYPE_CALL
  9551. , guid
  9552. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9553. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9554. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9555. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9556. if((server_sign == TRUE) && isStateChanged)
  9557. {
  9558. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9559. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9560. LWS_Send(message);
  9561. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9562. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9563. {
  9564. result = PASS;
  9565. }
  9566. }
  9567. else
  9568. {
  9569. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9570. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9571. result = PASS;
  9572. }
  9573. return result;
  9574. }
  9575. int sendTransactionEventRequest(int gun_index)
  9576. {
  9577. mtrace();
  9578. int result = FAIL;
  9579. char message[QUEUE_MESSAGE_LENGTH]={0};
  9580. char guid[37]={0};
  9581. char tempdata[128]={0};
  9582. uint8_t tempIndex;
  9583. json_object *TransactionEvent = json_object_new_object();
  9584. json_object *transactionInfo = json_object_new_object();
  9585. json_object *idToken = json_object_new_object();
  9586. json_object *evse = json_object_new_object();
  9587. json_object *meterValues = json_object_new_array();
  9588. char TempStopTransaction[256];
  9589. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9590. DEBUG_INFO("sendTransactionEventRequest...\n");
  9591. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9592. {
  9593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9594. {
  9595. tempIndex = ((gun_index==2) ? 1: 0);
  9596. }
  9597. else
  9598. {
  9599. tempIndex = gun_index;
  9600. }
  9601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9602. {
  9603. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9604. {
  9605. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9606. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9607. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9608. else
  9609. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9610. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9611. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9612. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9613. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9614. {
  9615. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9616. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9617. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9618. {
  9619. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9620. }
  9621. else
  9622. {
  9623. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9624. }
  9625. }
  9626. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9627. {
  9628. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9629. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9630. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9631. }
  9632. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9633. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9634. ) //S_PRECHARGE
  9635. {
  9636. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9637. {
  9638. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9639. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9640. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9641. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9642. }
  9643. else
  9644. {
  9645. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9646. }
  9647. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9648. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9649. }
  9650. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9651. {
  9652. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9653. {
  9654. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9655. {
  9656. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9657. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9658. }
  9659. else
  9660. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9661. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9662. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9663. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9664. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9665. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9666. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9667. }
  9668. else
  9669. {
  9670. storeTempStopTransaction(gun_index);
  9671. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9672. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9673. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9674. }
  9675. }
  9676. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9677. {
  9678. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9679. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9680. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9681. if((access(TempStopTransaction,F_OK))!=-1)
  9682. {
  9683. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9684. }
  9685. }
  9686. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9687. {
  9688. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9690. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9691. }
  9692. 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
  9693. {
  9694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9696. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9697. }
  9698. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9699. {
  9700. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9701. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9702. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9703. }
  9704. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9705. {
  9706. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9707. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9708. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9709. }
  9710. } //end of the same index
  9711. }//end of for CHAdeMO_QUANTITY
  9712. }
  9713. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9714. {
  9715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9716. {
  9717. tempIndex = ((gun_index==2) ? 1: 0);
  9718. }
  9719. else
  9720. {
  9721. tempIndex = gun_index;
  9722. }
  9723. for (int index = 0; index < CCS_QUANTITY; index++)
  9724. {
  9725. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9726. {
  9727. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9728. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9729. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9730. else
  9731. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9732. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9733. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9734. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9736. {
  9737. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9738. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9739. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9740. {
  9741. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9742. }
  9743. else
  9744. {
  9745. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9746. }
  9747. }
  9748. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9749. {
  9750. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9751. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9752. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9753. }
  9754. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9755. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9756. ) //S_PRECHARGE
  9757. {
  9758. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9759. {
  9760. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9761. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9762. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9764. }
  9765. else
  9766. {
  9767. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9768. }
  9769. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9770. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9771. }
  9772. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9773. {
  9774. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9775. {
  9776. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9777. {
  9778. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9779. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9780. }
  9781. else
  9782. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9783. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9784. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9785. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9786. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9787. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9788. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9789. }
  9790. else
  9791. {
  9792. storeTempStopTransaction(gun_index);
  9793. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9795. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9796. }
  9797. }
  9798. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9799. {
  9800. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9801. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9802. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9803. if((access(TempStopTransaction,F_OK))!=-1)
  9804. {
  9805. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9806. }
  9807. }
  9808. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9809. {
  9810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9811. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9813. }
  9814. 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
  9815. {
  9816. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9819. }
  9820. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9821. {
  9822. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9825. }
  9826. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9827. {
  9828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9829. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9830. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9831. }
  9832. } //end of the same index
  9833. } // end of for CCS_QUANTITY
  9834. }
  9835. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9836. {
  9837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9838. {
  9839. tempIndex = ((gun_index==2) ? 1: 0);
  9840. }
  9841. else
  9842. {
  9843. tempIndex = gun_index;
  9844. }
  9845. for (int index = 0; index < GB_QUANTITY; index++)
  9846. {
  9847. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9848. {
  9849. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9850. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9851. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9852. else
  9853. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9854. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9855. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9856. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9857. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9858. {
  9859. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9860. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9861. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9862. {
  9863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9864. }
  9865. else
  9866. {
  9867. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9868. }
  9869. }
  9870. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9871. {
  9872. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9873. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9874. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9875. }
  9876. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9877. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9878. ) //S_PRECHARGE
  9879. {
  9880. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9881. {
  9882. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9883. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9884. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9885. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9886. }
  9887. else
  9888. {
  9889. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9890. }
  9891. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9892. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9893. }
  9894. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9895. {
  9896. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9897. {
  9898. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  9899. {
  9900. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9901. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9902. }
  9903. else
  9904. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9905. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9906. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9907. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9908. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9909. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9910. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  9911. }
  9912. else
  9913. {
  9914. storeTempStopTransaction(gun_index);
  9915. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9916. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9917. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9918. }
  9919. }
  9920. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9921. {
  9922. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9923. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9924. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9925. if((access(TempStopTransaction,F_OK))!=-1)
  9926. {
  9927. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9928. }
  9929. }
  9930. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9931. {
  9932. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9933. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9934. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9935. }
  9936. 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
  9937. {
  9938. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9939. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9940. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9941. }
  9942. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9943. {
  9944. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9945. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9946. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9947. }
  9948. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9949. {
  9950. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9951. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9952. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9953. }
  9954. } //end of the same index
  9955. } // end of for GB_QUANTITY
  9956. }
  9957. else if(gunType[gun_index] == GUN_TYPE_DO)
  9958. {
  9959. tempIndex = gun_index;
  9960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9961. {
  9962. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9963. {
  9964. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9965. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9966. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9967. else
  9968. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9969. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9970. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9971. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9973. {
  9974. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9975. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9976. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9977. {
  9978. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9979. }
  9980. else
  9981. {
  9982. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9983. }
  9984. }
  9985. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9986. {
  9987. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9988. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9989. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9990. }
  9991. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9992. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9993. ) //S_PRECHARGE
  9994. {
  9995. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9996. {
  9997. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9998. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9999. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10000. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10001. }
  10002. else
  10003. {
  10004. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10005. }
  10006. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10007. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10008. }
  10009. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10010. {
  10011. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10012. {
  10013. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  10014. {
  10015. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10016. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10017. }
  10018. else
  10019. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10020. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10021. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10022. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10023. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10024. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10025. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  10026. }
  10027. else
  10028. {
  10029. storeTempStopTransaction(gun_index);
  10030. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10031. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10032. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10033. }
  10034. }
  10035. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10036. {
  10037. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10038. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10039. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10040. if((access(TempStopTransaction,F_OK))!=-1)
  10041. {
  10042. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10043. }
  10044. }
  10045. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10046. {
  10047. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10048. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10049. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10050. }
  10051. 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
  10052. {
  10053. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10054. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10055. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10056. }
  10057. 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
  10058. {
  10059. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10060. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10061. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10062. }
  10063. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10064. {
  10065. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10066. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10067. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10068. }
  10069. } //end of the same index
  10070. }
  10071. }
  10072. else
  10073. {
  10074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10075. {
  10076. tempIndex = 2;
  10077. }
  10078. else
  10079. {
  10080. tempIndex = gun_index;
  10081. }
  10082. for (int index = 0; index < AC_QUANTITY; index++)
  10083. {
  10084. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10085. {
  10086. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10087. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10088. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10089. else
  10090. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10091. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10092. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10093. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10094. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  10095. {
  10096. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10097. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10098. 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))
  10099. {
  10100. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10101. }
  10102. else
  10103. {
  10104. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10105. }
  10106. }
  10107. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10108. {
  10109. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10110. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10111. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10112. }
  10113. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10114. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10115. ) //S_PRECHARGE
  10116. {
  10117. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10118. {
  10119. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10120. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10121. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10122. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10123. }
  10124. else
  10125. {
  10126. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10127. }
  10128. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10129. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10130. }
  10131. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10132. {
  10133. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10134. {
  10135. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10136. {
  10137. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10138. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10139. }
  10140. else
  10141. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10142. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10143. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10144. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10145. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10146. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10147. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10148. }
  10149. else
  10150. {
  10151. storeTempStopTransaction(gun_index);
  10152. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10153. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10154. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10155. }
  10156. }
  10157. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10158. {
  10159. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10160. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10161. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10162. if((access(TempStopTransaction,F_OK))!=-1)
  10163. {
  10164. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10165. }
  10166. }
  10167. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10168. {
  10169. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10170. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10171. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10172. }
  10173. 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
  10174. {
  10175. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10176. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10177. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10178. }
  10179. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10180. {
  10181. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10182. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10183. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10184. }
  10185. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10186. {
  10187. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10188. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10189. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10190. }
  10191. }//end of the same index
  10192. }//end of for AC_QUANTITY
  10193. }
  10194. // Check if this message is triggered by TriggerMessage
  10195. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10196. {
  10197. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10198. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10199. }
  10200. // Clear meterValue buffer for the next transaction
  10201. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10202. {
  10203. meterValueBufferClear(gun_index);
  10204. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Transaction_Begin, FALSE);
  10205. }
  10206. // Message
  10207. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10208. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10209. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10210. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10211. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10212. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10213. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10214. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10215. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10216. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10217. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10218. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10219. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10220. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10221. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10222. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10223. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10224. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10225. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10226. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10227. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10228. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10229. {
  10230. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10231. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10232. json_object_object_add(TransactionEvent, "idToken", idToken);
  10233. }
  10234. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10235. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10236. json_object_object_add(TransactionEvent, "evse", evse);
  10237. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10238. {
  10239. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10240. {
  10241. json_object *meterValue = json_object_new_object();
  10242. json_object *sampledValues = json_object_new_array();
  10243. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10244. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10245. {
  10246. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10247. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) ||
  10248. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) ||
  10249. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) ||
  10250. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  10251. {
  10252. if(((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)) ||
  10253. ((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) == NULL)))
  10254. {
  10255. json_object *sampledValue = json_object_new_object();
  10256. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10257. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10258. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10259. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10260. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10261. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10262. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10263. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10264. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10265. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10266. {
  10267. json_object *unitOfMeasure = json_object_new_object();
  10268. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10269. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10270. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10271. }
  10272. json_object_array_add(sampledValues, sampledValue);
  10273. }
  10274. }
  10275. }
  10276. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10277. json_object_array_add(meterValues, meterValue);
  10278. }
  10279. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10280. }
  10281. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10282. {
  10283. json_object *meterValues = json_object_new_array();
  10284. meterValueBufferQuery(gun_index, meterValues);
  10285. if(json_object_array_length(meterValues) > 0)
  10286. {
  10287. DEBUG_INFO("parsed meterValue: %s\n", json_object_to_json_string_ext(meterValues, JSON_C_TO_STRING_PLAIN));
  10288. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10289. }
  10290. }
  10291. random_uuid(guid);
  10292. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10293. json_object_put(TransactionEvent);
  10294. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10295. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10296. {
  10297. result = PASS;
  10298. }
  10299. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10300. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10301. {
  10302. OCPP_insert_transaction_msg(YES, message);
  10303. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  10304. }
  10305. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10306. {
  10307. OCPP_insert_transaction_msg(NO, message);
  10308. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10309. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10310. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10311. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10312. }
  10313. return result;
  10314. }
  10315. //==========================================
  10316. // send confirm routine
  10317. //==========================================
  10318. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10319. {
  10320. mtrace();
  10321. int result = FAIL;
  10322. char message[4096]={0};
  10323. json_object *CancelReservation = json_object_new_object();
  10324. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10325. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10326. sprintf(message,"[%d,\"%s\",%s]"
  10327. ,MESSAGE_TYPE_CALLRESULT
  10328. ,uuid
  10329. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10330. json_object_put(CancelReservation);
  10331. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10332. LWS_Send(message);
  10333. result = TRUE;
  10334. return result;
  10335. }
  10336. int sendCertificateSignedConfirmation(char *uuid)
  10337. {
  10338. mtrace();
  10339. int result = FAIL;
  10340. char message[4096]={0};
  10341. json_object *CertificateSigned = json_object_new_object();
  10342. json_object *statusInfo = json_object_new_object();
  10343. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10344. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10345. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10346. {
  10347. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10348. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10349. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10350. }
  10351. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10352. sprintf(message,"[%d,\"%s\",%s]"
  10353. ,MESSAGE_TYPE_CALLRESULT
  10354. ,uuid
  10355. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10356. json_object_put(CertificateSigned);
  10357. LWS_Send(message);
  10358. result = TRUE;
  10359. return result;
  10360. }
  10361. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10362. {
  10363. mtrace();
  10364. int result = FAIL;
  10365. char message[4096]={0};
  10366. json_object *ChangeAvailability = json_object_new_object();
  10367. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10368. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10369. sprintf(message,"[%d,\"%s\",%s]"
  10370. ,MESSAGE_TYPE_CALLRESULT
  10371. ,uuid
  10372. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10373. json_object_put(ChangeAvailability);
  10374. LWS_Send(message);
  10375. result = TRUE;
  10376. return result;
  10377. }
  10378. int sendClearCacheConfirmation(char *uuid)
  10379. {
  10380. mtrace();
  10381. int result = FAIL;
  10382. char message[4096]={0};
  10383. json_object *ClearCache = json_object_new_object();
  10384. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10385. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10386. sprintf(message,"[%d,\"%s\",%s]"
  10387. ,MESSAGE_TYPE_CALLRESULT
  10388. ,uuid
  10389. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10390. json_object_put(ClearCache);
  10391. LWS_Send(message);
  10392. result = TRUE;
  10393. return result;
  10394. }
  10395. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10396. {
  10397. mtrace();
  10398. int result = FAIL;
  10399. char message[500]={0};
  10400. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10401. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10402. LWS_Send(message);
  10403. return result;
  10404. }
  10405. int sendClearDisplayMessageConfirmation(char *uuid)
  10406. {
  10407. mtrace();
  10408. int result = FAIL;
  10409. char message[4096]={0};
  10410. json_object *ClearDisplayMessage = json_object_new_object();
  10411. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10412. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10413. sprintf(message,"[%d,\"%s\",%s]"
  10414. ,MESSAGE_TYPE_CALLRESULT
  10415. ,uuid
  10416. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10417. json_object_put(ClearDisplayMessage);
  10418. LWS_Send(message);
  10419. result = TRUE;
  10420. return result;
  10421. }
  10422. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10423. {
  10424. mtrace();
  10425. int result = FAIL;
  10426. char message[4096]={0};
  10427. json_object *ClearVariableMonitoring = json_object_new_object();
  10428. json_object *clearMonitoringResults = json_object_new_array();
  10429. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10430. for(int idx=0;idx<variableQuantity;idx++)
  10431. {
  10432. json_object *clearMonitoringResult = json_object_new_object();
  10433. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10434. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10435. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10436. }
  10437. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10438. sprintf(message,"[%d,\"%s\",%s]"
  10439. ,MESSAGE_TYPE_CALLRESULT
  10440. ,uuid
  10441. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10442. json_object_put(ClearVariableMonitoring);
  10443. LWS_Send(message);
  10444. result = TRUE;
  10445. return result;
  10446. }
  10447. int sendCostUpdatedConfirmation(char *uuid)
  10448. {
  10449. mtrace();
  10450. int result = FAIL;
  10451. char message[4096]={0};
  10452. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10453. sprintf(message,"[%d,\"%s\",{}]"
  10454. ,MESSAGE_TYPE_CALLRESULT
  10455. ,uuid);
  10456. LWS_Send(message);
  10457. result = TRUE;
  10458. return result;
  10459. }
  10460. int sendCustomerInformationConfirmation(char *uuid)
  10461. {
  10462. mtrace();
  10463. int result = FAIL;
  10464. char message[4096]={0};
  10465. json_object *CustomerInformation = json_object_new_object();
  10466. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10467. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10468. sprintf(message,"[%d,\"%s\",%s]"
  10469. ,MESSAGE_TYPE_CALLRESULT
  10470. ,uuid
  10471. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10472. json_object_put(CustomerInformation);
  10473. LWS_Send(message);
  10474. result = TRUE;
  10475. return result;
  10476. }
  10477. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10478. {
  10479. mtrace();
  10480. int result = FAIL;
  10481. char message[4096]={0};
  10482. json_object *DataTransfer = json_object_new_object();
  10483. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10484. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10485. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10486. sprintf(message,"[%d,\"%s\",%s]"
  10487. ,MESSAGE_TYPE_CALLRESULT
  10488. ,uuid
  10489. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10490. json_object_put(DataTransfer);
  10491. LWS_Send(message);
  10492. result = TRUE;
  10493. return result;
  10494. }
  10495. int sendDeleteCertificateConfirmation(char *uuid)
  10496. {
  10497. mtrace();
  10498. int result = FAIL;
  10499. char message[4096]={0};
  10500. json_object *DeleteCertificate = json_object_new_object();
  10501. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10502. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10503. sprintf(message,"[%d,\"%s\",%s]"
  10504. ,MESSAGE_TYPE_CALLRESULT
  10505. ,uuid
  10506. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10507. json_object_put(DeleteCertificate);
  10508. LWS_Send(message);
  10509. result = TRUE;
  10510. return result;
  10511. }
  10512. int sendGetBaseReportConfirmation(char *uuid)
  10513. {
  10514. mtrace();
  10515. int result = FAIL;
  10516. char message[4096]={0};
  10517. json_object *GetBaseReport = json_object_new_object();
  10518. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10519. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10520. sprintf(message,"[%d,\"%s\",%s]"
  10521. ,MESSAGE_TYPE_CALLRESULT
  10522. ,uuid
  10523. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10524. json_object_put(GetBaseReport);
  10525. LWS_Send(message);
  10526. result = TRUE;
  10527. return result;
  10528. }
  10529. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10530. {
  10531. mtrace();
  10532. int result = FAIL;
  10533. char message[4096]={0};
  10534. json_object *GetChargingProfiles = json_object_new_object();
  10535. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10536. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10537. sprintf(message,"[%d,\"%s\",%s]"
  10538. ,MESSAGE_TYPE_CALLRESULT
  10539. ,uuid
  10540. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10541. json_object_put(GetChargingProfiles);
  10542. LWS_Send(message);
  10543. result = TRUE;
  10544. return result;
  10545. }
  10546. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int evseIdInt, int nPeriod)
  10547. {
  10548. mtrace();
  10549. int result = FAIL;
  10550. char message[4096]={0};
  10551. int CompositeScheduleIndex = 0;
  10552. json_object *GetCompositeSchedule = json_object_new_object();
  10553. json_object *schedule = json_object_new_object();
  10554. json_object *chargingSchedule = json_object_new_object();
  10555. json_object *chargingSchedulePeriod = json_object_new_array();
  10556. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10557. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10558. CompositeScheduleIndex = (evseIdInt > 0) ?(evseIdInt -1) : 0;
  10559. json_object_object_add(schedule, "evseId", json_object_new_int(evseIdInt));
  10560. if(nPeriod == 0)
  10561. {
  10562. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10563. {
  10564. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10565. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10566. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10567. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10568. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10569. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10570. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10571. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10572. uint8_t isNullSchedulePeriod = TRUE;
  10573. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10574. {
  10575. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10576. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10577. {
  10578. json_object *Period = json_object_new_object();
  10579. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10580. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10581. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10582. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10583. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10584. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10585. json_object_array_add(chargingSchedulePeriod, Period);
  10586. isNullSchedulePeriod = FALSE;
  10587. }
  10588. }
  10589. if(isNullSchedulePeriod == TRUE)
  10590. {
  10591. json_object *Period = json_object_new_object();
  10592. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10593. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10594. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10595. json_object_array_add(chargingSchedulePeriod, Period);
  10596. }
  10597. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10598. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10599. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10600. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10601. }
  10602. }
  10603. else
  10604. {
  10605. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10606. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10607. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10608. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10609. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10610. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10611. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10612. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10613. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10614. {
  10615. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10616. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10617. {
  10618. json_object *Period = json_object_new_object();
  10619. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10620. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10621. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10622. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10623. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10624. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10625. json_object_array_add(chargingSchedulePeriod, Period);
  10626. }
  10627. }
  10628. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10629. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10630. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10631. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10632. }
  10633. sprintf(message,"[%d,\"%s\",%s]"
  10634. ,MESSAGE_TYPE_CALLRESULT
  10635. ,uuid
  10636. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10637. json_object_put(GetCompositeSchedule);
  10638. LWS_Send(message);
  10639. result = TRUE;
  10640. return result;
  10641. }
  10642. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10643. {
  10644. mtrace();
  10645. int result = FAIL;
  10646. char message[4096]={0};
  10647. json_object *GetGetDisplayMessages = json_object_new_object();
  10648. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10649. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10650. sprintf(message,"[%d,\"%s\",%s]"
  10651. ,MESSAGE_TYPE_CALLRESULT
  10652. ,uuid
  10653. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10654. json_object_put(GetGetDisplayMessages);
  10655. LWS_Send(message);
  10656. result = TRUE;
  10657. return result;
  10658. }
  10659. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10660. {
  10661. mtrace();
  10662. int result = FAIL;
  10663. char message[4096]={0};
  10664. json_object *GetInstalledCertificateIds = json_object_new_object();
  10665. json_object *certificateHashDataChains = json_object_new_array();
  10666. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10667. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10668. for(int idx=0;idx<certQuantity;idx++)
  10669. {
  10670. json_object *cert = json_object_new_object();
  10671. json_object *certificateHashData = json_object_new_object();
  10672. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10673. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10674. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10675. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10676. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10677. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10678. json_object_array_add(certificateHashDataChains, cert);
  10679. }
  10680. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10681. sprintf(message,"[%d,\"%s\",%s]"
  10682. ,MESSAGE_TYPE_CALLRESULT
  10683. ,uuid
  10684. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10685. json_object_put(GetInstalledCertificateIds);
  10686. LWS_Send(message);
  10687. result = TRUE;
  10688. return result;
  10689. }
  10690. int sendGetLocalListVersionConfirmation(char *uuid)
  10691. {
  10692. mtrace();
  10693. int result = FAIL;
  10694. char message[4096]={0};
  10695. json_object *GetLocalListVersion = json_object_new_object();
  10696. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10697. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10698. sprintf(message,"[%d,\"%s\",%s]"
  10699. ,MESSAGE_TYPE_CALLRESULT
  10700. ,uuid
  10701. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10702. json_object_put(GetLocalListVersion);
  10703. LWS_Send(message);
  10704. result = TRUE;
  10705. return result;
  10706. }
  10707. int sendGetLogConfirmation(char *uuid)
  10708. {
  10709. mtrace();
  10710. int result = FAIL;
  10711. char message[4096]={0};
  10712. json_object *GetLog = json_object_new_object();
  10713. DEBUG_INFO("sendGetLogConfirmation...\n");
  10714. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10715. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10716. sprintf(message,"[%d,\"%s\",%s]"
  10717. ,MESSAGE_TYPE_CALLRESULT
  10718. ,uuid
  10719. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10720. json_object_put(GetLog);
  10721. LWS_Send(message);
  10722. result = TRUE;
  10723. return result;
  10724. }
  10725. int sendGetMonitoringReportConfirmation(char *uuid)
  10726. {
  10727. mtrace();
  10728. int result = FAIL;
  10729. char message[4096]={0};
  10730. json_object *GetMonitoringReport = json_object_new_object();
  10731. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10732. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10733. sprintf(message,"[%d,\"%s\",%s]"
  10734. ,MESSAGE_TYPE_CALLRESULT
  10735. ,uuid
  10736. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10737. json_object_put(GetMonitoringReport);
  10738. LWS_Send(message);
  10739. result = TRUE;
  10740. return result;
  10741. }
  10742. int sendGetReportConfirmation(char *uuid)
  10743. {
  10744. mtrace();
  10745. int result = FAIL;
  10746. char message[4096]={0};
  10747. json_object *GetReport = json_object_new_object();
  10748. DEBUG_INFO("sendGetReportConfirmation...\n");
  10749. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10750. sprintf(message,"[%d,\"%s\",%s]"
  10751. ,MESSAGE_TYPE_CALLRESULT
  10752. ,uuid
  10753. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10754. json_object_put(GetReport);
  10755. LWS_Send(message);
  10756. result = TRUE;
  10757. return result;
  10758. }
  10759. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  10760. {
  10761. mtrace();
  10762. int result = FAIL;
  10763. char message[4096]={0};
  10764. json_object *GetTransactionStatus = json_object_new_object();
  10765. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10766. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  10767. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  10768. sprintf(message,"[%d,\"%s\",%s]"
  10769. ,MESSAGE_TYPE_CALLRESULT
  10770. ,uuid
  10771. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10772. json_object_put(GetTransactionStatus);
  10773. LWS_Send(message);
  10774. result = TRUE;
  10775. return result;
  10776. }
  10777. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10778. {
  10779. mtrace();
  10780. int result = FAIL;
  10781. char message[4096]={0};
  10782. json_object *GetVariables = json_object_new_object();
  10783. json_object *getVariableResults = json_object_new_array();
  10784. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10785. for(int idx=0;idx<variableQuantity;idx++)
  10786. {
  10787. json_object *variableResult = json_object_new_object();
  10788. json_object *component = json_object_new_object();
  10789. json_object *variable = json_object_new_object();
  10790. json_object *evse = json_object_new_object();
  10791. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10792. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10793. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10794. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10795. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10796. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10797. {
  10798. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10799. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10800. json_object_object_add(component, "evse", evse);
  10801. }
  10802. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10803. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10804. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10805. json_object_object_add(variableResult, "component", component);
  10806. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10807. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10808. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10809. json_object_object_add(variableResult, "variable", variable);
  10810. json_object_array_add(getVariableResults, variableResult);
  10811. }
  10812. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10813. sprintf(message,"[%d,\"%s\",%s]"
  10814. ,MESSAGE_TYPE_CALLRESULT
  10815. ,uuid
  10816. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10817. json_object_put(GetVariables);
  10818. LWS_Send(message);
  10819. result = TRUE;
  10820. return result;
  10821. }
  10822. int sendInstallCertificateConfirmation(char *uuid)
  10823. {
  10824. mtrace();
  10825. int result = FAIL;
  10826. char message[4096]={0};
  10827. json_object *InstallCertificate = json_object_new_object();
  10828. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10829. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10830. sprintf(message,"[%d,\"%s\",%s]"
  10831. ,MESSAGE_TYPE_CALLRESULT
  10832. ,uuid
  10833. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10834. json_object_put(InstallCertificate);
  10835. LWS_Send(message);
  10836. result = TRUE;
  10837. return result;
  10838. }
  10839. int sendPublishFirmwareConfirmation(char *uuid)
  10840. {
  10841. mtrace();
  10842. int result = FAIL;
  10843. char message[4096]={0};
  10844. json_object *PublishFirmware = json_object_new_object();
  10845. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10846. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10847. sprintf(message,"[%d,\"%s\",%s]"
  10848. ,MESSAGE_TYPE_CALLRESULT
  10849. ,uuid
  10850. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10851. json_object_put(PublishFirmware);
  10852. LWS_Send(message);
  10853. result = TRUE;
  10854. return result;
  10855. }
  10856. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10857. {
  10858. mtrace();
  10859. int result = FAIL;
  10860. char message[4096]={0};
  10861. json_object *RemoteStartTransaction = json_object_new_object();
  10862. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10863. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10864. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10865. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10866. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10867. sprintf(message,"[%d,\"%s\",%s]"
  10868. ,MESSAGE_TYPE_CALLRESULT
  10869. ,uuid
  10870. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10871. json_object_put(RemoteStartTransaction);
  10872. LWS_Send(message);
  10873. result = TRUE;
  10874. return result;
  10875. }
  10876. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10877. {
  10878. mtrace();
  10879. int result = FAIL;
  10880. char message[4096]={0};
  10881. json_object *RemoteStopTransaction = json_object_new_object();
  10882. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  10883. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  10884. sprintf(message,"[%d,\"%s\",%s]"
  10885. ,MESSAGE_TYPE_CALLRESULT
  10886. ,uuid
  10887. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  10888. json_object_put(RemoteStopTransaction);
  10889. LWS_Send(message);
  10890. result = TRUE;
  10891. return result;
  10892. }
  10893. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  10894. {
  10895. mtrace();
  10896. int result = FAIL;
  10897. char message[4096]={0};
  10898. json_object *ReserveNow = json_object_new_object();
  10899. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  10900. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  10901. sprintf(message,"[%d,\"%s\",%s]"
  10902. ,MESSAGE_TYPE_CALLRESULT
  10903. ,uuid
  10904. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10905. json_object_put(ReserveNow);
  10906. LWS_Send(message);
  10907. result = TRUE;
  10908. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10909. return result;
  10910. }
  10911. int sendResetConfirmation(char *uuid)
  10912. {
  10913. mtrace();
  10914. int result = FAIL;
  10915. char message[4096]={0};
  10916. json_object *Reset = json_object_new_object();
  10917. DEBUG_INFO("sendResetConfirmation...\n");
  10918. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10919. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10920. sprintf(message,"[%d,\"%s\",%s]"
  10921. ,MESSAGE_TYPE_CALLRESULT
  10922. ,uuid
  10923. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10924. json_object_put(Reset);
  10925. LWS_Send(message);
  10926. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10927. {
  10928. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10929. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10930. }
  10931. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10932. {
  10933. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10934. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10935. }
  10936. result = TRUE;
  10937. return result;
  10938. }
  10939. int sendSendLocalListConfirmation(char *uuid)
  10940. {
  10941. mtrace();
  10942. int result = FAIL;
  10943. char message[4096]={0};
  10944. json_object *SendLocalList = json_object_new_object();
  10945. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  10946. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10947. sprintf(message,"[%d,\"%s\",%s]"
  10948. ,MESSAGE_TYPE_CALLRESULT
  10949. ,uuid
  10950. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10951. json_object_put(SendLocalList);
  10952. LWS_Send(message);
  10953. result = TRUE;
  10954. return result;
  10955. }
  10956. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10957. {
  10958. mtrace();
  10959. int result = FAIL;
  10960. char message[4096]={0};
  10961. json_object *SetChargingProfile = json_object_new_object();
  10962. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  10963. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  10964. sprintf(message,"[%d,\"%s\",%s]"
  10965. ,MESSAGE_TYPE_CALLRESULT
  10966. ,uuid
  10967. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10968. json_object_put(SetChargingProfile);
  10969. LWS_Send(message);
  10970. result = TRUE;
  10971. return result;
  10972. }
  10973. int sendSetDisplayMessagesConfirmation(char *uuid)
  10974. {
  10975. mtrace();
  10976. int result = FAIL;
  10977. char message[4096]={0};
  10978. json_object *SetDisplayMessage = json_object_new_object();
  10979. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  10980. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  10981. sprintf(message,"[%d,\"%s\",%s]"
  10982. ,MESSAGE_TYPE_CALLRESULT
  10983. ,uuid
  10984. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10985. json_object_put(SetDisplayMessage);
  10986. LWS_Send(message);
  10987. result = TRUE;
  10988. return result;
  10989. }
  10990. int sendSetMonitoringBaseConfirmation(char *uuid)
  10991. {
  10992. mtrace();
  10993. int result = FAIL;
  10994. char message[4096]={0};
  10995. json_object *SetMonitoringBase = json_object_new_object();
  10996. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  10997. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  10998. sprintf(message,"[%d,\"%s\",%s]"
  10999. ,MESSAGE_TYPE_CALLRESULT
  11000. ,uuid
  11001. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  11002. json_object_put(SetMonitoringBase);
  11003. LWS_Send(message);
  11004. result = TRUE;
  11005. return result;
  11006. }
  11007. int sendSetMonitoringLevelConfirmation(char *uuid)
  11008. {
  11009. mtrace();
  11010. int result = FAIL;
  11011. char message[4096]={0};
  11012. json_object *SetMonitoringLevel = json_object_new_object();
  11013. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  11014. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  11015. sprintf(message,"[%d,\"%s\",%s]"
  11016. ,MESSAGE_TYPE_CALLRESULT
  11017. ,uuid
  11018. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  11019. json_object_put(SetMonitoringLevel);
  11020. LWS_Send(message);
  11021. result = TRUE;
  11022. return result;
  11023. }
  11024. int sendSetNetworkProfileConfirmation(char *uuid)
  11025. {
  11026. mtrace();
  11027. int result = FAIL;
  11028. char message[4096]={0};
  11029. json_object *SetNetworkProfile = json_object_new_object();
  11030. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  11031. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  11032. sprintf(message,"[%d,\"%s\",%s]"
  11033. ,MESSAGE_TYPE_CALLRESULT
  11034. ,uuid
  11035. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  11036. json_object_put(SetNetworkProfile);
  11037. LWS_Send(message);
  11038. result = TRUE;
  11039. return result;
  11040. }
  11041. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  11042. {
  11043. mtrace();
  11044. int result = FAIL;
  11045. char message[4096]={0};
  11046. json_object *SetVariableMonitoring = json_object_new_object();
  11047. json_object *setMonitoringResults = json_object_new_array();
  11048. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  11049. for(int idx=0;idx<variableQuantity;idx++)
  11050. {
  11051. json_object *variableMonitorResult = json_object_new_object();
  11052. json_object *component = json_object_new_object();
  11053. json_object *variable = json_object_new_object();
  11054. json_object *evse = json_object_new_object();
  11055. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  11056. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  11057. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  11058. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  11059. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  11060. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  11061. json_object_object_add(component, "evse", evse);
  11062. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  11063. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  11064. json_object_object_add(variableMonitorResult, "component", component);
  11065. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  11066. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  11067. json_object_object_add(variableMonitorResult, "variable", variable);
  11068. json_object_array_add(setMonitoringResults, variableMonitorResult);
  11069. }
  11070. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  11071. sprintf(message,"[%d,\"%s\",%s]"
  11072. ,MESSAGE_TYPE_CALLRESULT
  11073. ,uuid
  11074. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  11075. json_object_put(SetVariableMonitoring);
  11076. LWS_Send(message);
  11077. result = TRUE;
  11078. return result;
  11079. }
  11080. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  11081. {
  11082. mtrace();
  11083. int result = FAIL;
  11084. char message[4096]={0};
  11085. json_object *SetVariable = json_object_new_object();
  11086. json_object *setVariableResults = json_object_new_array();
  11087. DEBUG_INFO("sendSetVariableConfirmation...\n");
  11088. for(int idx=0;idx<variableQuantity;idx++)
  11089. {
  11090. json_object *variableResult = json_object_new_object();
  11091. json_object *component = json_object_new_object();
  11092. json_object *variable = json_object_new_object();
  11093. json_object *evse = json_object_new_object();
  11094. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  11095. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  11096. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  11097. {
  11098. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  11099. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  11100. json_object_object_add(component, "evse", evse);
  11101. }
  11102. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  11103. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  11104. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  11105. json_object_object_add(variableResult, "component", component);
  11106. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  11107. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  11108. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  11109. json_object_object_add(variableResult, "variable", variable);
  11110. json_object_array_add(setVariableResults, variableResult);
  11111. }
  11112. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  11113. sprintf(message,"[%d,\"%s\",%s]"
  11114. ,MESSAGE_TYPE_CALLRESULT
  11115. ,uuid
  11116. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  11117. json_object_put(SetVariable);
  11118. LWS_Send(message);
  11119. result = TRUE;
  11120. return result;
  11121. }
  11122. int sendTriggerMessageConfirmation(char *uuid)
  11123. {
  11124. mtrace();
  11125. int result = FAIL;
  11126. char message[4096]={0};
  11127. json_object *TriggerMessage = json_object_new_object();
  11128. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  11129. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  11130. sprintf(message,"[%d,\"%s\",%s]",
  11131. MESSAGE_TYPE_CALLRESULT,
  11132. uuid,
  11133. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  11134. json_object_put(TriggerMessage);
  11135. LWS_Send(message);
  11136. result = TRUE;
  11137. return result;
  11138. }
  11139. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  11140. {
  11141. mtrace();
  11142. int result = FAIL;
  11143. char message[4096]={0};
  11144. json_object *UnlockConnector = json_object_new_object();
  11145. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  11146. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  11147. sprintf(message,"[%d,\"%s\",%s]",
  11148. MESSAGE_TYPE_CALLRESULT,
  11149. uuid,
  11150. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  11151. json_object_put(UnlockConnector);
  11152. LWS_Send(message);
  11153. result = TRUE;
  11154. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  11155. return result;
  11156. }
  11157. int sendUnpublishFirmwareConfirmation(char *uuid)
  11158. {
  11159. mtrace();
  11160. int result = FAIL;
  11161. char message[4096]={0};
  11162. json_object *UnpublishFirmware = json_object_new_object();
  11163. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11164. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11165. sprintf(message,"[%d,\"%s\",%s]"
  11166. ,MESSAGE_TYPE_CALLRESULT
  11167. ,uuid
  11168. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11169. json_object_put(UnpublishFirmware);
  11170. LWS_Send(message);
  11171. result = TRUE;
  11172. return result;
  11173. }
  11174. int sendUpdateFirmwareConfirmation(char *uuid)
  11175. {
  11176. mtrace();
  11177. int result = FAIL;
  11178. char message[4096]={0};
  11179. json_object *UpdateFirmware = json_object_new_object();
  11180. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11181. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11182. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11183. sprintf(message,"[%d,\"%s\",%s]"
  11184. ,MESSAGE_TYPE_CALLRESULT
  11185. ,uuid
  11186. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11187. json_object_put(UpdateFirmware);
  11188. LWS_Send(message);
  11189. result = TRUE;
  11190. return result;
  11191. }
  11192. int sendUnknownConfirmation(char *uuid)
  11193. {
  11194. mtrace();
  11195. int result = FAIL;
  11196. char message[256]={0};
  11197. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11198. DEBUG_INFO("sendUnknownConfirmation...\n");
  11199. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11200. LWS_Send(message);
  11201. result = TRUE;
  11202. return result;
  11203. }
  11204. //==========================================
  11205. // send CallError routine
  11206. //==========================================
  11207. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11208. {
  11209. mtrace();
  11210. char message[220]={0};
  11211. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11212. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11213. LWS_Send(message);
  11214. }
  11215. //==========================================
  11216. // Handle server request routine Start
  11217. //==========================================
  11218. int handleCancelReservationRequest(char *uuid, char *payload)
  11219. {
  11220. mtrace();
  11221. int result = FAIL;
  11222. int gunNO = 0;
  11223. int reservationIdInt = -1;
  11224. DEBUG_INFO("handleCancelReservationRequest...\n");
  11225. json_object *CancelReservation;
  11226. CancelReservation = json_tokener_parse(payload);
  11227. if(!is_error(CancelReservation))
  11228. {
  11229. // Required data
  11230. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11231. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11232. }
  11233. json_object_put(CancelReservation);
  11234. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11235. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11236. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11237. if(reservationIdInt != -1)
  11238. {
  11239. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11240. //check Transaction active
  11241. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11243. {
  11244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11245. {
  11246. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11247. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11248. {
  11249. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11250. }
  11251. else
  11252. {
  11253. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11254. }
  11255. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11256. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11257. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11258. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11259. goto end;
  11260. }
  11261. }
  11262. for (int index = 0; index < CCS_QUANTITY; index++)
  11263. {
  11264. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11265. {
  11266. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11267. if(gunType[2] == GUN_TYPE_CCS)
  11268. {
  11269. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11270. }
  11271. else
  11272. {
  11273. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11274. }
  11275. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11276. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11277. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11278. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11279. goto end;
  11280. }
  11281. }
  11282. for (int index = 0; index < GB_QUANTITY; index++)
  11283. {
  11284. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11285. {
  11286. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11287. if(gunType[2] == GUN_TYPE_GBT)
  11288. {
  11289. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11290. }
  11291. else
  11292. {
  11293. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11294. }
  11295. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11296. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11297. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11298. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11299. goto end;
  11300. }
  11301. }
  11302. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11303. {
  11304. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11305. {
  11306. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11307. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11308. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11309. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11310. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11311. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11312. goto end;
  11313. }
  11314. }
  11315. for (int index = 0; index < AC_QUANTITY; index++)
  11316. {
  11317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11318. {
  11319. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11321. {
  11322. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11323. }
  11324. else
  11325. {
  11326. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11327. }
  11328. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11329. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11330. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11331. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11332. goto end;
  11333. }
  11334. }
  11335. }
  11336. //The reservationId does NOT match the reservationId
  11337. sendCancelReservationConfirmation(uuid, gunNO);
  11338. end:
  11339. // Fill in ocpp packet uuid
  11340. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11341. return result;
  11342. }
  11343. int handleCertificateSignedRequest(char *uuid, char *payload)
  11344. {
  11345. mtrace();
  11346. int result = FAIL;
  11347. json_object *CertificateSigned;
  11348. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11349. CertificateSigned = json_tokener_parse(payload);
  11350. if(!is_error(CertificateSigned))
  11351. {
  11352. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11353. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11354. // Required data
  11355. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11356. // Optional data
  11357. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11358. {
  11359. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11360. }
  11361. else
  11362. {
  11363. if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11364. {
  11365. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]);
  11366. }
  11367. else if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11368. {
  11369. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]);
  11370. }
  11371. }
  11372. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11373. {
  11374. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  11375. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11376. fclose(fp);
  11377. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11378. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11379. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  11380. {
  11381. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11382. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  11383. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  11384. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  11385. }
  11386. else
  11387. {
  11388. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11389. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11390. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11391. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11392. }
  11393. }
  11394. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11395. {
  11396. FILE *fp = fopen("/Storage/OCPP/tempV2G.pem", "w");
  11397. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11398. fclose(fp);
  11399. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11400. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11401. if(certVerify(PRIVATE_KEY_V2G, "/Storage/OCPP/tempV2G.pem") == PASS)
  11402. {
  11403. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11404. system("rm -f /Storage/OCPP/certV2G_fallback.pem");
  11405. rename(CERTIFICATE_V2G, "/Storage/OCPP/certV2G_fallback.pem");
  11406. rename("/Storage/OCPP/tempV2G.pem", CERTIFICATE_V2G);
  11407. }
  11408. else
  11409. {
  11410. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11411. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11412. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11413. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11414. }
  11415. }
  11416. else
  11417. {
  11418. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11419. }
  11420. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11421. }
  11422. else
  11423. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11424. json_object_put(CertificateSigned);
  11425. sendCertificateSignedConfirmation(uuid);
  11426. return result;
  11427. }
  11428. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11429. {
  11430. mtrace();
  11431. int result = FAIL;
  11432. int evseId = 0, gunIndex = 0;
  11433. char operationalStatus[16]={0};
  11434. char comfirmstr[20];
  11435. //int specificId = FALSE;
  11436. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11437. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11438. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11439. json_object *ChangeAvailability;
  11440. ChangeAvailability = json_tokener_parse(payload);
  11441. if(!is_error(ChangeAvailability))
  11442. {
  11443. // Required data
  11444. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11445. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11446. // Requested evse. (When omitted, the message refers to the Charging Station as a whole.)
  11447. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11448. {
  11449. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id") != NULL)
  11450. {
  11451. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11452. if(evseId > 0){}
  11453. //specificId = TRUE;
  11454. else
  11455. goto end;
  11456. }
  11457. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11458. {
  11459. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11460. if(gunIndex != 1)
  11461. goto end;
  11462. }
  11463. }
  11464. }
  11465. json_object_put(ChangeAvailability);
  11466. if((evseId != 0) && (evseId <= gunTotalNumber))
  11467. {
  11468. ShmOCPP20Data->ChangeAvailability[evseId-1].evse.id = evseId;
  11469. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11470. }
  11471. else if(evseId == 0)
  11472. {
  11473. for(int i=0; i < gunTotalNumber; i++)
  11474. {
  11475. ShmOCPP20Data->ChangeAvailability[i].evse.id = i+1;
  11476. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11477. }
  11478. }
  11479. /*if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11480. {
  11481. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = 1;
  11482. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11483. }
  11484. else if(gunIndex == 0)
  11485. {
  11486. for(int i=0; i < gunTotalNumber; i++)
  11487. {
  11488. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = 1;
  11489. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11490. }
  11491. }*/
  11492. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11493. {
  11494. //----------------------evseId is 0 ------------------------------------------------//
  11495. if(evseId == 0)
  11496. {
  11497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11498. {
  11499. for(int i=0; i < gunTotalNumber; i++)
  11500. {
  11501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11502. {
  11503. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11504. {
  11505. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11506. {
  11507. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11508. goto end;
  11509. }
  11510. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11511. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11512. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11513. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11514. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11515. {
  11516. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11517. goto end;
  11518. }
  11519. }
  11520. }//END FOR CHAdeMO_QUANTITY
  11521. for (int index = 0; index < CCS_QUANTITY; index++)
  11522. {
  11523. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11524. {
  11525. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11526. {
  11527. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11528. goto end;
  11529. }
  11530. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11531. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11532. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11533. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11534. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11535. {
  11536. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11537. goto end;
  11538. }
  11539. }
  11540. }//END FOR CCS_QUANTITY
  11541. for (int index = 0; index < GB_QUANTITY; index++)
  11542. {
  11543. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11544. {
  11545. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11546. {
  11547. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11548. goto end;
  11549. }
  11550. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11551. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11552. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11553. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11555. {
  11556. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11557. goto end;
  11558. }
  11559. }
  11560. }// END FOR GB_QUANTITY
  11561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11562. {
  11563. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11564. {
  11565. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11566. {
  11567. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11568. goto end;
  11569. }
  11570. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11571. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11572. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11573. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11574. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11575. {
  11576. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11577. goto end;
  11578. }
  11579. }
  11580. }// END FOR DO_QUANTITY
  11581. for (int index = 0; index < AC_QUANTITY; index++)
  11582. {
  11583. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11584. {
  11585. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11586. {
  11587. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11588. goto end;
  11589. }
  11590. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11591. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11592. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11593. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11595. {
  11596. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11597. goto end;
  11598. }
  11599. }
  11600. }//END FOR AC_QUANTITY
  11601. }// END FOR gunTotalNumber
  11602. }
  11603. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11604. {
  11605. for(int i=0; i < gunTotalNumber; i++)
  11606. {
  11607. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11608. {
  11609. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11610. goto end;
  11611. }
  11612. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11613. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11614. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11615. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11616. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11617. {
  11618. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11619. goto end;
  11620. }
  11621. }
  11622. }
  11623. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11624. goto end;
  11625. }
  11626. //----------------------gunIndex is not 0 ------------------------------------------------//
  11627. //check Transaction active
  11628. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11629. {
  11630. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO))
  11631. {
  11632. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11633. {
  11634. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11635. goto end;
  11636. }
  11637. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11638. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11639. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11640. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11641. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11642. {
  11643. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11644. goto end;
  11645. }
  11646. else
  11647. {
  11648. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11649. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11650. goto end;
  11651. }
  11652. }
  11653. }//END FOR CHAdeMO_QUANTITY
  11654. for (int index = 0; index < CCS_QUANTITY; index++)
  11655. {
  11656. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS))
  11657. {
  11658. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11659. {
  11660. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11661. goto end;
  11662. }
  11663. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11664. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11665. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11666. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11667. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11668. {
  11669. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11670. goto end;
  11671. }
  11672. else
  11673. {
  11674. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11675. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11676. goto end;
  11677. }
  11678. }
  11679. }//END FOR CCS_QUANTITY
  11680. for (int index = 0; index < GB_QUANTITY; index++)
  11681. {
  11682. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))
  11683. {
  11684. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11685. {
  11686. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11687. goto end;
  11688. }
  11689. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11690. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11691. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11692. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11693. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11694. {
  11695. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11696. goto end;
  11697. }
  11698. else
  11699. {
  11700. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11701. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11702. goto end;
  11703. }
  11704. }
  11705. }// END FOR GB_QUANTITY
  11706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11707. {
  11708. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))
  11709. {
  11710. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11711. {
  11712. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11713. goto end;
  11714. }
  11715. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11716. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11717. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11718. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11719. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11720. {
  11721. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11722. goto end;
  11723. }
  11724. else
  11725. {
  11726. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11727. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11728. goto end;
  11729. }
  11730. }
  11731. }// END FOR DO_QUANTITY
  11732. for (int index = 0; index < AC_QUANTITY; index++)
  11733. {
  11734. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC))
  11735. {
  11736. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11737. {
  11738. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11739. goto end;
  11740. }
  11741. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11743. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11744. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11745. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11746. {
  11747. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11748. goto end;
  11749. }
  11750. else
  11751. {
  11752. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11753. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11754. goto end;
  11755. }
  11756. }
  11757. }//END FOR AC_QUANTITY
  11758. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11759. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11760. {
  11761. //----------------------gunIndex is 0 ------------------------------------------------//
  11762. if(evseId == 0)
  11763. {
  11764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11765. {
  11766. for(int i=0; i < gunTotalNumber; i++)
  11767. {
  11768. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11769. {
  11770. 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
  11771. {
  11772. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11773. goto end;
  11774. }
  11775. }//END FOR CHAdeMO_QUANTITY
  11776. for (int index = 0; index < CCS_QUANTITY; index++)
  11777. {
  11778. 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
  11779. {
  11780. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11781. goto end;
  11782. }
  11783. }//END FOR CCS_QUANTITY
  11784. for (int index = 0; index < GB_QUANTITY; index++)
  11785. {
  11786. 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
  11787. {
  11788. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11789. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11790. goto end;
  11791. }
  11792. }// END FOR GB_QUANTITY
  11793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11794. {
  11795. 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
  11796. {
  11797. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11798. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11799. goto end;
  11800. }
  11801. }// END FOR DO_QUANTITY
  11802. for (int index = 0; index < AC_QUANTITY; index++)
  11803. {
  11804. 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
  11805. {
  11806. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11807. goto end;
  11808. }
  11809. }//END FOR CHAdeMO_QUANTITY
  11810. }// END FOR gunTotalNumber
  11811. }
  11812. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11813. {
  11814. for(int i=0; i < gunTotalNumber; i++)
  11815. {
  11816. for (int index = 0; index < AC_QUANTITY; index++)
  11817. {
  11818. 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
  11819. {
  11820. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11821. goto end;
  11822. }
  11823. }//END FOR CHAdeMO_QUANTITY
  11824. } // END FOR gunTotalNumber
  11825. }
  11826. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11827. goto end;
  11828. }
  11829. //----------------------gunIndex is not 0 ------------------------------------------------//
  11830. //check Transaction active
  11831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11832. {
  11833. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11834. {
  11835. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11836. goto end;
  11837. }
  11838. }//END FOR CHAdeMO_QUANTITY
  11839. for (int index = 0; index < CCS_QUANTITY; index++)
  11840. {
  11841. if ((((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11842. {
  11843. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11844. goto end;
  11845. }
  11846. }//END FOR CCS_QUANTITY
  11847. for (int index = 0; index < GB_QUANTITY; index++)
  11848. {
  11849. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11850. {
  11851. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11852. goto end;
  11853. }
  11854. }// END FOR GB_QUANTITY
  11855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11856. {
  11857. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11858. {
  11859. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11860. goto end;
  11861. }
  11862. }// END FOR DO_QUANTITY
  11863. for (int index = 0; index < AC_QUANTITY; index++)
  11864. {
  11865. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11866. {
  11867. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11868. goto end;
  11869. }
  11870. }//END FOR AC_QUANTITY
  11871. }//END FOR AvailabilityEnumTypeStr[Operative]
  11872. end:
  11873. if((evseId > 0) && (evseId <= gunTotalNumber))
  11874. {
  11875. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].Response_status, "%s", comfirmstr );
  11876. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11877. ShmOCPP20Data->CsMsg.bits[evseId-1].ChangeAvailabilityReq = ON;
  11878. }
  11879. else if(evseId == 0)
  11880. {
  11881. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11882. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11883. {
  11884. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  11885. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  11886. }
  11887. }
  11888. else
  11889. {
  11890. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11891. }
  11892. sendChangeAvailabilityConfirmation(uuid, (evseId==0?evseId:evseId-1));
  11893. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11894. return result;
  11895. }
  11896. int handleClearCacheRequest(char *uuid, char *payload)
  11897. {
  11898. mtrace();
  11899. int result = FAIL;
  11900. char rmFileCmd[100]={0};
  11901. struct stat stats;
  11902. DEBUG_INFO("handleClearCacheRequest...\n");
  11903. stat("/Storage/OCPP", &stats);
  11904. // Check for directory existence
  11905. if (S_ISDIR(stats.st_mode) == 1)
  11906. {}
  11907. else
  11908. {
  11909. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  11910. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  11911. system(rmFileCmd);
  11912. }
  11913. if(DB_cleanLocalCache() != PASS)
  11914. {
  11915. DEBUG_INFO("open AuthorizationCache file failed\n");
  11916. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  11917. }
  11918. else
  11919. {
  11920. DEBUG_INFO("open AuthorizationCache file successful\n");
  11921. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  11922. }
  11923. sendClearCacheConfirmation(uuid);
  11924. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11925. return result;
  11926. }
  11927. int handleClearChargingProfileRequest(char *uuid, char *payload)
  11928. {
  11929. mtrace();
  11930. int result = FAIL;
  11931. int resultRename;
  11932. int evseIdInt, chargingProfileIdInt, stackLevelInt;
  11933. char chargingProfilePurposeStr[26]={0};
  11934. int tempevseIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  11935. char tempchargingProfilePurposeStr[26]={0};
  11936. char sstr[160]={0};
  11937. char str[100]={0};
  11938. int c = 0;
  11939. char *loc;
  11940. char fname[200]={0};
  11941. char comfirmstr[20]={0};
  11942. char word[1600]={0};
  11943. int clearflag = FALSE;
  11944. int chargingProfileIdIsNULL = FALSE;
  11945. int evseIsNULL = FALSE;
  11946. int chargingProfilePurposeIsNULL = FALSE;
  11947. int stackLevelIsNULL = FALSE;
  11948. //int GotoEnd = FALSE;
  11949. FILE *fptr1, *fptr2;
  11950. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  11951. int n_chargingProfile=0;
  11952. int isEmptyFile = FALSE;
  11953. char sLineWord[1600]={0};
  11954. char chargingProfiles[10][100]={0};
  11955. int ChargeProfileCount = 0;
  11956. int ch;
  11957. evseIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11958. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11959. json_object *ClearChargingProfile;
  11960. ClearChargingProfile = json_tokener_parse(payload);
  11961. if(!is_error(ClearChargingProfile))
  11962. {
  11963. // Optional data
  11964. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  11965. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  11966. else
  11967. chargingProfileIdIsNULL = TRUE;
  11968. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  11969. evseIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  11970. else
  11971. evseIsNULL = TRUE;
  11972. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  11973. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  11974. else
  11975. chargingProfilePurposeIsNULL = TRUE;
  11976. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  11977. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  11978. else
  11979. stackLevelIsNULL = TRUE;
  11980. }
  11981. json_object_put(ClearChargingProfile);
  11982. if(evseIsNULL == FALSE)
  11983. {
  11984. switch(evseIdInt)
  11985. {
  11986. case 0:
  11987. if(chargingProfilePurposeIsNULL == TRUE)
  11988. {
  11989. int l = 0;
  11990. strcpy(fname, ChargingStationMaxProfile_JSON);
  11991. if((access(fname,F_OK))!=-1)
  11992. {
  11993. strcpy(chargingProfiles[l], fname);
  11994. l = l + 1;
  11995. }
  11996. strcpy(fname, TxDefaultProfile_0_JSON);
  11997. if((access(fname,F_OK))!=-1)
  11998. {
  11999. strcpy(chargingProfiles[l], fname);
  12000. l = l + 1;
  12001. }
  12002. ChargeProfileCount = l;
  12003. }
  12004. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  12005. {
  12006. strcpy(fname, ChargingStationMaxProfile_JSON);
  12007. if((access(fname,F_OK))!=-1)
  12008. {
  12009. strcpy(chargingProfiles[0], fname);
  12010. ChargeProfileCount = 1;
  12011. }
  12012. }
  12013. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12014. {
  12015. strcpy(fname, TxDefaultProfile_0_JSON);
  12016. if((access(fname,F_OK))!=-1)
  12017. {
  12018. strcpy(chargingProfiles[0], fname);
  12019. ChargeProfileCount = 1;
  12020. }
  12021. }
  12022. break;
  12023. default:
  12024. if(chargingProfilePurposeIsNULL == TRUE)
  12025. {
  12026. int m = 0;
  12027. memset(fname, 0, ARRAY_SIZE(fname));
  12028. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12029. if((access(fname,F_OK))!=-1)
  12030. {
  12031. strcpy(chargingProfiles[m], fname);
  12032. m = m + 1;
  12033. }
  12034. memset(fname, 0, ARRAY_SIZE(fname));
  12035. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12036. if((access(fname,F_OK))!=-1)
  12037. {
  12038. strcpy(chargingProfiles[m], fname);
  12039. m = m + 1;
  12040. }
  12041. ChargeProfileCount = m;
  12042. }
  12043. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12044. {
  12045. //strcpy(fname, TxDefaultProfile_1_JSON);
  12046. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12047. if((access(fname,F_OK))!=-1)
  12048. {
  12049. strcpy(chargingProfiles[0], fname);
  12050. ChargeProfileCount = 1;
  12051. }
  12052. }
  12053. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  12054. {
  12055. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12056. if((access(fname,F_OK))!=-1)
  12057. {
  12058. strcpy(chargingProfiles[0], fname);
  12059. ChargeProfileCount = 1;
  12060. }
  12061. }
  12062. //strcpy(fname, ChargePointMaxProfile_JSON );
  12063. break;
  12064. }
  12065. }
  12066. else // Check all Charging Profiles
  12067. {
  12068. int i = 0;
  12069. char fnametemp[200]={0};
  12070. ChargeProfileCount = 0;
  12071. //Check ChargePointMaxProfile.json exit
  12072. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12073. {
  12074. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  12075. i = i + 1;
  12076. }
  12077. //Check TxDefaultProfile_%d.json
  12078. for(int j=1; j <= gunTotalNumber; j++)
  12079. {
  12080. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12081. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  12082. if((access(fnametemp,F_OK))!=-1)
  12083. {
  12084. strcpy(chargingProfiles[i], fnametemp);
  12085. i = i + 1;
  12086. }
  12087. }
  12088. //Check TxProfile_%d.json
  12089. for(int j=1; j <= gunTotalNumber; j++)
  12090. {
  12091. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12092. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  12093. if((access(fnametemp,F_OK))!=-1)
  12094. {
  12095. strcpy(chargingProfiles[i], fnametemp);
  12096. i = i + 1;
  12097. }
  12098. }
  12099. ChargeProfileCount = i;
  12100. }// End connectorIsNULL is TRUE
  12101. if(ChargeProfileCount == 0)
  12102. {
  12103. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12104. goto end;
  12105. }
  12106. if(evseIsNULL == FALSE && (evseIdInt != 0) && ( (evseIdInt-1) > gunTotalNumber) )
  12107. {
  12108. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12109. goto end;
  12110. }
  12111. if((evseIsNULL == FALSE) && (evseIdInt == 0) )
  12112. {
  12113. memset(str, 0, ARRAY_SIZE(str));
  12114. // clear temp file
  12115. sprintf(str,"rm -f %s",temp);
  12116. system(str);
  12117. for(int k=0; k < ChargeProfileCount; k++)
  12118. {
  12119. memset(str, 0, ARRAY_SIZE(str));
  12120. //clear file in C
  12121. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12122. system(str);
  12123. }
  12124. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12125. goto end;
  12126. }
  12127. else if(evseIsNULL == TRUE)
  12128. {
  12129. for(int k=0; k < ChargeProfileCount; k++)
  12130. {
  12131. fptr1 = fopen(chargingProfiles[k], "r");
  12132. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  12133. //Check Charging Profile Count
  12134. while(fscanf(fptr1, "%s", word) != EOF)
  12135. {
  12136. //DEBUG_INFO("word=%s\n",word);
  12137. if(strstr(word, "id")!= NULL)
  12138. {
  12139. //DEBUG_INFO("test id \n");
  12140. n_chargingProfile = n_chargingProfile + 1;
  12141. //DEBUG_INFO("id Found\n");
  12142. }
  12143. }
  12144. rewind(fptr1);
  12145. //search Charging Profile Element
  12146. //int i= 0;
  12147. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12148. {
  12149. //------------------------tempconnectorIdInt------------------------//
  12150. loc = strstr(sLineWord, "evseId");
  12151. c = 0;
  12152. memset(sstr ,0, sizeof(sstr) );
  12153. while (loc[strlen("evseId")+2+c] != ',')
  12154. {
  12155. sstr[c] = loc[strlen("evseId")+2+c];
  12156. c++;
  12157. }
  12158. sstr[c] = '\0';
  12159. tempevseIdInt = atoi(sstr);
  12160. printf("file's gun number is %d\n", tempevseIdInt);
  12161. //--------------------------id--------------------//
  12162. c = 0;
  12163. loc = strstr(sLineWord, "id");
  12164. memset(sstr ,0, ARRAY_SIZE(sstr));
  12165. while (loc[strlen("id")+2+c] != ',')
  12166. {
  12167. sstr[c] = loc[strlen("id")+2+c];
  12168. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12169. c++;
  12170. }
  12171. sstr[c] = '\0';
  12172. tempchargingProfileIdInt = atoi(sstr);
  12173. //stackLevel
  12174. c = 0;
  12175. loc = strstr(sLineWord, "stackLevel");
  12176. memset(sstr ,0, ARRAY_SIZE(sstr));
  12177. while (loc[strlen("stackLevel")+2+c] != ',')
  12178. {
  12179. sstr[c] = loc[strlen("stackLevel")+2+c];
  12180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12181. c++;
  12182. }
  12183. sstr[c] = '\0';
  12184. tempstackLevelInt = atoi(sstr);
  12185. c = 0;
  12186. loc = strstr(sLineWord, "chargingProfilePurpose");
  12187. memset(sstr ,0, ARRAY_SIZE(sstr));
  12188. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12189. {
  12190. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12191. c++;
  12192. }
  12193. sstr[c] = '\0';
  12194. strcpy(tempchargingProfilePurposeStr, sstr);
  12195. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12196. {
  12197. //------- not write to fptr2-------//
  12198. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12199. //clearflag = TRUE;
  12200. }
  12201. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12202. {
  12203. //------- not write to fptr2-------//
  12204. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12205. }
  12206. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12207. {
  12208. //------- not write to fptr2-------//
  12209. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12210. }
  12211. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12212. {
  12213. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12214. }
  12215. else
  12216. {
  12217. fprintf(fptr2, sLineWord);//writing data into file
  12218. }
  12219. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12220. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12221. if(clearflag == TRUE)
  12222. {
  12223. fclose(fptr1);
  12224. fclose(fptr2);
  12225. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12226. system(str);
  12227. // clear temp file
  12228. sprintf(str,"rm -f %s",temp);
  12229. system(str);
  12230. }
  12231. else
  12232. {
  12233. fclose(fptr1);
  12234. fclose(fptr2);
  12235. memset(str, 0, ARRAY_SIZE(str));
  12236. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12237. system(str);
  12238. resultRename = rename(temp, chargingProfiles[k]);
  12239. if(resultRename == 0)
  12240. {
  12241. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12242. }
  12243. else
  12244. {
  12245. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12246. }
  12247. if(comfirmstr[0]== 0)
  12248. {
  12249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12250. }
  12251. //Check chargingProfile is empty file
  12252. /*------ Read the file ----------------*/
  12253. fptr1=fopen(chargingProfiles[k],"r");
  12254. ch=fgetc(fptr1);
  12255. rewind(fptr1);
  12256. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12257. if(ch!=EOF)
  12258. {
  12259. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12260. {
  12261. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12262. if(sLineWord[0]=='\0')
  12263. {
  12264. isEmptyFile = TRUE;
  12265. break;
  12266. }
  12267. else
  12268. {
  12269. isEmptyFile = FALSE;
  12270. break;
  12271. }
  12272. }
  12273. }
  12274. else
  12275. isEmptyFile = TRUE;
  12276. fclose(fptr1);
  12277. if(isEmptyFile == TRUE)
  12278. {
  12279. memset(str, 0, ARRAY_SIZE(str));
  12280. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12281. system(str);
  12282. }
  12283. }
  12284. }// End of while(int k=0; k < ChargePointCount; k++)
  12285. }
  12286. else if((evseIsNULL == FALSE) && (evseIdInt != 0) )
  12287. {
  12288. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12289. for(int k=0; k < ChargeProfileCount; k++)
  12290. {
  12291. fptr1 = fopen(chargingProfiles[k], "r");
  12292. fptr2 = fopen(temp, "w+");
  12293. //Check Charging Profile Count
  12294. while(fscanf(fptr1, "%s", word) != EOF)
  12295. {
  12296. //DEBUG_INFO("word=%s\n",word);
  12297. if(strstr(word, "id")!= NULL)
  12298. {
  12299. n_chargingProfile = n_chargingProfile + 1;
  12300. }
  12301. }
  12302. rewind(fptr1);
  12303. //search Charging Profile Element
  12304. //int i= 0;
  12305. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12306. {
  12307. //*************************tempevseIdInt*********************************/
  12308. loc = strstr(sLineWord, "evseId");
  12309. c = 0;
  12310. memset(sstr ,0, ARRAY_SIZE(sstr));
  12311. while (loc[strlen("evseId")+2+c] != ',')
  12312. {
  12313. sstr[c] = loc[strlen("evseId")+2+c];
  12314. c++;
  12315. }
  12316. sstr[c] = '\0';
  12317. tempevseIdInt = atoi(sstr);
  12318. //id
  12319. c = 0;
  12320. loc = strstr(sLineWord, "id");
  12321. memset(sstr ,0, ARRAY_SIZE(sstr));
  12322. while (loc[strlen("id")+2+c] != ',')
  12323. {
  12324. sstr[c] = loc[strlen("id")+2+c];
  12325. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12326. c++;
  12327. }
  12328. sstr[c] = '\0';
  12329. tempchargingProfileIdInt = atoi(sstr);
  12330. //stackLevel
  12331. c = 0;
  12332. loc = strstr(sLineWord, "stackLevel");
  12333. memset(sstr ,0, ARRAY_SIZE(sstr));
  12334. while (loc[strlen("stackLevel")+2+c] != ',')
  12335. {
  12336. sstr[c] = loc[strlen("stackLevel")+2+c];
  12337. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12338. c++;
  12339. }
  12340. sstr[c] = '\0';
  12341. tempstackLevelInt = atoi(sstr);
  12342. c = 0;
  12343. loc = strstr(sLineWord, "chargingProfilePurpose");
  12344. memset(sstr ,0, ARRAY_SIZE(sstr));
  12345. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12346. {
  12347. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12348. c++;
  12349. }
  12350. sstr[c] = '\0';
  12351. strcpy(tempchargingProfilePurposeStr, sstr);
  12352. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12353. {
  12354. //------- not write to fptr2-------//
  12355. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12356. //clearflag = TRUE;
  12357. }
  12358. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12359. {
  12360. //------- not write to fptr2-------//
  12361. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12362. }
  12363. else if(stackLevelIsNULL == TRUE)
  12364. {
  12365. //Clear Whole File
  12366. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12367. clearflag = TRUE;
  12368. break;
  12369. }
  12370. else
  12371. {
  12372. fprintf(fptr2, sLineWord);//writing data into file
  12373. }
  12374. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12375. }
  12376. if(clearflag == TRUE)
  12377. {
  12378. fclose(fptr1);
  12379. fclose(fptr2);
  12380. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12381. system(str);
  12382. // clear temp file
  12383. sprintf(str,"rm -f %s",temp);
  12384. system(str);
  12385. }
  12386. else
  12387. {
  12388. fclose(fptr1);
  12389. fclose(fptr2);
  12390. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12391. system(str);
  12392. resultRename = rename(temp, chargingProfiles[k]);
  12393. if(resultRename == 0)
  12394. {
  12395. DEBUG_INFO("File ChargingProfile renamed successfully");
  12396. }
  12397. else
  12398. {
  12399. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12400. }
  12401. if(comfirmstr[0]== 0)
  12402. {
  12403. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12404. }
  12405. //Check chargingProfile is empty file
  12406. /*------ Read the file ----------------*/
  12407. fptr1=fopen(chargingProfiles[k],"r");
  12408. ch=fgetc(fptr1);
  12409. rewind(fptr1);
  12410. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12411. if(ch!=EOF)
  12412. {
  12413. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12414. {
  12415. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12416. if(sLineWord[0]=='\0')
  12417. {
  12418. isEmptyFile = TRUE;
  12419. break;
  12420. }
  12421. else
  12422. {
  12423. isEmptyFile = FALSE;
  12424. break;
  12425. }
  12426. }
  12427. }
  12428. else
  12429. isEmptyFile = TRUE;
  12430. fclose(fptr1);
  12431. if(isEmptyFile == TRUE)
  12432. {
  12433. memset(str, 0, ARRAY_SIZE(str));
  12434. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12435. system(str);
  12436. }
  12437. /*------- End of reading ---------------*/
  12438. }
  12439. } // while(int k=0; k < ChargeProfileCount; k++)
  12440. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12441. end:
  12442. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12443. {
  12444. if(evseIdInt == 0)
  12445. {
  12446. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12447. {
  12448. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12449. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12450. }
  12451. }
  12452. else
  12453. {
  12454. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12455. checkCompositeSchedule(evseIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[evseIdInt-1], 0, TRUE);
  12456. }
  12457. }
  12458. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12459. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12460. return result;
  12461. }
  12462. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12463. {
  12464. mtrace();
  12465. int result = FAIL;
  12466. json_object *ClearDisplayMessage;
  12467. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12468. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12469. ClearDisplayMessage = json_tokener_parse(payload);
  12470. if(!is_error(ClearDisplayMessage))
  12471. {
  12472. // Required data
  12473. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12474. {
  12475. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12476. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12477. }
  12478. }
  12479. json_object_put(ClearDisplayMessage);
  12480. sendCostUpdatedConfirmation(uuid);
  12481. return result;
  12482. }
  12483. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12484. {
  12485. mtrace();
  12486. int result = FAIL;
  12487. json_object *ClearVariableMonitorin;
  12488. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12489. ClearVariableMonitorin = json_tokener_parse(payload);
  12490. if(!is_error(ClearVariableMonitorin))
  12491. {
  12492. // Required data
  12493. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12494. {
  12495. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12496. {
  12497. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12498. /*
  12499. * TODO:
  12500. * 1. Check response
  12501. */
  12502. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12503. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12504. }
  12505. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12506. }
  12507. }
  12508. json_object_put(ClearVariableMonitorin);
  12509. return result;
  12510. }
  12511. int handleCostUpdatedRequest(char *uuid, char *payload)
  12512. {
  12513. mtrace();
  12514. int result = FAIL;
  12515. json_object *CostUpdate;
  12516. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12517. CostUpdate = json_tokener_parse(payload);
  12518. if(!is_error(CostUpdate))
  12519. {
  12520. // Required data
  12521. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12522. {
  12523. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12524. }
  12525. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12526. {
  12527. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12528. }
  12529. }
  12530. json_object_put(CostUpdate);
  12531. sendCostUpdatedConfirmation(uuid);
  12532. return result;
  12533. }
  12534. int handleCustomerInformationRequest(char *uuid, char *payload)
  12535. {
  12536. mtrace();
  12537. int result = FAIL;
  12538. json_object *CustomerInformation;
  12539. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12540. CustomerInformation = json_tokener_parse(payload);
  12541. if(!is_error(CustomerInformation))
  12542. {
  12543. // Required data
  12544. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12545. {
  12546. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12547. }
  12548. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12549. {
  12550. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12551. }
  12552. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12553. {
  12554. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12555. }
  12556. // Optional data
  12557. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12558. {
  12559. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12560. {
  12561. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12562. }
  12563. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12564. {
  12565. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12566. }
  12567. }
  12568. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12569. {
  12570. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12571. {
  12572. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12573. }
  12574. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12575. {
  12576. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12577. }
  12578. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12579. {
  12580. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12581. }
  12582. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12583. {
  12584. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12585. }
  12586. }
  12587. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12588. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12589. }
  12590. else
  12591. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12592. json_object_put(CustomerInformation);
  12593. sendCustomerInformationConfirmation(uuid);
  12594. return result;
  12595. }
  12596. void createFirmwareVersionByDataTransfer(void)
  12597. {
  12598. json_object *FirmwareDataTransfer = json_object_new_object();
  12599. // AC & DC model
  12600. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12601. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12602. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12603. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12604. // DC model
  12605. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12606. {
  12607. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12608. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12609. (gunType[3] != GUN_TYPE_UNKNOWN))
  12610. {
  12611. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12612. }
  12613. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12614. {
  12615. // DS DM DW
  12616. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12617. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12618. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12619. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12620. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12621. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12622. }
  12623. else
  12624. {
  12625. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12626. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12627. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12628. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12629. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12630. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12631. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12632. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12633. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12634. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12635. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12636. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12637. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12638. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12639. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12640. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12641. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12642. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12643. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12644. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12645. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12646. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12647. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12648. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12649. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12650. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12651. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12652. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12653. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12654. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12655. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12656. }
  12657. }
  12658. // 4G model
  12659. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12660. {
  12661. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12662. }
  12663. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12664. json_object_put(FirmwareDataTransfer);
  12665. }
  12666. int handleDataTransferRequest(char *uuid, char *payload)
  12667. {
  12668. mtrace();
  12669. int result = PASS;
  12670. DEBUG_INFO("handleDataTransferRequest...\n");
  12671. if((uuid != NULL) && (payload != NULL))
  12672. {
  12673. json_object *DataTransfer;
  12674. DataTransfer = json_tokener_parse(payload);
  12675. if(!is_error(DataTransfer))
  12676. {
  12677. // Required data
  12678. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12679. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12680. // Optional data
  12681. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12682. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12683. if(json_object_object_get(DataTransfer, "data") != NULL)
  12684. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12685. result = PASS;
  12686. }
  12687. json_object_put(DataTransfer);
  12688. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12689. {
  12690. // Send all moudle firmware version on EVSE
  12691. createFirmwareVersionByDataTransfer();
  12692. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12693. }
  12694. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12695. {
  12696. system("/usr/bin/run_tmate_restart.sh &");
  12697. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12698. }
  12699. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12700. {
  12701. json_object *data;
  12702. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12703. if(!is_error(data))
  12704. {
  12705. 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))
  12706. {
  12707. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12708. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12709. if(json_object_object_get(data, "SOC") != NULL)
  12710. {
  12711. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12712. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12713. }
  12714. if(json_object_object_get(data, "Energy") != NULL)
  12715. {
  12716. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12717. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12718. }
  12719. if(json_object_object_get(data, "Duration") != NULL)
  12720. {
  12721. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12722. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12723. }
  12724. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12725. }
  12726. else
  12727. {
  12728. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12729. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12730. }
  12731. }
  12732. else
  12733. {
  12734. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12735. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12736. }
  12737. json_object_put(data);
  12738. }
  12739. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12740. {
  12741. json_object *data;
  12742. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12743. if(!is_error(data))
  12744. {
  12745. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12746. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12747. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12748. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12749. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12750. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12751. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12752. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12753. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12754. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12755. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12756. }
  12757. else
  12758. {
  12759. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12760. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12761. }
  12762. json_object_put(data);
  12763. }
  12764. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12765. {
  12766. json_object *data;
  12767. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12768. if(!is_error(data))
  12769. {
  12770. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12771. if(json_object_object_get(data, "Content_Type") != NULL)
  12772. {
  12773. 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))
  12774. {
  12775. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12776. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12777. {
  12778. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12779. }
  12780. }
  12781. else
  12782. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12783. }
  12784. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12785. }
  12786. else
  12787. {
  12788. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12789. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12790. }
  12791. json_object_put(data);
  12792. }
  12793. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12794. {
  12795. json_object *data;
  12796. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12797. if(!is_error(data))
  12798. {
  12799. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12800. if(json_object_object_get(data, "ConnectorId") != NULL)
  12801. {
  12802. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12803. }
  12804. if(json_object_object_get(data, "Page_Index") != NULL)
  12805. {
  12806. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12807. }
  12808. if(json_object_object_get(data, "Duration") != NULL)
  12809. {
  12810. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12811. }
  12812. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12813. }
  12814. else
  12815. {
  12816. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12817. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12818. }
  12819. json_object_put(data);
  12820. }
  12821. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12822. {
  12823. json_object *data;
  12824. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12825. if(!is_error(data))
  12826. {
  12827. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12828. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12829. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12830. {
  12831. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12832. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12833. else
  12834. {
  12835. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12836. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12837. }
  12838. }
  12839. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12840. {
  12841. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12842. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12843. else
  12844. {
  12845. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12846. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12847. }
  12848. }
  12849. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12850. {
  12851. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12852. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12853. else
  12854. {
  12855. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12856. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12857. }
  12858. }
  12859. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12860. {
  12861. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12862. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12863. else
  12864. {
  12865. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12866. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12867. }
  12868. }
  12869. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12870. {
  12871. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12872. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12873. else
  12874. {
  12875. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12876. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12877. }
  12878. }
  12879. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12880. {
  12881. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  12882. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  12883. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  12884. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  12885. else
  12886. {
  12887. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12888. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12889. }
  12890. }
  12891. if(json_object_object_get(data, "isAuthentication") != NULL)
  12892. {
  12893. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  12894. {
  12895. case 0:
  12896. case 1:
  12897. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  12898. break;
  12899. default:
  12900. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12901. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12902. break;
  12903. }
  12904. }
  12905. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  12906. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12907. }
  12908. else
  12909. {
  12910. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12911. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12912. }
  12913. json_object_put(data);
  12914. }
  12915. else
  12916. {
  12917. // Can not find valid message id
  12918. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12919. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  12920. ,ShmOCPP20Data->DataTransfer[0].vendorId
  12921. ,ShmOCPP20Data->DataTransfer[0].messageId
  12922. ,ShmOCPP20Data->DataTransfer[0].data);
  12923. }
  12924. }
  12925. else
  12926. {
  12927. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12928. result = FAIL;
  12929. }
  12930. sendDataTransferConfirmation(uuid, 0);
  12931. return result;
  12932. }
  12933. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12934. {
  12935. mtrace();
  12936. int result = FAIL;
  12937. json_object *DeleteCertificate;
  12938. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12939. DeleteCertificate = json_tokener_parse(payload);
  12940. if(!is_error(DeleteCertificate))
  12941. {
  12942. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  12943. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  12944. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12945. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12946. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12947. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12948. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12949. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12950. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12951. DEBUG_INFO("serialNumber: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber);
  12952. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  12953. {
  12954. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  12955. }
  12956. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  12957. {
  12958. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  12959. }
  12960. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  12961. {
  12962. ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  12963. }
  12964. char temp[256] = {0};
  12965. char compareData[256] = {0};
  12966. int isMatch = TRUE;
  12967. // Check CentralSystemRootCertificate
  12968. if(access(ROOTCA_CS,F_OK) != -1)
  12969. {
  12970. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  12971. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  12972. for(int i = 0; compareData[i]; i++)
  12973. {
  12974. compareData[i] = tolower(compareData[i]);
  12975. }
  12976. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  12977. isMatch = FALSE;
  12978. if(isMatch == TRUE)
  12979. {
  12980. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  12981. for(int i = 0; compareData[i]; i++)
  12982. {
  12983. compareData[i] = tolower(compareData[i]);
  12984. }
  12985. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  12986. isMatch = FALSE;
  12987. }
  12988. if(isMatch == TRUE)
  12989. {
  12990. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  12991. for(int i = 0; compareData[i]; i++)
  12992. {
  12993. compareData[i] = tolower(compareData[i]);
  12994. }
  12995. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  12996. isMatch = FALSE;
  12997. }
  12998. if(isMatch == TRUE)
  12999. {
  13000. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  13001. sprintf(temp, "rm -f %s", ROOTCA_CS);
  13002. system(temp);
  13003. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13004. goto End;
  13005. }
  13006. }
  13007. // Check ManufacturerRootCertificate
  13008. if(access(ROOTCA_MF,F_OK) != -1)
  13009. {
  13010. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  13011. isMatch = TRUE;
  13012. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  13013. for(int i = 0; compareData[i]; i++)
  13014. {
  13015. compareData[i] = tolower(compareData[i]);
  13016. }
  13017. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13018. isMatch = FALSE;
  13019. if(isMatch == TRUE)
  13020. {
  13021. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  13022. for(int i = 0; compareData[i]; i++)
  13023. {
  13024. compareData[i] = tolower(compareData[i]);
  13025. }
  13026. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13027. isMatch = FALSE;
  13028. }
  13029. if(isMatch == TRUE)
  13030. {
  13031. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  13032. for(int i = 0; compareData[i]; i++)
  13033. {
  13034. compareData[i] = tolower(compareData[i]);
  13035. }
  13036. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13037. isMatch = FALSE;
  13038. }
  13039. if(isMatch == TRUE)
  13040. {
  13041. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  13042. sprintf(temp, "rm -f %s", ROOTCA_MF);
  13043. system(temp);
  13044. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13045. goto End;
  13046. }
  13047. }
  13048. if(access(ROOTCA_V2G,F_OK) != -1)
  13049. {
  13050. DEBUG_INFO("Checking V2GRootCertificate...\n");
  13051. isMatch = TRUE;
  13052. parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, compareData);
  13053. for(int i = 0; compareData[i]; i++)
  13054. {
  13055. compareData[i] = tolower(compareData[i]);
  13056. }
  13057. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13058. isMatch = FALSE;
  13059. if(isMatch == TRUE)
  13060. {
  13061. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, compareData);
  13062. for(int i = 0; compareData[i]; i++)
  13063. {
  13064. compareData[i] = tolower(compareData[i]);
  13065. }
  13066. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13067. isMatch = FALSE;
  13068. }
  13069. if(isMatch == TRUE)
  13070. {
  13071. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  13072. for(int i = 0; compareData[i]; i++)
  13073. {
  13074. compareData[i] = tolower(compareData[i]);
  13075. }
  13076. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13077. isMatch = FALSE;
  13078. }
  13079. if(isMatch == TRUE)
  13080. {
  13081. DEBUG_INFO("Deleting V2GRootCertificate...\n");
  13082. sprintf(temp, "rm -f %s", ROOTCA_V2G);
  13083. system(temp);
  13084. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13085. goto End;
  13086. }
  13087. }
  13088. if(access(ROOTCA_MO,F_OK) != -1)
  13089. {
  13090. DEBUG_INFO("Checking MORootCertificate...\n");
  13091. isMatch = TRUE;
  13092. parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, compareData);
  13093. for(int i = 0; compareData[i]; i++)
  13094. {
  13095. compareData[i] = tolower(compareData[i]);
  13096. }
  13097. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13098. isMatch = FALSE;
  13099. if(isMatch == TRUE)
  13100. {
  13101. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, compareData);
  13102. for(int i = 0; compareData[i]; i++)
  13103. {
  13104. compareData[i] = tolower(compareData[i]);
  13105. }
  13106. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13107. isMatch = FALSE;
  13108. }
  13109. if(isMatch == TRUE)
  13110. {
  13111. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, compareData);
  13112. for(int i = 0; compareData[i]; i++)
  13113. {
  13114. compareData[i] = tolower(compareData[i]);
  13115. }
  13116. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13117. isMatch = FALSE;
  13118. }
  13119. if(isMatch == TRUE)
  13120. {
  13121. DEBUG_INFO("Deleting MORootCertificate...\n");
  13122. sprintf(temp, "rm -f %s", ROOTCA_MO);
  13123. system(temp);
  13124. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13125. goto End;
  13126. }
  13127. }
  13128. // Check certCP
  13129. if(access(CERTIFICATE_CP,F_OK) != -1)
  13130. {
  13131. DEBUG_INFO("Checking certCP...\n");
  13132. isMatch = TRUE;
  13133. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  13134. for(int i = 0; compareData[i]; i++)
  13135. {
  13136. compareData[i] = tolower(compareData[i]);
  13137. }
  13138. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13139. isMatch = FALSE;
  13140. if(isMatch == TRUE)
  13141. {
  13142. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  13143. for(int i = 0; compareData[i]; i++)
  13144. {
  13145. compareData[i] = tolower(compareData[i]);
  13146. }
  13147. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13148. isMatch = FALSE;
  13149. }
  13150. if(isMatch == TRUE)
  13151. {
  13152. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  13153. for(int i = 0; compareData[i]; i++)
  13154. {
  13155. compareData[i] = tolower(compareData[i]);
  13156. }
  13157. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13158. isMatch = FALSE;
  13159. }
  13160. if(isMatch == TRUE)
  13161. {
  13162. DEBUG_INFO("Deleting certCP...\n");
  13163. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  13164. system(temp);
  13165. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13166. goto End;
  13167. }
  13168. }
  13169. }
  13170. else
  13171. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  13172. End:
  13173. json_object_put(DeleteCertificate);
  13174. ShmOCPP20Data->MsMsg.bits.DeleteCertificateReq = 1;
  13175. sendDeleteCertificateConfirmation(uuid);
  13176. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13177. return result;
  13178. }
  13179. int handleGetBaseReportRequest(char *uuid, char *payload)
  13180. {
  13181. mtrace();
  13182. int result = FAIL;
  13183. json_object *GetBaseRepor;
  13184. DEBUG_INFO("handleGetBaseReportRequest...\n");
  13185. GetBaseRepor = json_tokener_parse(payload);
  13186. if(!is_error(GetBaseRepor))
  13187. {
  13188. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  13189. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  13190. // Required data
  13191. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  13192. {
  13193. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  13194. }
  13195. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  13196. {
  13197. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  13198. }
  13199. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  13200. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13201. else
  13202. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13203. }
  13204. else
  13205. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13206. json_object_put(GetBaseRepor);
  13207. sendGetBaseReportConfirmation(uuid);
  13208. return result;
  13209. }
  13210. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  13211. {
  13212. mtrace();
  13213. int result = FAIL;
  13214. int gun_index = -1;
  13215. json_object *GetChargingProfiles;
  13216. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  13217. GetChargingProfiles = json_tokener_parse(payload);
  13218. if(!is_error(GetChargingProfiles))
  13219. {
  13220. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  13221. {
  13222. 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;
  13223. }
  13224. if(gun_index >-1)
  13225. {
  13226. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  13227. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  13228. // Required data
  13229. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  13230. {
  13231. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  13232. }
  13233. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  13234. {
  13235. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  13236. {
  13237. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  13238. }
  13239. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  13240. {
  13241. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  13242. }
  13243. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  13244. {
  13245. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  13246. {
  13247. 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)));
  13248. }
  13249. }
  13250. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  13251. {
  13252. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  13253. {
  13254. 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));
  13255. }
  13256. }
  13257. }
  13258. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  13259. }
  13260. else
  13261. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  13262. }
  13263. json_object_put(GetChargingProfiles);
  13264. sendGetChargingProfilesConfirmation(uuid, gun_index);
  13265. return result;
  13266. }
  13267. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  13268. {
  13269. mtrace();
  13270. int result = FAIL;
  13271. int evseIdInt, durationInt;
  13272. char chargingRateUnitStr[4]={0};
  13273. char comfirmstr[20];
  13274. int confirmPeriods = 0;
  13275. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  13276. json_object *GetCompositeSchedule;
  13277. GetCompositeSchedule = json_tokener_parse(payload);
  13278. if(!is_error(GetCompositeSchedule))
  13279. {
  13280. // Required data
  13281. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  13282. evseIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  13283. else
  13284. evseIdInt = -1;
  13285. if(json_object_object_get(GetCompositeSchedule, "duration"))
  13286. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  13287. else
  13288. durationInt = 86400;
  13289. // Optional data
  13290. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  13291. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  13292. }
  13293. json_object_put(GetCompositeSchedule);
  13294. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  13295. if((evseIdInt == 0) ||
  13296. ((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber)))
  13297. {
  13298. int gun_index = (evseIdInt==0?0:evseIdInt-1);
  13299. struct ChargingProfileType tmpProfile[1];
  13300. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  13301. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  13302. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  13303. {
  13304. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  13305. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  13306. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  13307. }
  13308. else
  13309. {
  13310. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  13311. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  13312. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  13313. }
  13314. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13315. {
  13316. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  13317. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  13318. }
  13319. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  13320. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  13321. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13322. {
  13323. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  13324. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  13325. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  13326. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  13327. (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))
  13328. {
  13329. confirmPeriods = idx;
  13330. break;
  13331. }
  13332. }
  13333. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  13334. {
  13335. confirmPeriods += 1;
  13336. }
  13337. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13338. }
  13339. else
  13340. {
  13341. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  13342. }
  13343. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, evseIdInt, confirmPeriods);
  13344. return result;
  13345. }
  13346. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  13347. {
  13348. mtrace();
  13349. int result = FAIL;
  13350. json_object *GetDisplayMessages;
  13351. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  13352. GetDisplayMessages = json_tokener_parse(payload);
  13353. if(!is_error(GetDisplayMessages))
  13354. {
  13355. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  13356. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  13357. // Required data
  13358. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  13359. {
  13360. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  13361. }
  13362. // Optional data
  13363. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  13364. {
  13365. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  13366. }
  13367. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  13368. {
  13369. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  13370. }
  13371. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  13372. {
  13373. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  13374. {
  13375. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  13376. }
  13377. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  13378. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  13379. }
  13380. else
  13381. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  13382. }
  13383. json_object_put(GetDisplayMessages);
  13384. return result;
  13385. }
  13386. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13387. {
  13388. mtrace();
  13389. int result = FAIL;
  13390. int certCnt = 0;
  13391. unsigned char foundCertCnt = 0;
  13392. json_object *GetInstalledCertificateIds;
  13393. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13394. GetInstalledCertificateIds = json_tokener_parse(payload);
  13395. if(!is_error(GetInstalledCertificateIds))
  13396. {
  13397. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13398. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13399. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13400. // Optional data
  13401. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13402. {
  13403. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13404. {
  13405. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13406. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13407. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "Accepted");
  13408. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  13409. // Check CSMSRootCertificate
  13410. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "CSMSRootCertificate")!= NULL)
  13411. {
  13412. if(access(ROOTCA_CS,F_OK) != -1)
  13413. {
  13414. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "CSMSRootCertificate");
  13415. char parseData[512] = {0};
  13416. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13417. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13418. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  13419. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13420. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13421. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13422. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13423. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13424. certCnt++;
  13425. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13426. }
  13427. else
  13428. {
  13429. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  13430. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13431. }
  13432. }
  13433. // Check ManufacturerRootCertificate
  13434. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "ManufacturerRootCertificate") != NULL)
  13435. {
  13436. if(access(ROOTCA_MF,F_OK) != -1)
  13437. {
  13438. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "ManufacturerRootCertificate");
  13439. char parseData[512] = {0};
  13440. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13441. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13442. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  13443. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13444. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13445. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13446. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13447. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13448. certCnt++;
  13449. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13450. }
  13451. else
  13452. {
  13453. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  13454. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13455. }
  13456. }
  13457. // Check MORootCertificate
  13458. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "MORootCertificate") != NULL)
  13459. {
  13460. if(access(ROOTCA_MO,F_OK) != -1)
  13461. {
  13462. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "MORootCertificate");
  13463. char parseData[512] = {0};
  13464. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13465. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13466. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, parseData) == PASS)
  13467. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13468. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13469. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13470. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13471. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13472. certCnt++;
  13473. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13474. }
  13475. else
  13476. {
  13477. DEBUG_INFO(">>> No MORootCertificate was found.\n");
  13478. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13479. }
  13480. }
  13481. // Check V2GRootCertificate
  13482. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GRootCertificate") != NULL)
  13483. {
  13484. if(access(ROOTCA_V2G,F_OK) != -1)
  13485. {
  13486. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GRootCertificate");
  13487. char parseData[512] = {0};
  13488. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13489. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13490. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13491. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13492. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13493. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13494. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13495. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13496. certCnt++;
  13497. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13498. }
  13499. else
  13500. {
  13501. DEBUG_INFO(">>> No V2GRootCertificate was found.\n");
  13502. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13503. }
  13504. }
  13505. // Check V2GCertificateChain
  13506. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GCertificateChain") != NULL)
  13507. {
  13508. if(access(CERTIFICATE_V2G,F_OK) != -1)
  13509. {
  13510. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GCertificateChain");
  13511. char parseData[512] = {0};
  13512. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13513. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13514. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13515. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13516. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13517. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13518. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13519. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13520. certCnt++;
  13521. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13522. }
  13523. else
  13524. {
  13525. DEBUG_INFO(">>> No V2GCertificateChain was found.\n");
  13526. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13527. }
  13528. }
  13529. else
  13530. {
  13531. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13532. }
  13533. }
  13534. }
  13535. else
  13536. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13537. }
  13538. json_object_put(GetInstalledCertificateIds);
  13539. sendGetInstalledCertificateIdsConfirmation(uuid, foundCertCnt);
  13540. return result;
  13541. }
  13542. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13543. {
  13544. mtrace();
  13545. int result = FAIL;
  13546. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13547. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13548. {
  13549. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13550. localversion = 0;
  13551. }
  13552. else
  13553. {
  13554. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13555. localversion = 0;
  13556. DB_getListVerion();
  13557. }
  13558. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13559. sendGetLocalListVersionConfirmation(uuid);
  13560. return result;
  13561. }
  13562. static char fnamePlusPath[100]={0};
  13563. static char fnamePWithNoPath[60]={0};
  13564. void checkUploadLog(void)
  13565. {
  13566. FILE *fp;
  13567. /* Open the command for reading. */
  13568. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13569. if (fp == NULL) {
  13570. printf("Failed to run command\n" );
  13571. exit(1);
  13572. }
  13573. int ftppathlen = 0;
  13574. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13575. int i = 0;
  13576. /* Read the output a line at a time - output it. */
  13577. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13578. if(i==0)
  13579. {
  13580. ftppathlen = strlen(fnamePlusPath);
  13581. printf("%s\n", fnamePlusPath);
  13582. fnamePlusPath[ftppathlen]='\0';
  13583. break;
  13584. }
  13585. i= i+1;
  13586. }
  13587. /* close */
  13588. pclose(fp);
  13589. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13590. {
  13591. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13592. {
  13593. fnamePlusPath[k]='\0';
  13594. }
  13595. }
  13596. i=1;
  13597. //char fname[60]={0};
  13598. while(i < ftppathlen)
  13599. {
  13600. int len=ftppathlen-i;
  13601. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13602. {
  13603. printf("compare '/' all right\n");
  13604. break;
  13605. }
  13606. i=i+1;
  13607. }
  13608. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13609. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13610. fnamePWithNoPath[i+1] = '\0';
  13611. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13612. {
  13613. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13614. {
  13615. fnamePWithNoPath[j]='\0';
  13616. }
  13617. }
  13618. FILE* fp1 = fopen(fnamePlusPath, "r");
  13619. if (fp1)
  13620. {
  13621. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13622. // file exists
  13623. fclose(fp1);
  13624. }
  13625. else
  13626. {
  13627. // file doesn't exist
  13628. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13629. }
  13630. }
  13631. void* GetLogProcess(void* data)
  13632. {
  13633. th_GetLog = pthread_self();
  13634. pthread_detach(pthread_self());
  13635. mtrace();
  13636. int requestId, retriesInt=0, retryIntervalInt=0;
  13637. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13638. 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};
  13639. int port=0;
  13640. int isSuccess = FALSE;
  13641. char ftpbuf[1024]={0};
  13642. char cmdBuf[2048];
  13643. struct tm *tmNow;
  13644. time_t CurrentTime;
  13645. struct tm tmStart;
  13646. struct tm tmStop;
  13647. CurrentTime = time(NULL);
  13648. tmNow=localtime(&CurrentTime);
  13649. uint16_t targetYear, targetMonth;
  13650. json_object *GetLog;
  13651. DEBUG_INFO("GetGetProcess...\n");
  13652. GetLog = json_tokener_parse(data);
  13653. if(!is_error(GetLog))
  13654. {
  13655. // Required data
  13656. if(json_object_object_get(GetLog, "requestId") != NULL)
  13657. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13658. if(json_object_object_get(GetLog, "logType") != NULL)
  13659. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13660. if(json_object_object_get(GetLog, "log") != NULL)
  13661. {
  13662. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13663. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13664. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13665. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13666. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13667. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13668. }
  13669. // Optional data
  13670. if(json_object_object_get(GetLog, "retries") != NULL)
  13671. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13672. else
  13673. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13674. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13675. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13676. else
  13677. retryIntervalInt = 30;
  13678. }
  13679. json_object_put(GetLog);
  13680. ShmOCPP20Data->GetLog.requestId = requestId;
  13681. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13682. {
  13683. /*
  13684. * TODO:
  13685. * 1. Pack security log
  13686. */
  13687. }
  13688. else
  13689. {
  13690. // Pack log to compress file
  13691. 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) &&
  13692. (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))
  13693. {
  13694. // Pack system log
  13695. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13696. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13697. targetYear = tmStart.tm_year;
  13698. targetMonth = tmStart.tm_mon;
  13699. do
  13700. {
  13701. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13702. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13703. if(targetMonth+1>=13)
  13704. {
  13705. targetYear += 1;
  13706. targetMonth = 1;
  13707. }
  13708. else
  13709. {
  13710. targetMonth += 1;
  13711. }
  13712. }while((targetYear < (tmNow->tm_year+1900)) ||
  13713. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13714. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13715. system(cmdBuf);
  13716. // Pack charging & event log
  13717. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13718. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13719. targetYear = tmStart.tm_year;
  13720. targetMonth = tmStart.tm_mon;
  13721. do
  13722. {
  13723. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13724. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  13725. if(targetMonth+1>=13)
  13726. {
  13727. targetYear += 1;
  13728. targetMonth = 1;
  13729. }
  13730. else
  13731. {
  13732. targetMonth += 1;
  13733. }
  13734. }while((targetYear < (tmNow->tm_year+1900)) ||
  13735. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13736. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13737. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13738. system(cmdBuf);
  13739. // Combine log file
  13740. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13741. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13742. }
  13743. else
  13744. {
  13745. system("exec /root/logPackTools 'log' 6");
  13746. }
  13747. }
  13748. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13749. system(cmdBuf);
  13750. checkUploadLog();
  13751. //****************location*******************/
  13752. if(strcmp(remoteLocation,"")==0)
  13753. {
  13754. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13755. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13756. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13757. goto end;
  13758. }
  13759. memset(protocol, 0, ARRAY_SIZE(protocol));
  13760. memset(user, 0, ARRAY_SIZE(user) );
  13761. memset(password, 0, ARRAY_SIZE(password));
  13762. memset(host, 0, ARRAY_SIZE(host));
  13763. memset(path, 0, ARRAY_SIZE(path));
  13764. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13765. memset(host1, 0, ARRAY_SIZE(host1));
  13766. memset(path1, 0, ARRAY_SIZE(path1));
  13767. /*location: ftp://user:password@host:port/path*/
  13768. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13769. if((access(fnamePlusPath,F_OK))!=-1)
  13770. {
  13771. DEBUG_INFO("fnamePlusPath exist.\n");
  13772. }
  13773. else
  13774. {
  13775. DEBUG_INFO("fnamePlusPath not exist!\n");
  13776. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13777. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13778. goto end;
  13779. }
  13780. if(strchr(remoteLocation,'@')==NULL)
  13781. {
  13782. sscanf(remoteLocation,
  13783. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13784. protocol, host, &port, path);
  13785. strcpy(user,"anonymous");
  13786. strcpy(password,"");
  13787. }
  13788. else
  13789. {
  13790. //DEBUG_INFO("pch=%s\n", pch);
  13791. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13792. protocol, user, password, host, &port, path);
  13793. }
  13794. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13795. {
  13796. DEBUG_INFO("protocol is not ftp/http ! \n");
  13797. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13798. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13799. goto end;
  13800. }
  13801. if(strncmp(remoteLocation,"http", 4) == 0)
  13802. {
  13803. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13804. sprintf(ftppath,"/%s", path);
  13805. do
  13806. {
  13807. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13808. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13809. sleep(3);
  13810. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13811. if(!isSuccess)
  13812. {
  13813. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13814. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13815. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13816. sleep(retryIntervalInt);
  13817. }
  13818. else
  13819. {
  13820. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13821. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13822. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13823. }
  13824. retriesInt--;
  13825. }while((isSuccess == 0)&&(retriesInt >= 0));
  13826. }
  13827. else
  13828. {
  13829. sscanf(host,"%[^/]%s",host1, path1);
  13830. if(strlen(path) > 0)
  13831. sprintf(ftppath,"/%s", path);
  13832. else
  13833. sprintf(ftppath,"/%s", path1);
  13834. int ftppathlen=strlen(ftppath);
  13835. int i=1;
  13836. char filenametemp[50];
  13837. while(i < ftppathlen)
  13838. {
  13839. int len=ftppathlen-i;
  13840. if(ftppath[len]== 47) // '/' ascll code: 47
  13841. {
  13842. DEBUG_INFO("find '/' all right\n");
  13843. break;
  13844. }
  13845. i=i+1;
  13846. }
  13847. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13848. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13849. filenametemp[i+1] = 0;
  13850. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13851. if(port == 0)
  13852. port = 21;
  13853. do
  13854. {
  13855. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13856. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13857. sleep(3);
  13858. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13859. if(!isSuccess)
  13860. {
  13861. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13862. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13863. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13864. sleep(retryIntervalInt);
  13865. }
  13866. else
  13867. {
  13868. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13869. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13870. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13871. }
  13872. retriesInt--;
  13873. }while((!isSuccess)&&(retriesInt >= 0));
  13874. }
  13875. end:
  13876. system("rm -f /mnt/*");
  13877. sleep(5);
  13878. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13879. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13880. interLock.isGetLogGoing = OFF;
  13881. pthread_exit(NULL);
  13882. }
  13883. int handleGetLogRequest(char *uuid, char *payload)
  13884. {
  13885. mtrace();
  13886. int result = FAIL;
  13887. char fName[258];
  13888. time_t CurrentTime;
  13889. struct tm *tm;
  13890. pthread_t th_Status;
  13891. DEBUG_INFO("handleGetLogRequest...\n");
  13892. CurrentTime = time(NULL);
  13893. tm = localtime(&CurrentTime);
  13894. 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);
  13895. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  13896. if(interLock.isGetLogGoing)
  13897. {
  13898. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  13899. isCancelUploadLog = TRUE;
  13900. pthread_cancel(th_GetLog);
  13901. interLock.isGetLogGoing = OFF;
  13902. sleep(1);
  13903. isCancelUploadLog = OFF;
  13904. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  13905. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13906. sleep(1);
  13907. }
  13908. else
  13909. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  13910. sendGetLogConfirmation(uuid);
  13911. if(!interLock.isGetLogGoing)
  13912. {
  13913. interLock.isGetLogGoing = ON;
  13914. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  13915. sleep(1);
  13916. }
  13917. else
  13918. {
  13919. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  13920. }
  13921. return result;
  13922. }
  13923. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  13924. {
  13925. mtrace();
  13926. int result = FAIL;
  13927. json_object *GetMonitoringReport;
  13928. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  13929. GetMonitoringReport = json_tokener_parse(payload);
  13930. if(!is_error(GetMonitoringReport))
  13931. {
  13932. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  13933. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  13934. // Required data
  13935. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  13936. {
  13937. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  13938. }
  13939. // Optional data
  13940. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  13941. {
  13942. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  13943. }
  13944. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  13945. {
  13946. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  13947. {
  13948. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  13949. {
  13950. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  13951. {
  13952. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  13953. {
  13954. 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")));
  13955. }
  13956. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13957. {
  13958. 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")));
  13959. }
  13960. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13961. {
  13962. 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)
  13963. {
  13964. 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"));
  13965. }
  13966. 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)
  13967. {
  13968. 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"));
  13969. }
  13970. }
  13971. }
  13972. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  13973. {
  13974. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13975. {
  13976. 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")));
  13977. }
  13978. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13979. {
  13980. 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")));
  13981. }
  13982. }
  13983. }
  13984. }
  13985. }
  13986. }
  13987. json_object_put(GetMonitoringReport);
  13988. /*
  13989. * TODO:
  13990. * 1. Response result
  13991. */
  13992. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13993. sendGetMonitoringReportConfirmation(uuid);
  13994. return result;
  13995. }
  13996. int handleGetReportRequest(char *uuid, char *payload)
  13997. {
  13998. mtrace();
  13999. int result = FAIL;
  14000. json_object *GetReport;
  14001. DEBUG_INFO("handleGetReportRequest...\n");
  14002. GetReport = json_tokener_parse(payload);
  14003. if(!is_error(GetReport))
  14004. {
  14005. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  14006. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  14007. // Required data
  14008. if(json_object_object_get(GetReport, "requestId") != NULL)
  14009. {
  14010. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  14011. }
  14012. // Optional data
  14013. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  14014. {
  14015. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  14016. }
  14017. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  14018. {
  14019. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  14020. {
  14021. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  14022. {
  14023. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  14024. {
  14025. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  14026. {
  14027. 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")));
  14028. }
  14029. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14030. {
  14031. 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")));
  14032. }
  14033. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14034. {
  14035. 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)
  14036. {
  14037. 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"));
  14038. }
  14039. 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)
  14040. {
  14041. 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"));
  14042. }
  14043. }
  14044. }
  14045. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  14046. {
  14047. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14048. {
  14049. 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")));
  14050. }
  14051. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14052. {
  14053. 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")));
  14054. }
  14055. }
  14056. }
  14057. }
  14058. }
  14059. }
  14060. json_object_put(GetReport);
  14061. /*
  14062. * TODO:
  14063. * 1. Response result
  14064. */
  14065. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14066. sendGetReportConfirmation(uuid);
  14067. return result;
  14068. }
  14069. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  14070. {
  14071. mtrace();
  14072. int result = FAIL;
  14073. int8_t gun_index = -1;
  14074. json_object *GetTransactionStatus;
  14075. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  14076. GetTransactionStatus = json_tokener_parse(payload);
  14077. if(!is_error(GetTransactionStatus))
  14078. {
  14079. /*
  14080. * TODO:
  14081. * 1. Check transaction locate which connector
  14082. */
  14083. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  14084. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  14085. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  14086. {
  14087. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  14088. }
  14089. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  14090. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  14091. }
  14092. json_object_put(GetTransactionStatus);
  14093. sendGetTransactionStatusConfirmation(uuid, gun_index);
  14094. return result;
  14095. }
  14096. int handleGetVariablesRequest(char *uuid, char *payload)
  14097. {
  14098. mtrace();
  14099. int result = FAIL;
  14100. int isUnknownComponent = TRUE;
  14101. json_object *GetVariables;
  14102. DEBUG_INFO("handleGetVariablesRequest...\n");
  14103. GetVariables = json_tokener_parse(payload);
  14104. if(!is_error(GetVariables))
  14105. {
  14106. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  14107. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  14108. // Required data
  14109. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  14110. {
  14111. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  14112. {
  14113. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  14114. {
  14115. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  14116. {
  14117. 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")));
  14118. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  14119. }
  14120. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  14121. {
  14122. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  14123. }*/
  14124. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  14125. {
  14126. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  14127. {
  14128. 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")));
  14129. }
  14130. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  14131. {
  14132. 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")));
  14133. }
  14134. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  14135. {
  14136. 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)
  14137. {
  14138. 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"));
  14139. }
  14140. 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)
  14141. {
  14142. 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"));
  14143. }
  14144. }
  14145. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  14146. }
  14147. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  14148. {
  14149. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  14150. {
  14151. 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")));
  14152. }
  14153. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  14154. {
  14155. 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")));
  14156. }
  14157. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  14158. }
  14159. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14160. {
  14161. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  14162. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  14163. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  14164. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  14165. {
  14166. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  14167. isUnknownComponent = FALSE;
  14168. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  14169. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  14170. {
  14171. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  14172. break;
  14173. }
  14174. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14175. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  14176. {
  14177. struct sysinfo s_info;
  14178. int error = sysinfo(&s_info);
  14179. if(error != 0)
  14180. {
  14181. DEBUG_WARN("System uptime get error: %d\n", error);
  14182. }
  14183. else
  14184. {
  14185. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  14186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  14187. }
  14188. }
  14189. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14190. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  14191. {
  14192. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  14193. }
  14194. else
  14195. {
  14196. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14197. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  14198. }
  14199. break;
  14200. }
  14201. else
  14202. {
  14203. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  14204. {
  14205. isUnknownComponent = FALSE;
  14206. }
  14207. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  14208. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  14209. }
  14210. }
  14211. if(isUnknownComponent == TRUE)
  14212. {
  14213. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  14214. }
  14215. }
  14216. }
  14217. }
  14218. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  14219. }
  14220. json_object_put(GetVariables);
  14221. return result;
  14222. }
  14223. int handleInstallCertificateRequest(char *uuid, char *payload)
  14224. {
  14225. mtrace();
  14226. int result = PASS;
  14227. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14228. json_object *InstallCertificate;
  14229. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14230. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14231. InstallCertificate = json_tokener_parse(payload);
  14232. if(!is_error(InstallCertificate))
  14233. {
  14234. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  14235. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  14236. // Required data
  14237. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  14238. {
  14239. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14240. }
  14241. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  14242. {
  14243. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14244. }
  14245. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificateType);
  14246. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificate);
  14247. char temp[1024];
  14248. FILE *fp = fopen(tempCert, "w");
  14249. fprintf(fp, "%s", ShmOCPP20Data->InstallCertificate.certificate);
  14250. fclose(fp);
  14251. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14252. char strExpDate[30];
  14253. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14254. fp = popen(temp, "r");
  14255. if(fp)
  14256. {
  14257. while(fgets(temp, sizeof(temp), fp) != NULL)
  14258. {
  14259. if(strstr(temp, "notAfter=") != NULL)
  14260. {
  14261. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14262. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14263. break;
  14264. }
  14265. }
  14266. }
  14267. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14268. struct tm tmExpDate;
  14269. struct timeb tbExpDate;
  14270. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14271. tbExpDate.time = mktime(&tmExpDate);
  14272. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14273. {
  14274. DEBUG_INFO("The enddate is already expired...\n");
  14275. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14276. goto End;
  14277. }
  14278. // Verify certificate with rootCA
  14279. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14280. fp = popen(temp, "r");
  14281. if(fp)
  14282. {
  14283. while(fgets(temp, sizeof(temp), fp) != NULL)
  14284. {
  14285. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14286. {
  14287. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14288. break;
  14289. }
  14290. else
  14291. {
  14292. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14293. }
  14294. }
  14295. }
  14296. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14297. {
  14298. //=====================================================
  14299. // Verify if the certificate is valid or not. (OCSP?)
  14300. //=====================================================
  14301. /*
  14302. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14303. // Get ocsp url
  14304. char ocspUrl[512];
  14305. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14306. fp = popen(temp, "r");
  14307. if(fp)
  14308. {
  14309. while(fgets(temp, sizeof(temp), fp) != NULL)
  14310. {
  14311. if(strstr(temp, "://") != NULL)
  14312. {
  14313. strcpy(ocspUrl, temp);
  14314. break;
  14315. }
  14316. }
  14317. }
  14318. // Get certificate chain for issuer
  14319. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14320. *
  14321. // Execute OCSP
  14322. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14323. fp = popen(temp, "r");
  14324. if(fp)
  14325. {
  14326. while(fgets(temp, sizeof(temp), fp) != NULL)
  14327. {
  14328. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14329. {
  14330. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14331. break;
  14332. }
  14333. }
  14334. }
  14335. system("rm -f /Storage/OCPP/tempChain.pem");
  14336. pclose(fp);
  14337. */
  14338. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14339. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14340. {
  14341. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14342. goto End;
  14343. }
  14344. else
  14345. DEBUG_INFO("OCSP verifying...PASS.\n");
  14346. }
  14347. else
  14348. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14349. }
  14350. json_object_put(InstallCertificate);
  14351. End:
  14352. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") == 0)
  14353. {
  14354. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]) == 0)
  14355. {
  14356. if(access(ROOTCA_CS,F_OK) != -1)
  14357. {
  14358. DEBUG_INFO("Existed CSMSRootCertificate is found. Replacing...\n");
  14359. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14360. rename(tempCert, ROOTCA_CS);
  14361. }
  14362. else
  14363. {
  14364. DEBUG_INFO("No existed CSMSRootCertificate Creating...\n");
  14365. rename(tempCert, ROOTCA_CS);
  14366. }
  14367. }
  14368. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]) == 0)
  14369. {
  14370. if(access(ROOTCA_MF,F_OK) != -1)
  14371. {
  14372. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14373. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14374. rename(tempCert, ROOTCA_MF);
  14375. }
  14376. else
  14377. {
  14378. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14379. rename(tempCert, ROOTCA_MF);
  14380. }
  14381. }
  14382. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]) == 0)
  14383. {
  14384. if(access(ROOTCA_V2G,F_OK) != -1)
  14385. {
  14386. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14387. rename(ROOTCA_V2G, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14388. rename(tempCert, ROOTCA_V2G);
  14389. }
  14390. else
  14391. {
  14392. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14393. rename(tempCert, ROOTCA_V2G);
  14394. }
  14395. }
  14396. ShmOCPP20Data->MsMsg.bits.InstallCertificateReq = 1;
  14397. }
  14398. sendInstallCertificateConfirmation(uuid);
  14399. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14400. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14401. {
  14402. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14403. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  14404. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14405. }
  14406. return result;
  14407. }
  14408. int handlePublishFirmwareRequest(char *uuid, char *payload)
  14409. {
  14410. mtrace();
  14411. int result = FAIL;
  14412. json_object *PublishFirmware;
  14413. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  14414. PublishFirmware = json_tokener_parse(payload);
  14415. if(!is_error(PublishFirmware))
  14416. {
  14417. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  14418. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  14419. // Required data
  14420. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  14421. {
  14422. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  14423. }
  14424. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  14425. {
  14426. sprintf((char*)ShmOCPP20Data->PublishFirmware.checksum, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  14427. }
  14428. // Optional data
  14429. if(json_object_object_get(PublishFirmware, "location") != NULL)
  14430. {
  14431. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  14432. }
  14433. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  14434. {
  14435. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  14436. }
  14437. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  14438. {
  14439. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  14440. }
  14441. }
  14442. json_object_put(PublishFirmware);
  14443. /*
  14444. * TODO:
  14445. * 1. Publish firmware preocess and response
  14446. */
  14447. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  14448. sendPublishFirmwareConfirmation(uuid);
  14449. return result;
  14450. }
  14451. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  14452. {
  14453. mtrace();
  14454. int result = FAIL;
  14455. int8_t evseId = -1;
  14456. uint8_t tempIndex;
  14457. uint8_t isOverConnectorMax = FALSE;
  14458. uint8_t isPeriodOverMax = FALSE;
  14459. uint8_t isTxProfile = TRUE;
  14460. uint8_t isAllowStart = TRUE;
  14461. uint8_t filename[128]={0};
  14462. char cmdBuf[128];
  14463. FILE *filePtr;
  14464. json_object *RemoteStartTransaction;
  14465. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  14466. RemoteStartTransaction = json_tokener_parse(payload);
  14467. if(!is_error(RemoteStartTransaction))
  14468. {
  14469. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  14470. {
  14471. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  14472. {
  14473. evseId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  14474. }
  14475. else
  14476. {
  14477. isOverConnectorMax = TRUE;
  14478. DEBUG_WARN("Evse id shall not equal 0 and should be less than gunTotalNumber.\n");
  14479. }
  14480. }
  14481. else
  14482. {
  14483. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  14484. {
  14485. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  14486. {
  14487. evseId = (idx+1);
  14488. DEBUG_INFO("Remote start without evseId but detect connector of evse-%02d connected ready to start.\n", evseId);
  14489. break;
  14490. }
  14491. }
  14492. }
  14493. if(isOverConnectorMax == FALSE)
  14494. {
  14495. if(evseId > 0)
  14496. {
  14497. DEBUG_INFO("Requested evseId id: %d\n", evseId);
  14498. memset(&ShmOCPP20Data->RequestStartTransaction[evseId-1], 0, sizeof(struct RequestStartTransaction_20));
  14499. memcpy(&ShmOCPP20Data->RequestStartTransaction[evseId-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[evseId-1].guid));
  14500. // Required data
  14501. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14502. {
  14503. ShmOCPP20Data->RequestStartTransaction[evseId-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14504. }
  14505. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14506. {
  14507. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14508. {
  14509. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14510. }
  14511. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14512. {
  14513. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14514. }
  14515. }
  14516. // Optional data
  14517. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14518. {
  14519. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14520. {
  14521. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14522. }
  14523. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14524. {
  14525. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14526. }
  14527. }
  14528. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14529. {
  14530. // Check periods is over max configuration
  14531. 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))
  14532. {
  14533. isPeriodOverMax = TRUE;
  14534. }
  14535. // Check profile purpose is TxProfile
  14536. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14537. {
  14538. ShmOCPP20Data->RequestStartTransaction[evseId-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14539. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  14540. }
  14541. else
  14542. {
  14543. isTxProfile = FALSE;
  14544. }
  14545. }
  14546. //check Transaction active
  14547. if(gunType[evseId-1] == GUN_TYPE_CHAdeMO)
  14548. {
  14549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14550. {
  14551. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14552. }
  14553. else
  14554. {
  14555. tempIndex = (evseId-1);
  14556. }
  14557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14558. {
  14559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  14560. {
  14561. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14562. {
  14563. //Reserved
  14564. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  14565. }
  14566. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14567. {
  14568. //Reserved
  14569. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  14570. isAllowStart = FALSE;
  14571. }
  14572. else
  14573. {
  14574. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14575. {
  14576. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  14577. isAllowStart = FALSE;
  14578. }
  14579. }//END FOR ELSE
  14580. }
  14581. }// END FOR CHAdeMO_QUANTITY
  14582. }
  14583. else if(gunType[evseId-1] == GUN_TYPE_CCS)
  14584. {
  14585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14586. {
  14587. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14588. }
  14589. else
  14590. {
  14591. tempIndex = (evseId-1);
  14592. }
  14593. for (int index = 0; index < CCS_QUANTITY; index++)
  14594. {
  14595. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14596. {
  14597. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14598. {
  14599. //Reserved
  14600. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  14601. }
  14602. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14603. {
  14604. //Reserved
  14605. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  14606. isAllowStart = FALSE;
  14607. }
  14608. else
  14609. {
  14610. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14611. {
  14612. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  14613. isAllowStart = FALSE;
  14614. }
  14615. }// END FOR ELSE
  14616. }
  14617. }// END FOR CCS_QUANTITY
  14618. }
  14619. else if(gunType[evseId-1] == GUN_TYPE_GBT)
  14620. {
  14621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14622. {
  14623. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14624. }
  14625. else
  14626. {
  14627. tempIndex = (evseId-1);
  14628. }
  14629. for (int index = 0; index < GB_QUANTITY; index++)
  14630. {
  14631. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  14632. {
  14633. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14634. {
  14635. //Reserved
  14636. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  14637. }
  14638. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14639. {
  14640. //Reserved
  14641. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  14642. isAllowStart = FALSE;
  14643. }
  14644. else
  14645. {
  14646. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14647. {
  14648. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  14649. isAllowStart = FALSE;
  14650. }
  14651. }// END FOR ELSE
  14652. }
  14653. } // END FOR GB_QUANTITY
  14654. }
  14655. else if(gunType[evseId-1] == GUN_TYPE_DO)
  14656. {
  14657. tempIndex = (evseId-1);
  14658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14659. {
  14660. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  14661. {
  14662. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14663. {
  14664. //Reserved
  14665. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  14666. }
  14667. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14668. {
  14669. //Reserved
  14670. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  14671. isAllowStart = FALSE;
  14672. }
  14673. else
  14674. {
  14675. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14676. {
  14677. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  14678. isAllowStart = FALSE;
  14679. }
  14680. }// END FOR ELSE
  14681. }
  14682. } // END FOR GB_QUANTITY
  14683. }
  14684. else
  14685. {
  14686. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14687. {
  14688. tempIndex = 2;
  14689. }
  14690. else
  14691. {
  14692. tempIndex = (evseId-1);
  14693. }
  14694. for (int index = 0; index < AC_QUANTITY; index++)
  14695. {
  14696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  14697. {
  14698. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14699. {
  14700. //Reserved
  14701. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  14702. }
  14703. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14704. {
  14705. //Reserved
  14706. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  14707. isAllowStart = FALSE;
  14708. }
  14709. else
  14710. {
  14711. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14712. {
  14713. DEBUG_WARN("AC connector not allow start cause busy.\n");
  14714. isAllowStart = FALSE;
  14715. }
  14716. }//END FOR ELSE
  14717. }
  14718. }// END FOR AC_QUANTITY
  14719. }
  14720. }
  14721. else
  14722. {
  14723. DEBUG_INFO("Connector id does not specific.\n");
  14724. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14725. {
  14726. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  14727. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  14728. // Required data
  14729. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14730. {
  14731. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14732. }
  14733. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14734. {
  14735. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14736. {
  14737. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14738. }
  14739. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14740. {
  14741. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14742. }
  14743. }
  14744. // Optional data
  14745. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14746. {
  14747. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14748. {
  14749. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14750. }
  14751. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14752. {
  14753. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14754. }
  14755. }
  14756. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14757. {
  14758. // Check periods is over max configuration
  14759. 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))
  14760. {
  14761. isPeriodOverMax = TRUE;
  14762. }
  14763. // Check profile purpose is TxProfile
  14764. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14765. {
  14766. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14767. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14768. }
  14769. else
  14770. {
  14771. isTxProfile = FALSE;
  14772. }
  14773. }
  14774. }
  14775. }
  14776. }
  14777. // Profile replace or add info
  14778. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  14779. {
  14780. if(evseId != -1)
  14781. {
  14782. if(strlen((char*)filename) > 0)
  14783. {
  14784. // Save profile to file
  14785. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  14786. system(cmdBuf);
  14787. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", evseId);
  14788. filePtr = fopen((char*)filename, "w");
  14789. fprintf(filePtr, "{\"evseId\":%d,\"chargingProfile\":%s}\n", evseId, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14790. fclose(filePtr);
  14791. }
  14792. ShmOCPP20Data->CsMsg.bits[evseId-1].RequestStartTransactionReq = ON;
  14793. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14794. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_transactionId);
  14795. result = PASS;
  14796. }
  14797. else
  14798. {
  14799. uint8_t isHasIdleConnector = FALSE;
  14800. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14801. {
  14802. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  14803. {
  14804. isHasIdleConnector = TRUE;
  14805. break;
  14806. }
  14807. }
  14808. if((isHasIdleConnector == TRUE) && !ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14809. {
  14810. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  14811. if(strlen((char*)filename) > 0)
  14812. {
  14813. // Save profile to file
  14814. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14815. system(cmdBuf);
  14816. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  14817. filePtr = fopen((char*)filename, "w");
  14818. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14819. fclose(filePtr);
  14820. }
  14821. refreshStartTimer(&clientTime.RemoteStartWait);
  14822. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  14823. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14824. {
  14825. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14826. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  14827. }
  14828. result = PASS;
  14829. }
  14830. else
  14831. {
  14832. DEBUG_INFO("There is not any connector is idle.\n");
  14833. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14834. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14835. }
  14836. }
  14837. }
  14838. else
  14839. {
  14840. if(isOverConnectorMax != FALSE)
  14841. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  14842. if(isPeriodOverMax)
  14843. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14844. if(!isTxProfile)
  14845. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  14846. if(!isAllowStart)
  14847. DEBUG_WARN("Target connector does not allow start.\n");
  14848. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((evseId-1)<0?0:(evseId-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  14849. }
  14850. }
  14851. json_object_put(RemoteStartTransaction);
  14852. sendRemoteStartTransactionConfirmation(uuid, ((evseId-1)<0?0:(evseId-1)));
  14853. return result;
  14854. }
  14855. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  14856. {
  14857. mtrace();
  14858. int result = FAIL;
  14859. int match = FALSE;
  14860. int GunNO = 0;
  14861. int tempIndex = 0;
  14862. char transactionIdStr[37];
  14863. int transactionIdIsNULL= TRUE;
  14864. json_object *RemoteStopTransaction;
  14865. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  14866. if(server_pending == TRUE)
  14867. {
  14868. return 0;
  14869. }
  14870. RemoteStopTransaction = json_tokener_parse(payload);
  14871. if(!is_error(RemoteStopTransaction))
  14872. {
  14873. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  14874. {
  14875. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  14876. transactionIdIsNULL = FALSE;
  14877. }
  14878. }
  14879. json_object_put(RemoteStopTransaction);
  14880. if(transactionIdIsNULL == FALSE)
  14881. {
  14882. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14883. {
  14884. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  14885. {
  14886. //check Transaction active
  14887. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14888. {
  14889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14890. {
  14891. tempIndex = ((gun_index==2) ? 1: 0);
  14892. }
  14893. else
  14894. {
  14895. tempIndex = gun_index;
  14896. }
  14897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14898. {
  14899. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14900. {
  14901. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14902. {
  14903. match = TRUE;
  14904. GunNO = gun_index;
  14905. }
  14906. }
  14907. }// END FOR CHAdeMO_QUANTITY
  14908. }
  14909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14910. {
  14911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14912. {
  14913. tempIndex = ((gun_index==2) ? 1: 0);
  14914. }
  14915. else
  14916. {
  14917. tempIndex = gun_index;
  14918. }
  14919. for (int index = 0; index < CCS_QUANTITY; index++)
  14920. {
  14921. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14922. {
  14923. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14924. {
  14925. match = TRUE;
  14926. GunNO = gun_index;
  14927. }
  14928. }
  14929. }// END FOR CCS_QUANTITY
  14930. }
  14931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14932. {
  14933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14934. {
  14935. tempIndex = ((gun_index==2) ? 1: 0);
  14936. }
  14937. else
  14938. {
  14939. tempIndex = gun_index;
  14940. }
  14941. for (int index = 0; index < GB_QUANTITY; index++)
  14942. {
  14943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14944. {
  14945. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14946. {
  14947. match = TRUE;
  14948. GunNO = gun_index;
  14949. }
  14950. }
  14951. }// END FOR GB_QUANTITY
  14952. }
  14953. else if(gunType[gun_index] == GUN_TYPE_DO)
  14954. {
  14955. tempIndex = gun_index;
  14956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14957. {
  14958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14959. {
  14960. 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
  14961. {
  14962. match = TRUE;
  14963. GunNO = gun_index;
  14964. }
  14965. }
  14966. }// END FOR GB_QUANTITY
  14967. }
  14968. else
  14969. {
  14970. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14971. {
  14972. tempIndex = 2;
  14973. }
  14974. else
  14975. {
  14976. tempIndex = gun_index;
  14977. }
  14978. for (int index = 0; index < AC_QUANTITY; index++)
  14979. {
  14980. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14981. {
  14982. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14983. {
  14984. match = TRUE;
  14985. GunNO = gun_index;
  14986. }
  14987. }
  14988. }// END FOR CHAdeMO_QUANTITY
  14989. } // END FOR AC ELSE
  14990. }// CHECK IF ResponseTransactionId == transactionIdInt
  14991. }//END FOR
  14992. if( match == TRUE)
  14993. {
  14994. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  14995. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14996. }
  14997. else
  14998. {
  14999. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15000. }
  15001. }
  15002. else
  15003. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15004. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  15005. return result;
  15006. }
  15007. int handleReserveNowRequest(char *uuid, char *payload)
  15008. {
  15009. mtrace();
  15010. int result = FAIL;
  15011. int evseIdInt=0, reservationIdInt=0;
  15012. int tempIndex = 0;
  15013. json_object *ReserveNow;
  15014. DEBUG_INFO("handleReserveNowRequest ...\n");
  15015. ReserveNow = json_tokener_parse(payload);
  15016. if(!is_error(ReserveNow))
  15017. {
  15018. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  15019. {
  15020. evseIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15021. evseIdInt = (evseIdInt==0)?1:evseIdInt;
  15022. memset(&ShmOCPP20Data->ReserveNow[evseIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  15023. ShmOCPP20Data->ReserveNow[evseIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15024. }
  15025. // Required data
  15026. if(json_object_object_get(ReserveNow, "id") != NULL)
  15027. ShmOCPP20Data->ReserveNow[evseIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  15028. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  15029. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  15030. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  15031. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  15032. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  15033. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  15034. // Optional data
  15035. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  15036. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  15037. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  15038. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  15039. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  15040. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  15041. result = PASS;
  15042. }
  15043. json_object_put(ReserveNow);
  15044. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15045. if((evseIdInt > 0) && ((evseIdInt -1) <= gunTotalNumber))
  15046. {
  15047. //check Transaction active
  15048. if(gunType[evseIdInt -1] == GUN_TYPE_CHAdeMO)
  15049. {
  15050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15051. {
  15052. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15053. }
  15054. else
  15055. {
  15056. tempIndex = evseIdInt -1;
  15057. }
  15058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15059. {
  15060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15061. {
  15062. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15063. {
  15064. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15065. {
  15066. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15067. {
  15068. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  15069. {
  15070. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15071. }
  15072. else
  15073. {
  15074. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15075. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15076. }
  15077. }
  15078. 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'))
  15079. {
  15080. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15081. }
  15082. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15083. {
  15084. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15085. }
  15086. else
  15087. {
  15088. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15089. }
  15090. }
  15091. 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
  15092. {
  15093. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15094. }
  15095. }
  15096. else
  15097. {
  15098. //replace reservation
  15099. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15100. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15101. }
  15102. }
  15103. } // END FOR CHAdeMO_QUANTITY
  15104. }
  15105. else if(gunType[evseIdInt -1] == GUN_TYPE_CCS)
  15106. {
  15107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15108. {
  15109. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15110. }
  15111. else
  15112. {
  15113. tempIndex = evseIdInt -1;
  15114. }
  15115. for (int index = 0; index < CCS_QUANTITY; index++)
  15116. {
  15117. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15118. {
  15119. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15120. {
  15121. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15122. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15123. {
  15124. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15125. {
  15126. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  15127. {
  15128. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15129. }
  15130. else
  15131. {
  15132. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15133. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15134. }
  15135. }
  15136. 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'))
  15137. {
  15138. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15139. }
  15140. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  15141. {
  15142. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15143. }
  15144. else
  15145. {
  15146. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15147. }
  15148. }
  15149. 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
  15150. {
  15151. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15152. }
  15153. }
  15154. else
  15155. {
  15156. //replace reservation
  15157. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15158. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15159. }
  15160. }
  15161. } // END FOR CCS_QUANTITY
  15162. }
  15163. else if(gunType[evseIdInt -1] == GUN_TYPE_GBT)
  15164. {
  15165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15166. {
  15167. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15168. }
  15169. else
  15170. {
  15171. tempIndex = evseIdInt -1;
  15172. }
  15173. for (int index = 0; index < GB_QUANTITY; index++)
  15174. {
  15175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15176. {
  15177. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15178. {
  15179. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15180. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15181. {
  15182. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15183. {
  15184. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  15185. {
  15186. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15187. }
  15188. else
  15189. {
  15190. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15191. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15192. }
  15193. }
  15194. 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'))
  15195. {
  15196. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15197. }
  15198. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15199. {
  15200. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15201. }
  15202. else
  15203. {
  15204. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15205. }
  15206. }
  15207. 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
  15208. {
  15209. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15210. }
  15211. }
  15212. else
  15213. {
  15214. //replace reservation
  15215. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15216. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15217. }
  15218. }
  15219. }// END FOR GB_QUANTITY
  15220. }
  15221. else if(gunType[evseIdInt -1] == GUN_TYPE_DO)
  15222. {
  15223. tempIndex = evseIdInt -1;
  15224. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15225. {
  15226. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15227. {
  15228. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  15229. {
  15230. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15231. 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
  15232. {
  15233. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15234. {
  15235. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  15236. {
  15237. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15238. }
  15239. else
  15240. {
  15241. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15242. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15243. }
  15244. }
  15245. 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'))
  15246. {
  15247. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15248. }
  15249. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15250. {
  15251. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15252. }
  15253. else
  15254. {
  15255. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15256. }
  15257. }
  15258. 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
  15259. {
  15260. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15261. }
  15262. }
  15263. else
  15264. {
  15265. //replace reservation
  15266. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15267. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15268. }
  15269. }
  15270. }// END FOR DO_QUANTITY
  15271. }
  15272. else
  15273. {
  15274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15275. {
  15276. tempIndex = 2;
  15277. }
  15278. else
  15279. {
  15280. tempIndex = (evseIdInt -1);
  15281. }
  15282. for (int index = 0; index < AC_QUANTITY; index++)
  15283. {
  15284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15285. {
  15286. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15287. {
  15288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15289. {
  15290. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15291. {
  15292. 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))
  15293. {
  15294. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15295. }
  15296. else
  15297. {
  15298. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15299. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15300. }
  15301. }
  15302. 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'))
  15303. {
  15304. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15305. }
  15306. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15307. {
  15308. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15309. }
  15310. else
  15311. {
  15312. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15313. }
  15314. }
  15315. 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
  15316. {
  15317. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15318. }
  15319. }
  15320. else
  15321. {
  15322. //replace reservation
  15323. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15324. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15325. }
  15326. }
  15327. } // END FOR AC_QUANTITY
  15328. }
  15329. }
  15330. else if(evseIdInt == 0)
  15331. {
  15332. //check Transaction active
  15333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15334. {
  15335. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15336. {
  15337. 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'))
  15338. {
  15339. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15340. goto end;
  15341. }
  15342. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15343. {
  15344. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15345. goto end;
  15346. }
  15347. 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
  15348. {
  15349. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15350. goto end;
  15351. }
  15352. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15353. {
  15354. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15355. goto end;
  15356. }
  15357. }
  15358. }// END FOR CHAdeMO_QUANTITY
  15359. for (int index = 0; index < CCS_QUANTITY; index++)
  15360. {
  15361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15362. {
  15363. 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'))
  15364. {
  15365. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15366. goto end;
  15367. }
  15368. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  15369. {
  15370. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15371. goto end;
  15372. }
  15373. 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
  15374. {
  15375. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15376. goto end;
  15377. }
  15378. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15379. {
  15380. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15381. goto end;
  15382. }
  15383. }
  15384. } // END FOR CCS_QUANTITY
  15385. for (int index = 0; index < GB_QUANTITY; index++)
  15386. {
  15387. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15388. {
  15389. 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'))
  15390. {
  15391. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15392. goto end;
  15393. }
  15394. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15395. {
  15396. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15397. goto end;
  15398. }
  15399. 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
  15400. {
  15401. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15402. goto end;
  15403. }
  15404. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15405. {
  15406. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15407. goto end;
  15408. }
  15409. }
  15410. } // END FOR GB_QUANTITY
  15411. for (int index = 0; index < AC_QUANTITY; index++)
  15412. {
  15413. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15414. {
  15415. 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'))
  15416. {
  15417. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15418. goto end;
  15419. }
  15420. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15421. {
  15422. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15423. goto end;
  15424. }
  15425. 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
  15426. {
  15427. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15428. goto end;
  15429. }
  15430. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15431. {
  15432. 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))
  15433. {
  15434. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15435. goto end;
  15436. }
  15437. }
  15438. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15439. {
  15440. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15441. goto end;
  15442. }
  15443. }
  15444. }// END FOR AC_QUANTITY
  15445. //The connectorId is 0
  15446. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  15447. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15448. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  15449. result = TRUE;
  15450. return result;
  15451. }
  15452. else
  15453. {
  15454. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15455. }
  15456. if(strcmp((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  15457. {
  15458. strcpy((char *)ShmOCPP20Data->ReserveNow[evseIdInt-1].guid, uuid);
  15459. result = TRUE;
  15460. return result;
  15461. }
  15462. end:
  15463. sendReserveNowConfirmation(uuid, (evseIdInt==0?evseIdInt:evseIdInt-1));
  15464. return result;
  15465. }
  15466. int handleResetRequest(char *uuid, char *payload)
  15467. {
  15468. mtrace();
  15469. int result = FAIL;
  15470. json_object *Reset = json_object_new_object();
  15471. DEBUG_INFO("handleResetRequest...\n");
  15472. Reset = json_tokener_parse(payload);
  15473. ShmOCPP20Data->Reset.evseId = 0;
  15474. if(!is_error(Reset))
  15475. {
  15476. // Required data
  15477. if(json_object_object_get(Reset, "type") != NULL)
  15478. {
  15479. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  15480. }
  15481. if(json_object_object_get(Reset, "evseId") != NULL)
  15482. {
  15483. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  15484. }
  15485. }
  15486. json_object_put(Reset);
  15487. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  15488. {
  15489. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  15490. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  15491. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  15492. result = PASS;
  15493. }
  15494. else
  15495. {
  15496. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  15497. }
  15498. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  15499. sendResetConfirmation(uuid);
  15500. return result;
  15501. }
  15502. int handleSendLocalListRequest(char *uuid, char *payload)
  15503. {
  15504. mtrace();
  15505. int result = FAIL;
  15506. int checkState_Faulted = FALSE;
  15507. json_object *SendLocalList;
  15508. DEBUG_INFO("handleSendLocalListRequest...\n");
  15509. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  15510. {
  15511. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15512. goto end;
  15513. }
  15514. SendLocalList = json_tokener_parse(payload);
  15515. if(!is_error(SendLocalList))
  15516. {
  15517. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  15518. // Required data
  15519. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  15520. {
  15521. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  15522. }
  15523. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  15524. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  15525. // Optional data
  15526. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  15527. {
  15528. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  15529. {
  15530. // Required data
  15531. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  15532. {
  15533. 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")));
  15534. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.type, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken"), "type"))));
  15535. }
  15536. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  15537. {
  15538. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.status, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status"))));
  15539. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  15540. 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")));
  15541. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  15542. 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"));
  15543. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  15544. {
  15545. 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")));
  15546. 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")));
  15547. }
  15548. }
  15549. }
  15550. }
  15551. }
  15552. json_object_put(SendLocalList);
  15553. //check Charge Point state
  15554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15555. {
  15556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15557. {
  15558. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15559. }
  15560. }
  15561. for (int index = 0; index < CCS_QUANTITY; index++)
  15562. {
  15563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15564. {
  15565. checkState_Faulted = TRUE; //OCPP Status
  15566. }
  15567. }
  15568. for (int index = 0; index < GB_QUANTITY; index++)
  15569. {
  15570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15571. {
  15572. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15573. }
  15574. }
  15575. for (int index = 0; index < AC_QUANTITY; index++)
  15576. {
  15577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15578. {
  15579. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15580. }
  15581. }
  15582. if(checkState_Faulted == TRUE)
  15583. {
  15584. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15585. goto end;
  15586. }
  15587. // Check update type
  15588. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  15589. {
  15590. //Local list full update
  15591. DEBUG_INFO("Local list full update.\n");
  15592. DB_getListVerion();
  15593. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15594. {
  15595. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15596. goto end;
  15597. }*/
  15598. DB_cleanLocalList();
  15599. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15600. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15601. }
  15602. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  15603. {
  15604. //Local list different update
  15605. DEBUG_INFO("Local list different update.\n");
  15606. DB_getListVerion();
  15607. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15608. {
  15609. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  15610. goto end;
  15611. }
  15612. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15613. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15614. }
  15615. else
  15616. {
  15617. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15618. goto end;
  15619. }
  15620. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  15621. end:
  15622. sendSendLocalListConfirmation(uuid);
  15623. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15624. return result;
  15625. }
  15626. int handleSetChargingProfileRequest(char *uuid, char *payload)
  15627. {
  15628. mtrace();
  15629. int result = FAIL;
  15630. struct SetChargingProfile_20 SetProfileReq = {0};
  15631. uint8_t isLostEvseId = FALSE;
  15632. uint8_t isPeriodOverMax = FALSE;
  15633. uint8_t isStackOverMax = FALSE;
  15634. uint8_t isProfileOverMax = FALSE;
  15635. uint8_t isEvseMismatch = FALSE;
  15636. uint8_t isTransactiodIdMismatch = FALSE;
  15637. uint8_t isInvalidLimit = FALSE;
  15638. uint8_t isWrongFormat = FALSE;
  15639. uint8_t replaceableProfileCnt = 0;
  15640. uint8_t existProfileQuantity = 0;
  15641. uint8_t filename[128]={0};
  15642. uint8_t dataLine[4096]={0};
  15643. FILE *filePtr;
  15644. json_object *SetChargingProfile;
  15645. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  15646. SetChargingProfile = json_tokener_parse(payload);
  15647. if(!is_error(SetChargingProfile))
  15648. {
  15649. // Required data
  15650. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  15651. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  15652. else
  15653. isLostEvseId = TRUE;
  15654. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  15655. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  15656. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  15657. {
  15658. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15659. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15660. {
  15661. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  15662. }
  15663. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  15664. {
  15665. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15666. }
  15667. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  15668. {
  15669. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  15670. }
  15671. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  15672. {
  15673. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  15674. }
  15675. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  15676. {
  15677. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  15678. }
  15679. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  15680. {
  15681. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  15682. }
  15683. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  15684. {
  15685. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  15686. }
  15687. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  15688. {
  15689. int chargingScheduleCount = 0;
  15690. int chargingSchedulePeriodCount = 0;
  15691. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  15692. {
  15693. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  15694. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  15695. {
  15696. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  15697. {
  15698. 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")));
  15699. }
  15700. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  15701. {
  15702. 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"));
  15703. }
  15704. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  15705. {
  15706. 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"));
  15707. }
  15708. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  15709. {
  15710. 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")));
  15711. }
  15712. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  15713. {
  15714. 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"));
  15715. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  15716. {
  15717. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  15718. {
  15719. 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)
  15720. {
  15721. 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"));
  15722. }
  15723. 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)
  15724. {
  15725. 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"));
  15726. }
  15727. 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)
  15728. {
  15729. 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"));
  15730. }
  15731. 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)
  15732. {
  15733. 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"));
  15734. }
  15735. // Check invalid limit
  15736. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  15737. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  15738. {
  15739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  15740. {
  15741. 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)))) ||
  15742. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  15743. {
  15744. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  15745. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15746. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15747. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15748. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  15749. isInvalidLimit = TRUE;
  15750. }
  15751. }
  15752. else
  15753. {
  15754. 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) ||
  15755. (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)))
  15756. {
  15757. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  15758. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15759. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15760. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15761. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  15762. isInvalidLimit = TRUE;
  15763. }
  15764. }
  15765. }
  15766. }
  15767. }
  15768. else
  15769. {
  15770. isPeriodOverMax = TRUE;
  15771. }
  15772. }
  15773. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  15774. {
  15775. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "id") != NULL)
  15776. {
  15777. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "id"));
  15778. }
  15779. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffDescription") != NULL)
  15780. {
  15781. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffDescription, json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffDescription")));
  15782. }
  15783. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "numEPriceLevels") != NULL)
  15784. {
  15785. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.numEPriceLevels = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "numEPriceLevels"));
  15786. }
  15787. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry") != NULL)
  15788. {
  15789. int cntEntry = json_object_array_length(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"));
  15790. if(cntEntry<=1024)
  15791. {
  15792. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  15793. {
  15794. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel") != NULL)
  15795. {
  15796. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].ePriceLevel = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel"));
  15797. }
  15798. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval") != NULL)
  15799. {
  15800. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "start") != NULL)
  15801. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].relativeTimeInterval.start = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "start"));
  15802. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "duration") != NULL)
  15803. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].relativeTimeInterval.duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "duration"));
  15804. }
  15805. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost") != NULL)
  15806. {
  15807. uint8_t cntConCost = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"));
  15808. if(cntConCost<=3)
  15809. {
  15810. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  15811. {
  15812. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "startValue") != NULL)
  15813. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].startValue = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"));
  15814. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost") != NULL)
  15815. {
  15816. uint8_t cntCost = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"));
  15817. if(cntConCost<=3)
  15818. {
  15819. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  15820. {
  15821. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "costKind") != NULL)
  15822. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].costKind, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "costKind")));
  15823. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amount") != NULL)
  15824. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].amount = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amount"));
  15825. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amountMultiplier") != NULL)
  15826. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].amountMultiplier = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amountMultiplier"));
  15827. }
  15828. }
  15829. }
  15830. }
  15831. }
  15832. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].ePriceLevel = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel"));
  15833. }
  15834. }
  15835. }
  15836. }
  15837. }
  15838. }
  15839. }
  15840. else
  15841. {
  15842. isWrongFormat = TRUE;
  15843. }
  15844. }
  15845. // Check periods is over max configuration
  15846. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  15847. {
  15848. if(SetProfileReq.evseId == 0)
  15849. {
  15850. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  15851. filePtr = fopen((char*)filename, "r");
  15852. if (!filePtr)
  15853. {
  15854. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  15855. filePtr = fopen((char*)filename, "w+");
  15856. }
  15857. else
  15858. {
  15859. //Check Charging Profile Count
  15860. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15861. char *line = NULL;
  15862. size_t len = 0;
  15863. while(getline(&line, &len, filePtr) != -1)
  15864. {
  15865. json_object *obj = NULL;
  15866. obj = json_tokener_parse(line);
  15867. if(is_error(obj))
  15868. {
  15869. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15870. }
  15871. else
  15872. {
  15873. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15874. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15875. {
  15876. existProfileQuantity += 1;
  15877. }
  15878. else
  15879. replaceableProfileCnt += 1;
  15880. }
  15881. //DEBUG_INFO("word=%s\n",word);
  15882. /*if(strstr((char*)dataLine, "id")!= NULL)
  15883. {
  15884. existProfileQuantity += 1;
  15885. }*/
  15886. }
  15887. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15888. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15889. {
  15890. isStackOverMax = TRUE;
  15891. }
  15892. }
  15893. fclose(filePtr);
  15894. }
  15895. else
  15896. isEvseMismatch = TRUE;
  15897. }
  15898. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  15899. {
  15900. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  15901. isEvseMismatch = TRUE;
  15902. if(!isEvseMismatch)
  15903. {
  15904. if(SetProfileReq.evseId == 0)
  15905. {
  15906. int tmpExistProfileQuantity;
  15907. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  15908. {
  15909. tmpExistProfileQuantity = 0;
  15910. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15911. filePtr = fopen((char*)filename, "r");
  15912. if (!filePtr)
  15913. {
  15914. DEBUG_INFO("%s not exist, create it.\n", filename);
  15915. filePtr = fopen((char*)filename, "w+");
  15916. }
  15917. else
  15918. {
  15919. //Check Charging Profile Count
  15920. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15921. char *line = NULL;
  15922. size_t len = 0;
  15923. while(getline(&line, &len, filePtr) != -1)
  15924. {
  15925. json_object *obj = NULL;
  15926. obj = json_tokener_parse(line);
  15927. if(is_error(obj))
  15928. {
  15929. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15930. }
  15931. else
  15932. {
  15933. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15934. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15935. {
  15936. tmpExistProfileQuantity += 1;
  15937. }
  15938. else
  15939. replaceableProfileCnt += 1;
  15940. }
  15941. //DEBUG_INFO("word=%s\n",word);
  15942. /*if(strstr((char*)dataLine, "id")!= NULL)
  15943. {
  15944. tmpExistProfileQuantity += 1;
  15945. }*/
  15946. }
  15947. }
  15948. fclose(filePtr);
  15949. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15950. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15951. {
  15952. isStackOverMax = TRUE;
  15953. }
  15954. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  15955. }
  15956. }
  15957. else
  15958. {
  15959. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15960. filePtr = fopen((char*)filename, "r");
  15961. if (!filePtr)
  15962. {
  15963. DEBUG_INFO("%s not exist, create it.\n", filename);
  15964. filePtr = fopen((char*)filename, "w+");
  15965. }
  15966. else
  15967. {
  15968. //Check Charging Profile Count
  15969. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15970. char *line = NULL;
  15971. size_t len = 0;
  15972. while(getline(&line, &len, filePtr) != -1)
  15973. {
  15974. json_object *obj = NULL;
  15975. obj = json_tokener_parse(line);
  15976. if(is_error(obj))
  15977. {
  15978. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  15979. }
  15980. else
  15981. {
  15982. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15983. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15984. {
  15985. existProfileQuantity += 1;
  15986. }
  15987. else
  15988. replaceableProfileCnt += 1;
  15989. }
  15990. //DEBUG_INFO("word=%s\n",word);
  15991. /*if(strstr((char*)dataLine, "id")!= NULL)
  15992. {
  15993. existProfileQuantity += 1;
  15994. }*/
  15995. }
  15996. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15997. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15998. {
  15999. isStackOverMax = TRUE;
  16000. }
  16001. }
  16002. fclose(filePtr);
  16003. }
  16004. }
  16005. }
  16006. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  16007. {
  16008. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  16009. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16010. else
  16011. isEvseMismatch = TRUE;
  16012. if(!isEvseMismatch)
  16013. {
  16014. filePtr = fopen((char*)filename, "r");
  16015. if (!filePtr)
  16016. {
  16017. DEBUG_INFO("%s not exist, create it.\n", filename);
  16018. filePtr = fopen((char*)filename, "w+");
  16019. }
  16020. else
  16021. {
  16022. //Check Charging Profile Count
  16023. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16024. char *line = NULL;
  16025. size_t len = 0;
  16026. while(getline(&line, &len, filePtr) != -1)
  16027. {
  16028. json_object *obj = NULL;
  16029. obj = json_tokener_parse(line);
  16030. if(is_error(obj))
  16031. {
  16032. DEBUG_ERROR("Parse TxProfile from file error.\n");
  16033. }
  16034. else
  16035. {
  16036. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16037. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16038. {
  16039. existProfileQuantity += 1;
  16040. }
  16041. else
  16042. replaceableProfileCnt += 1;
  16043. }
  16044. //DEBUG_INFO("word=%s\n",word);
  16045. /*if(strstr((char*)dataLine, "id")!= NULL)
  16046. {
  16047. existProfileQuantity += 1;
  16048. }*/
  16049. }
  16050. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16051. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16052. {
  16053. isStackOverMax = TRUE;
  16054. }
  16055. }
  16056. fclose(filePtr);
  16057. if(strcmp((char*)SetProfileReq.chargingProfile.transactionId, (char*)ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId) != 0)
  16058. isTransactiodIdMismatch = TRUE;
  16059. }
  16060. }
  16061. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  16062. {
  16063. /*
  16064. * TODO:
  16065. *
  16066. */
  16067. }
  16068. else
  16069. {}
  16070. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  16071. {
  16072. FILE *fp;
  16073. char dataLine[4096]={0};
  16074. char fnametemp[128]={0};
  16075. int tmpProfileQuantity;
  16076. //Check ChargePointMaxProfile.json exit
  16077. existProfileQuantity = 0;
  16078. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  16079. {
  16080. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  16081. //Check Charging Profile Count
  16082. tmpProfileQuantity = 0;
  16083. while(fscanf(fp, "%s", dataLine) != EOF)
  16084. {
  16085. if(strstr(dataLine, "id")!= NULL)
  16086. {
  16087. existProfileQuantity += 1;
  16088. tmpProfileQuantity += 1;
  16089. }
  16090. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16091. }
  16092. fclose(fp);
  16093. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  16094. }
  16095. //Check TxDefaultProfile_%d.json
  16096. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16097. {
  16098. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16099. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16100. if((access(fnametemp,F_OK))!=-1)
  16101. {
  16102. fp = fopen(fnametemp, "r");
  16103. //Check Charging Profile Count
  16104. tmpProfileQuantity = 0;
  16105. while(fscanf(fp, "%s", dataLine) != EOF)
  16106. {
  16107. //DEBUG_INFO("word=%s\n",word);
  16108. if(strstr(dataLine, "id")!= NULL)
  16109. {
  16110. existProfileQuantity += 1;
  16111. tmpProfileQuantity += 1;
  16112. }
  16113. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16114. }
  16115. fclose(fp);
  16116. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16117. }
  16118. }
  16119. //Check TxProfile_%d.json
  16120. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16121. {
  16122. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16123. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  16124. if((access(fnametemp,F_OK))!=-1)
  16125. {
  16126. fp = fopen(fnametemp, "r");
  16127. //Check Charging Profile Count
  16128. tmpProfileQuantity = 0;
  16129. while(fscanf(fp, "%s", dataLine) != EOF)
  16130. {
  16131. if(strstr(dataLine, "id")!= NULL)
  16132. {
  16133. existProfileQuantity += 1;
  16134. tmpProfileQuantity += 1;
  16135. }
  16136. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16137. }
  16138. fclose(fp);
  16139. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16140. }
  16141. }
  16142. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  16143. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  16144. // To check total Profile quantity
  16145. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  16146. {
  16147. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16148. isProfileOverMax = TRUE;
  16149. }
  16150. else
  16151. {
  16152. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16153. isProfileOverMax = TRUE;
  16154. }
  16155. }
  16156. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  16157. }
  16158. // Profile replace or add info
  16159. if(!isLostEvseId && !isPeriodOverMax && !isProfileOverMax && !isEvseMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  16160. {
  16161. FILE *infile;
  16162. FILE *outfile;
  16163. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  16164. char rmFileCmd[128];
  16165. int tempchargingProfileIdInt;
  16166. int tempchargingProfileStackLevelInt;
  16167. int chkChar;
  16168. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  16169. {
  16170. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  16171. {
  16172. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  16173. }
  16174. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  16175. {
  16176. if(SetProfileReq.evseId==0)
  16177. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16178. else
  16179. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16180. }
  16181. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  16182. {
  16183. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16184. }
  16185. else
  16186. {
  16187. /*
  16188. * TODO:
  16189. *
  16190. */
  16191. }
  16192. infile = fopen ((char*)filename, "r");
  16193. outfile = fopen ((char*)tmpProfileName, "w");
  16194. chkChar = fgetc(infile);
  16195. rewind(infile);
  16196. if(chkChar == EOF)
  16197. {
  16198. // Profile is empty
  16199. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16200. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16201. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16202. fclose(infile);
  16203. fclose(outfile);
  16204. sprintf(rmFileCmd,"rm -f %s",filename);
  16205. system(rmFileCmd);
  16206. rename((char*)tmpProfileName, (char*)filename);
  16207. }
  16208. else
  16209. {
  16210. // Profile is not empty
  16211. int ChargingProfileAdded = FALSE;
  16212. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  16213. {
  16214. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  16215. json_object *tmpChargingProfile;
  16216. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  16217. if(!is_error(tmpChargingProfile))
  16218. {
  16219. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  16220. {
  16221. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  16222. {
  16223. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  16224. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  16225. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  16226. }
  16227. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16228. {
  16229. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  16230. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  16231. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  16232. }
  16233. }
  16234. }
  16235. json_object_put(tmpChargingProfile);
  16236. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  16237. {
  16238. if(ChargingProfileAdded == FALSE)
  16239. {
  16240. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16241. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16242. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16243. ChargingProfileAdded = TRUE;
  16244. }
  16245. }
  16246. else
  16247. {
  16248. fprintf(outfile,"%s\n",dataLine);
  16249. if(ChargingProfileAdded == FALSE)
  16250. {
  16251. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16252. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16253. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16254. ChargingProfileAdded = TRUE;
  16255. }
  16256. }
  16257. } // end of while loop
  16258. fclose(infile);
  16259. fclose(outfile);
  16260. sprintf(rmFileCmd,"rm -f %s",filename);
  16261. system(rmFileCmd);
  16262. rename((char*)tmpProfileName, (char*)filename);
  16263. }
  16264. }
  16265. sleep(1);
  16266. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  16267. result = PASS;
  16268. }
  16269. else
  16270. {
  16271. if(isLostEvseId)
  16272. DEBUG_WARN("Connector id is wrong.\n");
  16273. if(isEvseMismatch)
  16274. DEBUG_WARN("Connector id is mismatch.\n");
  16275. if(isPeriodOverMax)
  16276. DEBUG_WARN("Profile periods quantity is over spec.\n");
  16277. if(isProfileOverMax)
  16278. DEBUG_WARN("Profile quantity is over spec.\n");
  16279. if(isTransactiodIdMismatch)
  16280. DEBUG_WARN("Transaction id is mismatch.\n");
  16281. if(isInvalidLimit)
  16282. DEBUG_WARN("Limit value is invalid.\n");
  16283. if(isStackOverMax)
  16284. DEBUG_WARN("Profile stack is over spec.\n");
  16285. if(isWrongFormat)
  16286. DEBUG_WARN("Profile format is wrong.\n");
  16287. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  16288. }
  16289. }
  16290. json_object_put(SetChargingProfile);
  16291. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  16292. {
  16293. if(SetProfileReq.evseId == 0)
  16294. {
  16295. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  16296. {
  16297. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  16298. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16299. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  16300. }
  16301. }
  16302. else
  16303. {
  16304. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  16305. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16306. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  16307. }
  16308. }
  16309. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  16310. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16311. return result;
  16312. }
  16313. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  16314. {
  16315. mtrace();
  16316. int result = FAIL;
  16317. json_object *SetDisplayMessage;
  16318. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  16319. SetDisplayMessage = json_tokener_parse(payload);
  16320. if(!is_error(SetDisplayMessage))
  16321. {
  16322. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  16323. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  16324. // Required data
  16325. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  16326. {
  16327. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  16328. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  16329. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  16330. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  16331. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  16332. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  16333. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  16334. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  16335. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  16336. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  16337. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  16338. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  16339. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  16340. {
  16341. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  16342. 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")));
  16343. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  16344. 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")));
  16345. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  16346. 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")));
  16347. }
  16348. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  16349. {
  16350. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  16351. 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")));
  16352. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  16353. 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")));
  16354. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  16355. {
  16356. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  16357. 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"));
  16358. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  16359. 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"));
  16360. }
  16361. }
  16362. }
  16363. }
  16364. json_object_put(SetDisplayMessage);
  16365. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  16366. sendSetDisplayMessagesConfirmation(uuid);
  16367. // Announce CSU there is display request come from server
  16368. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  16369. return result;
  16370. }
  16371. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  16372. {
  16373. mtrace();
  16374. int result = FAIL;
  16375. json_object *SetMonitoringBase;
  16376. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  16377. SetMonitoringBase = json_tokener_parse(payload);
  16378. if(!is_error(SetMonitoringBase))
  16379. {
  16380. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  16381. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  16382. // Required data
  16383. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  16384. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  16385. }
  16386. json_object_put(SetMonitoringBase);
  16387. /*
  16388. * TODO:
  16389. * 1. Configure monitor base and response
  16390. */
  16391. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  16392. sendSetMonitoringBaseConfirmation(uuid);
  16393. return result;
  16394. }
  16395. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  16396. {
  16397. mtrace();
  16398. int result = FAIL;
  16399. json_object *SetMonitoringLevel;
  16400. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  16401. SetMonitoringLevel = json_tokener_parse(payload);
  16402. if(!is_error(SetMonitoringLevel))
  16403. {
  16404. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  16405. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  16406. // Required data
  16407. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  16408. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  16409. }
  16410. json_object_put(SetMonitoringLevel);
  16411. /*
  16412. * TODO:
  16413. * Configure monitor status and response
  16414. */
  16415. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  16416. sendSetMonitoringLevelConfirmation(uuid);
  16417. return result;
  16418. }
  16419. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  16420. {
  16421. mtrace();
  16422. int result = FAIL;
  16423. json_object *SetNetworkProfile;
  16424. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  16425. SetNetworkProfile = json_tokener_parse(payload);
  16426. if(!is_error(SetNetworkProfile))
  16427. {
  16428. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  16429. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  16430. // Required data
  16431. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  16432. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  16433. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  16434. {
  16435. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  16436. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  16437. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  16438. {
  16439. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  16440. {
  16441. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  16442. }
  16443. else
  16444. {
  16445. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16446. goto end;
  16447. }
  16448. }
  16449. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  16450. {
  16451. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  16452. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  16453. {
  16454. char protocol[10], host[128], path[512], port[10];
  16455. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  16456. if(check >= 3)
  16457. {
  16458. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  16459. DEBUG_INFO("protocol: %s\n",protocol);
  16460. DEBUG_INFO("host: %s\n",host);
  16461. DEBUG_INFO("port: %s\n",port);
  16462. DEBUG_INFO("path: %s\n",path);
  16463. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  16464. }
  16465. else
  16466. {
  16467. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16468. goto end;
  16469. }
  16470. }
  16471. else
  16472. {
  16473. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16474. goto end;
  16475. }
  16476. }
  16477. else
  16478. {
  16479. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16480. goto end;
  16481. }
  16482. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  16483. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  16484. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  16485. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  16486. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  16487. {
  16488. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  16489. 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")));
  16490. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  16491. 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")));
  16492. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  16493. 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")));
  16494. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  16495. 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")));
  16496. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  16497. 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")));
  16498. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  16499. 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")));
  16500. }
  16501. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  16502. {
  16503. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  16504. {
  16505. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  16506. 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")));
  16507. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  16508. }
  16509. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  16510. {
  16511. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  16512. 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")));
  16513. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  16514. }
  16515. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  16516. {
  16517. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  16518. 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")));
  16519. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  16520. }
  16521. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  16522. 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"));
  16523. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  16524. 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")));
  16525. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  16526. 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"));
  16527. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  16528. 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")));
  16529. }
  16530. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  16531. }
  16532. }
  16533. json_object_put(SetNetworkProfile);
  16534. /*
  16535. * TODO:
  16536. * 1. Process network configuration and response
  16537. */
  16538. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  16539. {
  16540. }
  16541. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  16542. {
  16543. }
  16544. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  16545. {
  16546. }
  16547. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  16548. {
  16549. }
  16550. else
  16551. {
  16552. }
  16553. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  16554. {
  16555. }
  16556. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  16557. {
  16558. }
  16559. else
  16560. {
  16561. }
  16562. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  16563. {
  16564. }
  16565. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  16566. {
  16567. }
  16568. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  16569. {
  16570. }
  16571. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  16572. {
  16573. }
  16574. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  16575. {
  16576. }
  16577. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  16578. {
  16579. }
  16580. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  16581. {
  16582. }
  16583. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  16584. {
  16585. }
  16586. else
  16587. {
  16588. }
  16589. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  16590. {
  16591. }
  16592. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  16593. {
  16594. }
  16595. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  16596. {
  16597. }
  16598. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  16599. {
  16600. }
  16601. else
  16602. {
  16603. }
  16604. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  16605. {
  16606. }
  16607. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  16608. {
  16609. }
  16610. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  16611. {
  16612. }
  16613. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  16614. {
  16615. }
  16616. else
  16617. {
  16618. }
  16619. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  16620. end:
  16621. sendSetNetworkProfileConfirmation(uuid);
  16622. return result;
  16623. }
  16624. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  16625. {
  16626. mtrace();
  16627. int result = FAIL;
  16628. json_object *SetVariableMonitoring;
  16629. uint8_t variableQuantity = 0;
  16630. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  16631. SetVariableMonitoring = json_tokener_parse(payload);
  16632. if(!is_error(SetVariableMonitoring))
  16633. {
  16634. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  16635. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  16636. // Required data
  16637. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  16638. {
  16639. variableQuantity++;
  16640. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  16641. {
  16642. 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"));
  16643. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  16644. }
  16645. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  16646. {
  16647. 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"));
  16648. }
  16649. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  16650. {
  16651. 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")));
  16652. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16653. }
  16654. else
  16655. {
  16656. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  16657. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16658. }
  16659. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  16660. {
  16661. 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"));
  16662. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  16663. }
  16664. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  16665. {
  16666. 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"));
  16667. }
  16668. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  16669. {
  16670. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  16671. {
  16672. 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")));
  16673. }
  16674. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  16675. {
  16676. 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")));
  16677. }
  16678. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  16679. {
  16680. 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)
  16681. {
  16682. 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"));
  16683. }
  16684. 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)
  16685. {
  16686. 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"));
  16687. }
  16688. }
  16689. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  16690. }
  16691. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  16692. {
  16693. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  16694. {
  16695. 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")));
  16696. }
  16697. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  16698. {
  16699. 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")));
  16700. }
  16701. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  16702. }
  16703. /*
  16704. * TODO
  16705. * Set Variables and save to DB
  16706. */
  16707. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  16708. }
  16709. }
  16710. json_object_put(SetVariableMonitoring);
  16711. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  16712. return result;
  16713. }
  16714. int handleSetVariablesRequest(char *uuid, char *payload)
  16715. {
  16716. mtrace();
  16717. uint8_t result = FAIL;
  16718. uint8_t isUnknownComponent = TRUE;
  16719. uint8_t isNeedReconnect = FALSE;
  16720. json_object *SetVariables;
  16721. DEBUG_INFO("handleSetVariablesRequest...\n");
  16722. SetVariables = json_tokener_parse(payload);
  16723. if(!is_error(SetVariables))
  16724. {
  16725. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  16726. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  16727. // Required data
  16728. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  16729. {
  16730. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  16731. {
  16732. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  16733. {
  16734. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  16735. {
  16736. 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")));
  16737. }
  16738. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  16739. {
  16740. 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")));
  16741. }
  16742. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  16743. {
  16744. 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)
  16745. {
  16746. 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"));
  16747. }
  16748. 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)
  16749. {
  16750. 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"));
  16751. }
  16752. }
  16753. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  16754. }
  16755. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  16756. {
  16757. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  16758. {
  16759. 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")));
  16760. }
  16761. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  16762. {
  16763. 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")));
  16764. }
  16765. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  16766. }
  16767. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  16768. {
  16769. 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")));
  16770. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  16771. }
  16772. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  16773. {
  16774. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  16775. }
  16776. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  16777. {
  16778. 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")));
  16779. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  16780. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  16781. {
  16782. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  16783. (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) &&
  16784. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  16785. (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))
  16786. {
  16787. isUnknownComponent = FALSE;
  16788. //DEBUG_INFO("Checking variable...[%s][%s], dataType: %s\n",ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType);
  16789. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  16790. {
  16791. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  16792. {
  16793. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16794. break;
  16795. }
  16796. }
  16797. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  16798. {
  16799. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  16800. {
  16801. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16802. break;
  16803. }
  16804. }
  16805. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  16806. {
  16807. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  16808. {
  16809. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16810. break;
  16811. }
  16812. }
  16813. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  16814. {
  16815. // To make sure all boolean value is in uppercase
  16816. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  16817. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  16818. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  16819. {
  16820. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  16821. }
  16822. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  16823. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  16824. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  16825. {
  16826. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  16827. }
  16828. else
  16829. {
  16830. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16831. break;
  16832. }
  16833. }
  16834. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  16835. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  16836. {
  16837. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  16838. break;
  16839. }
  16840. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  16841. {
  16842. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16843. break;
  16844. }
  16845. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  16846. {
  16847. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16848. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16849. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16850. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16851. {
  16852. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16853. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16854. if(strstr((char*)tmp, "true") != NULL)
  16855. {
  16856. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  16857. }
  16858. else
  16859. {
  16860. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  16861. }
  16862. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16863. }
  16864. else
  16865. {
  16866. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16867. break;
  16868. }
  16869. }
  16870. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  16871. {
  16872. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  16873. }
  16874. else
  16875. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16876. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  16877. {
  16878. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  16879. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16880. else
  16881. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16882. }
  16883. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  16884. {
  16885. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16886. {
  16887. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16888. }
  16889. else
  16890. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  16891. }
  16892. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  16893. {
  16894. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16895. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16896. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16897. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16898. {
  16899. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16900. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16901. }
  16902. else
  16903. {
  16904. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16905. break;
  16906. }
  16907. }
  16908. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  16909. {
  16910. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16911. {
  16912. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16913. }
  16914. else
  16915. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16916. }
  16917. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "CharingProfileRefreshInterval") != NULL))
  16918. {
  16919. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16920. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16921. else
  16922. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16923. }
  16924. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  16925. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  16926. {
  16927. isNeedReconnect = TRUE;
  16928. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16929. //SetOcppConnStatus(FALSE);
  16930. }
  16931. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  16932. {
  16933. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16934. {
  16935. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16936. }
  16937. else
  16938. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16939. }
  16940. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  16941. {
  16942. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16943. {
  16944. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16945. }
  16946. else
  16947. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16948. }
  16949. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  16950. {
  16951. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16952. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16953. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16954. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16955. {
  16956. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16957. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  16958. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16959. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16960. }
  16961. }
  16962. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  16963. {
  16964. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  16965. {
  16966. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16967. }
  16968. else
  16969. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16970. }
  16971. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  16972. {
  16973. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  16974. {
  16975. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16976. }
  16977. else
  16978. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16979. }
  16980. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  16981. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  16982. {
  16983. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  16984. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  16985. }
  16986. break;
  16987. }
  16988. else
  16989. {
  16990. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  16991. {
  16992. isUnknownComponent = FALSE;
  16993. }
  16994. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  16995. }
  16996. }
  16997. if(isUnknownComponent == TRUE)
  16998. {
  16999. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17000. }
  17001. }
  17002. }
  17003. }
  17004. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  17005. if(isNeedReconnect)
  17006. {
  17007. SetOcppConnStatus(FALSE);
  17008. }
  17009. }
  17010. json_object_put(SetVariables);
  17011. return result;
  17012. }
  17013. int handleTriggerMessageRequest(char *uuid, char *payload)
  17014. {
  17015. mtrace();
  17016. int result = FAIL;
  17017. int evseIdIsNULL = FALSE;
  17018. //int connectorIdIsNULL = FALSE;
  17019. int evseIdInt =0;
  17020. //int connectorIdInt =0;
  17021. json_object *TriggerMessage;
  17022. DEBUG_INFO("handleTriggerMessageRequest\n");
  17023. TriggerMessage = json_tokener_parse(payload);
  17024. if(!is_error(TriggerMessage))
  17025. {
  17026. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  17027. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  17028. // Required data
  17029. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  17030. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  17031. // Optional data
  17032. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  17033. {
  17034. // Required data
  17035. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  17036. {
  17037. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  17038. evseIdInt = ShmOCPP20Data->TriggerMessage.evse.id;
  17039. }
  17040. else
  17041. evseIdIsNULL = TRUE;
  17042. // Optional data
  17043. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  17044. {
  17045. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  17046. //connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  17047. }
  17048. //else
  17049. //connectorIdIsNULL = TRUE;
  17050. }
  17051. else
  17052. evseIdIsNULL = TRUE;
  17053. }
  17054. json_object_put(TriggerMessage);
  17055. if((evseIdIsNULL == TRUE) || ((evseIdIsNULL == FALSE) && ((evseIdInt > 0) && (evseIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  17056. {
  17057. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  17058. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  17059. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  17060. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  17061. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  17062. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  17063. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  17064. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  17065. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  17066. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  17067. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  17068. {
  17069. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  17070. sendTriggerMessageConfirmation(uuid);
  17071. return TRUE;
  17072. }
  17073. else
  17074. {
  17075. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  17076. sendTriggerMessageConfirmation(uuid);
  17077. }
  17078. }
  17079. else if(evseIdIsNULL == FALSE && ((evseIdInt <= 0) || (evseIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  17080. {
  17081. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17082. sendTriggerMessageConfirmation(uuid);
  17083. return TRUE;
  17084. }
  17085. //==========================
  17086. // Trigger message
  17087. //==========================
  17088. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  17089. {
  17090. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  17091. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  17092. {
  17093. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  17094. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17095. }
  17096. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17097. }
  17098. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  17099. {
  17100. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  17101. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  17102. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  17103. }
  17104. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  17105. {
  17106. if(server_sign)
  17107. {
  17108. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17109. sendTriggerMessageConfirmation(uuid);
  17110. return TRUE;
  17111. }
  17112. else
  17113. {
  17114. if(DB_updateBootType(BootReasonEnumType_Triggered))
  17115. server_sign = FALSE;
  17116. }
  17117. }
  17118. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  17119. {
  17120. refreshStartTimer(&clientTime.Heartbeat);
  17121. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  17122. }
  17123. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  17124. {
  17125. if(evseIdIsNULL == FALSE)
  17126. {
  17127. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17128. {
  17129. cpinitateMsg.bits[evseIdInt-1].TriggerMeterValueReq = ON;
  17130. }
  17131. }
  17132. else
  17133. {
  17134. for(int idx=0;idx< gunTotalNumber;idx++)
  17135. {
  17136. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  17137. }
  17138. }
  17139. }
  17140. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  17141. {
  17142. if(evseIdIsNULL == FALSE)
  17143. {
  17144. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17145. {
  17146. cpinitateMsg.bits[evseIdInt-1].TriggerStatusNotificationReq = ON;
  17147. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  17148. }
  17149. }
  17150. else
  17151. {
  17152. for(int idx=0;idx< gunTotalNumber;idx++)
  17153. {
  17154. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  17155. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  17156. }
  17157. }
  17158. }
  17159. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  17160. {
  17161. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17162. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17163. {
  17164. 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\" &");
  17165. }
  17166. }
  17167. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  17168. {
  17169. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17170. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17171. {
  17172. 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\" &");
  17173. }
  17174. }
  17175. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  17176. {
  17177. if(evseIdIsNULL == FALSE)
  17178. {
  17179. if((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber))
  17180. {
  17181. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  17182. cpinitateMsg.bits[evseIdInt -1].TriggerTransactionEventReq = ON;
  17183. }
  17184. }
  17185. else
  17186. {
  17187. for(int idx=0;idx< gunTotalNumber;idx++)
  17188. {
  17189. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  17190. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  17191. }
  17192. }
  17193. }
  17194. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  17195. {
  17196. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17197. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17198. {
  17199. 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\" &");
  17200. }
  17201. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17202. {
  17203. 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\" &");
  17204. }
  17205. }
  17206. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  17207. {
  17208. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  17209. }
  17210. return result;
  17211. }
  17212. int handleUnlockConnectorRequest(char *uuid, char *payload)
  17213. {
  17214. mtrace();
  17215. int result = FAIL;
  17216. int evseIdInt =0;
  17217. int tempIndex = 0;
  17218. json_object *UnlockConnector;
  17219. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  17220. UnlockConnector = json_tokener_parse(payload);
  17221. if(!is_error(UnlockConnector))
  17222. {
  17223. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  17224. {
  17225. evseIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  17226. ShmOCPP20Data->UnlockConnector[(evseIdInt>0?evseIdInt-1:0)].evseId = evseIdInt;
  17227. //it should not be array!!
  17228. }
  17229. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  17230. {
  17231. if(json_object_get_int(json_object_object_get(UnlockConnector, "connectorId")) != 1)
  17232. {
  17233. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17234. goto end;
  17235. }
  17236. }
  17237. }
  17238. json_object_put(UnlockConnector);
  17239. DEBUG_INFO("Unlock evseIdInt = %d\n",evseIdInt);
  17240. if(gunTotalNumber == 0)
  17241. {
  17242. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17243. goto end;
  17244. }
  17245. else if((evseIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (evseIdInt <= 0))
  17246. {
  17247. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17248. goto end;
  17249. }
  17250. else
  17251. {
  17252. memset(&ShmOCPP20Data->UnlockConnector[evseIdInt-1], 0, sizeof(struct UnlockConnector_20));
  17253. memcpy(&ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid));
  17254. //check Transaction active
  17255. if(gunType[evseIdInt-1] == GUN_TYPE_CHAdeMO)
  17256. {
  17257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17258. {
  17259. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17260. }
  17261. else
  17262. {
  17263. tempIndex = evseIdInt -1;
  17264. }
  17265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17266. {
  17267. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  17268. {
  17269. //stop Transaction
  17270. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17271. }
  17272. }
  17273. }
  17274. else if(gunType[evseIdInt-1] == GUN_TYPE_CCS)
  17275. {
  17276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17277. {
  17278. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17279. }
  17280. else
  17281. {
  17282. tempIndex = evseIdInt -1;
  17283. }
  17284. for (int index = 0; index < CCS_QUANTITY; index++)
  17285. {
  17286. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  17287. {
  17288. //stop Transaction
  17289. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17290. }
  17291. }
  17292. }
  17293. else if(gunType[evseIdInt-1] == GUN_TYPE_GBT)
  17294. {
  17295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17296. {
  17297. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17298. }
  17299. else
  17300. {
  17301. tempIndex = evseIdInt -1;
  17302. }
  17303. for (int index = 0; index < GB_QUANTITY; index++)
  17304. {
  17305. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  17306. {
  17307. //stop Transaction
  17308. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17309. }
  17310. }
  17311. }
  17312. else if(gunType[evseIdInt-1] == GUN_TYPE_DO)
  17313. {
  17314. tempIndex = evseIdInt -1;
  17315. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17316. {
  17317. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  17318. {
  17319. //stop Transaction
  17320. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17321. }
  17322. }
  17323. }
  17324. else
  17325. {
  17326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17327. {
  17328. tempIndex = 2;
  17329. }
  17330. else
  17331. {
  17332. tempIndex = evseIdInt-1;
  17333. }
  17334. for (int index = 0; index < AC_QUANTITY; index++)
  17335. {
  17336. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  17337. {
  17338. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17339. }
  17340. }
  17341. }
  17342. ShmOCPP20Data->UnlockConnector[evseIdInt-1].connectorId = evseIdInt;
  17343. strcpy((char *)ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid);
  17344. result = TRUE;
  17345. return result;
  17346. }
  17347. end:
  17348. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorConf = ON;
  17349. return result;
  17350. }
  17351. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  17352. {
  17353. mtrace();
  17354. int result = FAIL;
  17355. json_object *UnpublishFirmware;
  17356. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  17357. UnpublishFirmware = json_tokener_parse(payload);
  17358. if(!is_error(UnpublishFirmware))
  17359. {
  17360. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  17361. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  17362. // Required data
  17363. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  17364. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  17365. }
  17366. json_object_put(UnpublishFirmware);
  17367. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  17368. /*
  17369. * TODO:
  17370. * 1. Check unpublished status
  17371. */
  17372. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  17373. sendUnpublishFirmwareConfirmation(uuid);
  17374. return result;
  17375. }
  17376. static char UpdateFirmwarepayloadData[512]={0};
  17377. void *UpdateFirmwareProcess(void *data)
  17378. {
  17379. pthread_detach(pthread_self());
  17380. mtrace();
  17381. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  17382. int port=0;
  17383. int isSuccess = 0;
  17384. char ftpbuf[1024];
  17385. char temp[1024];
  17386. char * pch;
  17387. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  17388. json_object *UpdateFirmware;
  17389. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  17390. if(!is_error(UpdateFirmware))
  17391. {
  17392. // Required data
  17393. if(json_object_object_get(UpdateFirmware, "requestId"))
  17394. {
  17395. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  17396. }
  17397. if(json_object_object_get(UpdateFirmware, "firmware"))
  17398. {
  17399. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  17400. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  17401. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  17402. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  17403. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  17404. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  17405. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  17406. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  17407. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  17408. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  17409. }
  17410. // Optional data
  17411. if(json_object_object_get(UpdateFirmware, "retries"))
  17412. {
  17413. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  17414. }
  17415. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  17416. {
  17417. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  17418. }
  17419. }
  17420. json_object_put(UpdateFirmware);
  17421. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  17422. memset(path, 0, ARRAY_SIZE(path));
  17423. // Wait retrieveData
  17424. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  17425. {
  17426. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17427. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  17428. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17429. do
  17430. {
  17431. sleep(1);
  17432. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  17433. }
  17434. system("rm -f /mnt/*");
  17435. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  17436. {
  17437. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  17438. sprintf(ftppath,"/%s", path);
  17439. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  17440. DEBUG_INFO("protocol: %s\n",protocol);
  17441. DEBUG_INFO("host: %s\n",host);
  17442. DEBUG_INFO("path: %s\n",path);
  17443. DEBUG_INFO("ftppath: %s\n",ftppath);
  17444. int ftppathlen=strlen(ftppath);
  17445. int i=1;
  17446. char filenametemp[50];
  17447. while(i < ftppathlen)
  17448. {
  17449. int len=ftppathlen-i;
  17450. if(ftppath[len]== 47) // '/' ascll code: 47
  17451. {
  17452. DEBUG_INFO("compare '/' all right\n");
  17453. break;
  17454. }
  17455. i=i+1;
  17456. }
  17457. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  17458. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  17459. filenametemp[i+1] = 0;
  17460. do
  17461. {
  17462. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17463. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17464. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17465. sleep(3);
  17466. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17467. if(!isSuccess)
  17468. {
  17469. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17470. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17471. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17472. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17473. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17474. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17475. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17476. }
  17477. else
  17478. {
  17479. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17480. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17481. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17482. }
  17483. ShmOCPP20Data->UpdateFirmware.retries--;
  17484. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17485. }
  17486. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  17487. {
  17488. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17489. memset(temp, 0, ARRAY_SIZE(temp));
  17490. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17491. int ftppathlen=strlen(ftpbuf);
  17492. int i=1;
  17493. char filenametemp[50];
  17494. while(i < ftppathlen)
  17495. {
  17496. int len=ftppathlen-i;
  17497. if(ftpbuf[len]== 47) // '/' ascll code: 47
  17498. {
  17499. DEBUG_INFO(" compare '/' all right\n");
  17500. break;
  17501. }
  17502. i=i+1;
  17503. }
  17504. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  17505. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  17506. filenametemp[i+1] = 0;
  17507. strncpy(temp, ftpbuf, ftppathlen-i+1);
  17508. pch=strchr(temp,'@');
  17509. if(pch==NULL)
  17510. {
  17511. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17512. protocol, host, &port, path);
  17513. strcpy(user,"anonymous");
  17514. strcpy(password,"");
  17515. }
  17516. else
  17517. {
  17518. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  17519. protocol, user, password, host, &port, path);
  17520. }
  17521. sscanf(host,"%[^/]%s",host1, path1);
  17522. sprintf(ftppath,"%s", path1);
  17523. if(port == 0)
  17524. {
  17525. port = 21;
  17526. }
  17527. do
  17528. {
  17529. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17530. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17531. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17532. sleep(3);
  17533. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17534. if(!isSuccess)
  17535. {
  17536. //BulldogUtil.sleepMs(interval*1000);
  17537. DEBUG_INFO("Update firmware request and download file fail.\n");
  17538. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17539. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17540. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17541. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17542. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17543. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17544. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17545. }
  17546. else
  17547. {
  17548. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17549. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17550. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17551. }
  17552. ShmOCPP20Data->UpdateFirmware.retries--;
  17553. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17554. }
  17555. else
  17556. {
  17557. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17558. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17559. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17560. sleep(1);
  17561. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17562. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17563. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17564. }
  17565. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  17566. interLock.isUpdateFirmwareGoing = OFF;
  17567. pthread_exit(NULL);
  17568. }
  17569. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  17570. {
  17571. mtrace();
  17572. int result = FAIL;
  17573. pthread_t t;
  17574. sendUpdateFirmwareConfirmation(uuid);
  17575. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  17576. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  17577. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  17578. if(!interLock.isUpdateFirmwareGoing)
  17579. {
  17580. interLock.isUpdateFirmwareGoing = ON;
  17581. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  17582. sleep(1);
  17583. }
  17584. else
  17585. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  17586. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  17587. return result;
  17588. }
  17589. int handleUnknownRequest(char *uuid, char *payload)
  17590. {
  17591. mtrace();
  17592. int result = FAIL;
  17593. DEBUG_INFO("handleUnknownRequest...\n");
  17594. sendUnknownConfirmation(uuid);
  17595. result = PASS;
  17596. return result;
  17597. }
  17598. //==========================================
  17599. // Handle server response routine
  17600. //==========================================
  17601. void handleAuthorizeResponse(char *payload, int gun_index)
  17602. {
  17603. mtrace();
  17604. DEBUG_INFO("handleAuthorizeResponse...\n");
  17605. json_object *Authorize;
  17606. Authorize = json_tokener_parse(payload);
  17607. if(!is_error(Authorize))
  17608. {
  17609. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  17610. {
  17611. // Required data
  17612. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  17613. // Optional data
  17614. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  17615. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  17616. else
  17617. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  17618. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  17619. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  17620. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  17621. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  17622. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  17623. {
  17624. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  17625. {
  17626. 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));
  17627. }
  17628. }
  17629. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  17630. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  17631. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  17632. {
  17633. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  17634. 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")));
  17635. else
  17636. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  17637. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  17638. 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")));
  17639. }
  17640. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  17641. {
  17642. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  17643. 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")));
  17644. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  17645. 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")));
  17646. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  17647. 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")));
  17648. }
  17649. }
  17650. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  17651. {
  17652. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  17653. }
  17654. }
  17655. json_object_put(Authorize);
  17656. //Update idTag information to authorization cache if supported
  17657. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  17658. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  17659. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  17660. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  17661. {
  17662. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  17663. }
  17664. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  17665. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  17666. authorizeRetryTimes = 0;
  17667. }
  17668. void handleBootNotificationResponse(char *payload, int gun_index)
  17669. {
  17670. mtrace();
  17671. char statusStr[12]={0};
  17672. char currentTimeStr[30]={0};
  17673. int intervalInt = 0;
  17674. DEBUG_INFO("handleBootNotificationResponse...\n");
  17675. json_object *BootNotification;
  17676. BootNotification = json_tokener_parse(payload);
  17677. if(!is_error(BootNotification))
  17678. {
  17679. // Required data
  17680. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  17681. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  17682. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  17683. }
  17684. json_object_put(BootNotification);
  17685. DEBUG_INFO("statusStr: %s\n", statusStr);
  17686. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  17687. BootNotificationInterval = intervalInt;
  17688. //write back to ShmOCPP20Data->BootNotification
  17689. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  17690. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  17691. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  17692. {
  17693. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  17694. {
  17695. //Do nothing because the value is out of range.
  17696. }
  17697. else
  17698. {
  17699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  17700. HeartBeatWaitTime = intervalInt;
  17701. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  17702. }
  17703. server_sign = TRUE;
  17704. server_pending =FALSE;
  17705. DB_updateBootType(BootReasonEnumType_PowerUp);
  17706. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  17707. }
  17708. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  17709. {
  17710. server_pending = TRUE;
  17711. }
  17712. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  17713. srand(time(NULL));
  17714. refreshStartTimer(&clientTime.Heartbeat);
  17715. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  17716. SetOcppConnStatus(TRUE);
  17717. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  17718. }
  17719. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  17720. {
  17721. mtrace();
  17722. json_object *ClearedChargingLimit;
  17723. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  17724. ClearedChargingLimit = json_tokener_parse(payload);
  17725. if(!is_error(ClearedChargingLimit))
  17726. {
  17727. // Required data
  17728. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  17729. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  17730. }
  17731. json_object_put(ClearedChargingLimit);
  17732. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  17733. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  17734. }
  17735. void handleDataTransferResponse(char *payload, int gun_index)
  17736. {
  17737. mtrace();
  17738. json_object *DataTrans;
  17739. DEBUG_INFO("handleDataTransferResponse...\n");
  17740. DataTrans = json_tokener_parse(payload);
  17741. if(!is_error(DataTrans))
  17742. {
  17743. // Required data
  17744. if(json_object_object_get(DataTrans,"status") != NULL)
  17745. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  17746. // Optional data
  17747. if(json_object_object_get(DataTrans,"data") != NULL)
  17748. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  17749. }
  17750. json_object_put(DataTrans);
  17751. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  17752. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  17753. }
  17754. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17755. {
  17756. mtrace();
  17757. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  17758. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  17759. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  17760. }
  17761. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  17762. {
  17763. mtrace();
  17764. json_object *Get15118EVCertificate;
  17765. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  17766. Get15118EVCertificate = json_tokener_parse(payload);
  17767. if(!is_error(Get15118EVCertificate))
  17768. {
  17769. // Required data
  17770. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  17771. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  17772. // Optional data
  17773. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  17774. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  17775. }
  17776. json_object_put(Get15118EVCertificate);
  17777. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  17778. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  17779. }
  17780. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  17781. {
  17782. mtrace();
  17783. json_object *GetCertificateStatus;
  17784. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  17785. GetCertificateStatus = json_tokener_parse(payload);
  17786. if(!is_error(GetCertificateStatus))
  17787. {
  17788. // Required data
  17789. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  17790. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  17791. // Optional data
  17792. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  17793. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  17794. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  17795. {
  17796. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  17797. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  17798. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  17799. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  17800. }
  17801. }
  17802. json_object_put(GetCertificateStatus);
  17803. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  17804. {
  17805. /*
  17806. * TODO:
  17807. * 1. If get certificate response accepted process something here
  17808. */
  17809. }
  17810. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  17811. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  17812. }
  17813. void handleHeartbeatResponse(char *payload, int gun_index)
  17814. {
  17815. mtrace();
  17816. DEBUG_INFO("handleHeartbeatResponse...\n");
  17817. json_object *Heartbeat;
  17818. Heartbeat = json_tokener_parse(payload);
  17819. if(!is_error(Heartbeat))
  17820. {
  17821. // Required data
  17822. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  17823. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  17824. }
  17825. json_object_put(Heartbeat);
  17826. if(FirstHeartBeat == OFF)
  17827. {
  17828. FirstHeartBeat = ON;
  17829. DEBUG_INFO("FirstHeartBeat \n");
  17830. }
  17831. HeartBeatWithNOResponse = 0;
  17832. refreshStartTimer(&clientTime.Heartbeat);
  17833. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  17834. }
  17835. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  17836. {
  17837. mtrace();
  17838. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  17839. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  17840. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  17841. }
  17842. void handleMeterValuesResponse(char *payload, int gun_index)
  17843. {
  17844. mtrace();
  17845. DEBUG_INFO("handleMeterValuesResponse...\n");
  17846. isQueueSendable = ON;
  17847. }
  17848. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  17849. {
  17850. mtrace();
  17851. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  17852. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  17853. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  17854. }
  17855. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  17856. {
  17857. mtrace();
  17858. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  17859. }
  17860. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  17861. {
  17862. mtrace();
  17863. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  17864. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  17865. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  17866. }
  17867. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  17868. {
  17869. mtrace();
  17870. json_object *NotifyEVChargingNeeds;
  17871. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  17872. NotifyEVChargingNeeds = json_tokener_parse(payload);
  17873. if(!is_error(NotifyEVChargingNeeds))
  17874. {
  17875. // Required data
  17876. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  17877. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  17878. }
  17879. json_object_put(NotifyEVChargingNeeds);
  17880. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  17881. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  17882. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  17883. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  17884. }
  17885. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  17886. {
  17887. mtrace();
  17888. json_object *NotifyEVChargingSchedule;
  17889. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  17890. NotifyEVChargingSchedule = json_tokener_parse(payload);
  17891. if(!is_error(NotifyEVChargingSchedule))
  17892. {
  17893. // Required data
  17894. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  17895. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  17896. }
  17897. json_object_put(NotifyEVChargingSchedule);
  17898. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  17899. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  17900. }
  17901. void handleNotifyEventResponse(char *payload, int gun_index)
  17902. {
  17903. mtrace();
  17904. DEBUG_INFO("handleNotifyEventResponse...\n");
  17905. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  17906. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  17907. }
  17908. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  17909. {
  17910. mtrace();
  17911. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  17912. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  17913. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  17914. }
  17915. void handleNotifyReportResponse(char *payload, int gun_index)
  17916. {
  17917. mtrace();
  17918. DEBUG_INFO("handleNotifyReportResponse...\n");
  17919. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  17920. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  17921. }
  17922. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17923. {
  17924. mtrace();
  17925. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  17926. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  17927. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  17928. }
  17929. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  17930. {
  17931. mtrace();
  17932. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  17933. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  17934. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  17935. }
  17936. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  17937. {
  17938. mtrace();
  17939. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  17940. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  17941. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  17942. }
  17943. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  17944. {
  17945. mtrace();
  17946. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  17947. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  17948. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  17949. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  17950. }
  17951. void handleSignCertificateResponse(char *payload, int gun_index)
  17952. {
  17953. mtrace();
  17954. json_object *SignCertificate;
  17955. DEBUG_INFO("handleSignCertificateResponse...\n");
  17956. SignCertificate = json_tokener_parse(payload);
  17957. if(!is_error(SignCertificate))
  17958. {
  17959. // Required data
  17960. if(json_object_object_get(SignCertificate,"status") != NULL)
  17961. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  17962. // Optional data
  17963. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  17964. {
  17965. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  17966. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  17967. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  17968. }
  17969. }
  17970. json_object_put(SignCertificate);
  17971. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  17972. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  17973. }
  17974. void handleStatusNotificationResponse(char *payload, int gun_index)
  17975. {
  17976. mtrace();
  17977. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  17978. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  17979. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  17980. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  17981. }
  17982. void handleTransactionEventResponse(char *payload, int gun_index)
  17983. {
  17984. mtrace();
  17985. json_object *TransactionEven;
  17986. DEBUG_INFO("handleTransactionEventResponse...\n");
  17987. TransactionEven = json_tokener_parse(payload);
  17988. if(!is_error(TransactionEven))
  17989. {
  17990. // Required data
  17991. // Optional data
  17992. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  17993. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  17994. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  17995. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  17996. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  17997. {
  17998. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  17999. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  18000. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18001. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  18002. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  18003. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  18004. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  18005. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  18006. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  18007. {
  18008. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18009. 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")));
  18010. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18011. 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")));
  18012. }
  18013. }
  18014. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  18015. {
  18016. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  18017. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  18018. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  18019. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  18020. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  18021. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  18022. }
  18023. }
  18024. json_object_put(TransactionEven);
  18025. isQueueSendable = ON;
  18026. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  18027. }
  18028. //==========================================
  18029. // Handle Error routine
  18030. //==========================================
  18031. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  18032. {
  18033. mtrace();
  18034. #ifdef SystemLogMessage
  18035. DEBUG_INFO("errorCode: %s\n", errorCode);
  18036. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  18037. DEBUG_INFO("errorDetails: %s\n", payload);
  18038. #endif
  18039. }
  18040. //===============================================
  18041. // Common routine
  18042. //===============================================
  18043. int initialConfigurationTable(void)
  18044. {
  18045. DEBUG_INFO("initialConfigurationTable...\n");
  18046. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  18047. DB_variableIsCreate();
  18048. DB_variableLoadFromDb();
  18049. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  18050. {
  18051. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  18052. DB_variableClear();
  18053. DB_variableIsCreate();
  18054. DB_variableLoadFromDb();
  18055. }
  18056. DB_getNetworkProfileFromDb();
  18057. return 0;
  18058. }
  18059. int TransactionMessageAttemptsGet(void)
  18060. {
  18061. return TransactionMessageAttemptsValue;
  18062. }
  18063. int FirstHeartBeatResponse(void)
  18064. {
  18065. return FirstHeartBeat;
  18066. }
  18067. int TransactionMessageRetryIntervalGet(void)
  18068. {
  18069. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18070. }
  18071. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18072. {
  18073. int result = TRUE;
  18074. char rmFileCmd[100]={0};
  18075. char FilePath[100]={0};
  18076. char ftpbuf[200];
  18077. int systemresult;
  18078. sprintf(FilePath,"/mnt/%s",filename);
  18079. system("ping 8.8.8.8 &");
  18080. if((access(FilePath,F_OK))!=-1)
  18081. {
  18082. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18083. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18084. system(rmFileCmd);
  18085. }
  18086. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18087. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18088. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18089. systemresult = system(ftpbuf);
  18090. if(systemresult != 0)
  18091. {
  18092. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  18093. result = FALSE;
  18094. }
  18095. system("pkill ping");
  18096. return result;
  18097. }
  18098. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18099. {
  18100. int result = TRUE;
  18101. char rmFileCmd[100]={0};
  18102. char FilePath[100]={0};
  18103. char ftpbuf[200];
  18104. int systemresult;
  18105. sprintf(FilePath,"/mnt/%s",filename);
  18106. system("ping 8.8.8.8 &");
  18107. if((access(FilePath,F_OK))!=-1)
  18108. {
  18109. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18110. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18111. system(rmFileCmd);
  18112. }
  18113. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18114. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18115. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18116. systemresult = system(ftpbuf);
  18117. if(systemresult != 0)
  18118. {
  18119. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18120. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18121. systemresult = system(ftpbuf);
  18122. if(systemresult != 0)
  18123. {
  18124. DEBUG_WARN("FTP download fail!\n");
  18125. result = FALSE;
  18126. }
  18127. }
  18128. system("pkill ping");
  18129. return result;
  18130. }
  18131. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18132. {
  18133. char rmFileCmd[100]={0};
  18134. char FilePath[100]={0};
  18135. char buf[512];
  18136. int systemresult = 0;
  18137. //DEBUG_INFO("filename=%s\n",filename);
  18138. //DEBUG_INFO("url=%s\n",url);
  18139. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18140. if((access(FilePath,F_OK))!=-1)
  18141. {
  18142. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18143. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18144. system(rmFileCmd);
  18145. }
  18146. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18147. if(fp == NULL)
  18148. {
  18149. DEBUG_INFO("log is NULL\n");
  18150. return FALSE;
  18151. }
  18152. else
  18153. {
  18154. fprintf(fp, "%s\n", url);
  18155. fprintf(fp, "%s\n", filename);
  18156. fclose(fp);
  18157. }
  18158. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18159. if(phpFP == NULL)
  18160. {
  18161. DEBUG_INFO("PHP upload fail.\n");
  18162. return FALSE;
  18163. }
  18164. else
  18165. {
  18166. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18167. {
  18168. if(strstr(buf, "result") != NULL)
  18169. {
  18170. sscanf(buf, "result: %d", &systemresult);
  18171. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18172. }
  18173. }
  18174. pclose(phpFP);
  18175. }
  18176. if(systemresult != 1)
  18177. {
  18178. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18179. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18180. if(phpFP == NULL)
  18181. {
  18182. DEBUG_WARN("PHP PUT upload fail.\n");
  18183. return FALSE;
  18184. }
  18185. else
  18186. {
  18187. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18188. {
  18189. if(strstr(buf, "result") != NULL)
  18190. {
  18191. sscanf(buf, "result: %d", &systemresult);
  18192. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18193. }
  18194. }
  18195. pclose(phpFP);
  18196. }
  18197. }
  18198. if(systemresult != 1)
  18199. {
  18200. DEBUG_WARN("PHP PUT upload fail.\n");
  18201. return FALSE;
  18202. }
  18203. return TRUE;
  18204. }
  18205. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18206. {
  18207. int result = FALSE;
  18208. char ftpbuf[200];
  18209. int systemresult;
  18210. /*
  18211. // Domaind name transfer to IP address
  18212. struct hostent* server;
  18213. char *IPbuffer;
  18214. server = gethostbyname(location);
  18215. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18216. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18217. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18218. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18219. systemresult = system(ftpbuf);
  18220. if(systemresult != 0)
  18221. {
  18222. DEBUG_INFO("ftpput error!\n");
  18223. }
  18224. else
  18225. {
  18226. result = TRUE;
  18227. DEBUG_INFO("ftpput OK!\n");
  18228. }
  18229. return result;
  18230. }
  18231. //=========================================
  18232. // Routine
  18233. //=========================================
  18234. int GetOcppServerURL()
  18235. {
  18236. int result = FALSE;
  18237. struct yuarel url;
  18238. char urlStr[512];
  18239. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18240. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18241. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18242. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  18243. {
  18244. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  18245. if(yuarel_parse(&url, urlStr) != -1)
  18246. {
  18247. sprintf(OcppProtocol, "%s", url.scheme);
  18248. sprintf(OcppHost, "%s", url.host);
  18249. if(url.path == NULL)
  18250. OcppTempPath[0] = '\0';
  18251. else
  18252. sprintf(OcppTempPath, "%s", url.path);
  18253. if(url.port == 0)
  18254. {
  18255. if(strcmp(OcppProtocol, "wss") == 0)
  18256. OcppPort = 443;
  18257. else
  18258. OcppPort = 80;
  18259. }
  18260. else
  18261. OcppPort = url.port;
  18262. result = TRUE;
  18263. }
  18264. }
  18265. else
  18266. {
  18267. strcpy(OcppHost,"");
  18268. }
  18269. return result;
  18270. }
  18271. int GetOcppPath()
  18272. {
  18273. int result = FALSE;
  18274. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18275. {
  18276. if(OcppTempPath == NULL)
  18277. {
  18278. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18279. }
  18280. else
  18281. {
  18282. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18283. }
  18284. result = TRUE;
  18285. }
  18286. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  18287. {
  18288. if(OcppTempPath == NULL)
  18289. {
  18290. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  18291. }
  18292. else
  18293. {
  18294. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  18295. }
  18296. result = TRUE;
  18297. }
  18298. else
  18299. {
  18300. strcpy(OcppPath,"");
  18301. }
  18302. return result;
  18303. }
  18304. int GetOcppPort()
  18305. {
  18306. return OcppPort;
  18307. }
  18308. int GetOcppConnStatus(void)
  18309. {
  18310. return ShmOCPP20Data->OcppConnStatus;
  18311. }
  18312. void SetOcppConnStatus(uint8_t status)
  18313. {
  18314. ShmOCPP20Data->OcppConnStatus = status;
  18315. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18316. }
  18317. int GetHeartBeatWithNOResponse(void)
  18318. {
  18319. return HeartBeatWithNOResponse;
  18320. }
  18321. void SetHeartBeatWithNOResponse(void)
  18322. {
  18323. HeartBeatWithNOResponse = 0;
  18324. }
  18325. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18326. void storeTempStopTransaction(int gun_index)
  18327. {
  18328. char TempStopTransaction[256];
  18329. //char message[1024*20]={0};
  18330. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  18331. char guid[37]={0};
  18332. json_object *TransactionEvent = json_object_new_object();
  18333. json_object *transactionInfo = json_object_new_object();
  18334. json_object *idToken = json_object_new_object();
  18335. json_object *evse = json_object_new_object();
  18336. json_object *meterValues = json_object_new_array();
  18337. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18338. DEBUG_INFO("storeTempStopTransaction...\n");
  18339. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  18340. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  18341. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  18342. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  18343. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  18344. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  18345. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  18346. // Message
  18347. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  18348. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  18349. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  18350. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  18351. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  18352. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  18353. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  18354. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  18355. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  18356. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  18357. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  18358. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  18359. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  18360. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  18361. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  18362. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  18363. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  18364. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  18365. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  18366. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  18367. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  18368. {
  18369. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  18370. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  18371. json_object_object_add(TransactionEvent, "idToken", idToken);
  18372. }
  18373. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  18374. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  18375. json_object_object_add(TransactionEvent, "evse", evse);
  18376. meterValueBufferQuery(gun_index, meterValues);
  18377. if(json_object_array_length(meterValues) > 0)
  18378. {
  18379. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  18380. }
  18381. random_uuid(guid);
  18382. sprintf(queuedata,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  18383. , guid
  18384. , "TransactionEvent"
  18385. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  18386. json_object_put(TransactionEvent);
  18387. // open file for writing
  18388. FILE *outfile;
  18389. outfile = fopen (TempStopTransaction, "w+");
  18390. //DEBUG_INFO("data = %s\n", queuedata);
  18391. fputs(queuedata, outfile);
  18392. fputs("\n", outfile);
  18393. fclose (outfile);
  18394. }
  18395. void checkTempStopTransaction(int gun_index)
  18396. {
  18397. FILE *fptr1;
  18398. char ch;
  18399. char str[QUEUE_MESSAGE_LENGTH]={0};
  18400. char guid[37]={0};
  18401. char tempdata[65]={0};
  18402. char TempStopTransaction[256];
  18403. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18404. fptr1 = fopen(TempStopTransaction, "r");
  18405. if (!fptr1)
  18406. {
  18407. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  18408. return ;
  18409. }
  18410. ch=fgetc(fptr1);
  18411. rewind(fptr1);
  18412. if(ch!=EOF)
  18413. {
  18414. // copy all contents to the temporary file except the specific line
  18415. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18416. {
  18417. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18418. if(str[0]=='\0')
  18419. {
  18420. break;
  18421. }
  18422. strncpy(guid, str+4, 36); //copy guid
  18423. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  18424. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18425. {
  18426. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18427. }
  18428. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18429. memset(str,0,ARRAY_SIZE(str));
  18430. }
  18431. }
  18432. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18433. fclose(fptr1);
  18434. remove(TempStopTransaction); // remove the original file
  18435. }
  18436. int GetWebSocketPingInterval(void)
  18437. {
  18438. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  18439. }
  18440. int GetServerSign(void)
  18441. {
  18442. return server_sign;
  18443. }
  18444. uint8_t GetOcppSecurityProfile()
  18445. {
  18446. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  18447. }
  18448. void MergeCertificates()
  18449. {
  18450. char cmdBuf[2048]={0};
  18451. if(access(ROOTCA_CS,F_OK) != -1)
  18452. {
  18453. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  18454. }
  18455. else
  18456. {
  18457. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  18458. }
  18459. system(cmdBuf);
  18460. }
  18461. void GetOcppChargerBoxId(uint8_t *data)
  18462. {
  18463. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18464. }
  18465. void GetOcppSecurityPassword(uint8_t *data)
  18466. {
  18467. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  18468. }
  18469. void SetServerSign(int value)
  18470. {
  18471. server_sign = value;
  18472. }
  18473. int GetBootNotificationInterval(void)
  18474. {
  18475. return BootNotificationInterval;
  18476. }
  18477. int GetInternetConn(void)
  18478. {
  18479. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18480. }
  18481. int GetBackendConnectionTimeout(void)
  18482. {
  18483. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18484. }
  18485. int isConnectorInitMode(int gun_index)
  18486. {
  18487. int tempIndex = 0;
  18488. int result = TRUE;
  18489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18491. {
  18492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18493. {
  18494. tempIndex = ((gun_index==2) ? 1: 0);
  18495. }
  18496. else
  18497. {
  18498. tempIndex = gun_index;
  18499. }
  18500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18501. {
  18502. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18503. {
  18504. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18505. } //end of the same index
  18506. }//end of for CHAdeMO_QUANTITY
  18507. }
  18508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18509. {
  18510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18511. {
  18512. tempIndex = ((gun_index==2) ? 1: 0);
  18513. }
  18514. else
  18515. {
  18516. tempIndex = gun_index;
  18517. }
  18518. for (int index = 0; index < CCS_QUANTITY; index++)
  18519. {
  18520. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18521. {
  18522. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18523. } //end of the same index
  18524. } // end of for CCS_QUANTITY
  18525. }
  18526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18527. {
  18528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18529. {
  18530. tempIndex = ((gun_index==2) ? 1: 0);
  18531. }
  18532. else
  18533. {
  18534. tempIndex = gun_index;
  18535. }
  18536. for (int index = 0; index < GB_QUANTITY; index++)
  18537. {
  18538. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18539. {
  18540. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18541. } //end of the same index
  18542. } // end of for GB_QUANTITY
  18543. }
  18544. else if(gunType[gun_index] == GUN_TYPE_DO)
  18545. {
  18546. tempIndex = gun_index;
  18547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18548. {
  18549. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18550. {
  18551. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18552. } //end of the same index
  18553. }
  18554. }
  18555. else
  18556. {
  18557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18558. {
  18559. tempIndex = 2;
  18560. }
  18561. else
  18562. {
  18563. tempIndex = gun_index;
  18564. }
  18565. for (int index = 0; index < AC_QUANTITY; index++)
  18566. {
  18567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18568. {
  18569. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18570. }//end of the same index
  18571. }//end of for AC_QUANTITY
  18572. }
  18573. return result;
  18574. }
  18575. void refreshProcDogTimer()
  18576. {
  18577. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  18578. }
  18579. void InitialSystemValue(void)
  18580. {
  18581. localversion=0;
  18582. BootNotificationInterval = 10;
  18583. authorizeRetryTimes = 0;
  18584. GunStatusInterval = 10;
  18585. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  18586. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  18587. //Heart Beat
  18588. HeartBeatWithNOResponse = 0;
  18589. HeartBeatCountPerHour = 0;
  18590. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  18591. if(HeartBeatWaitTime == 0)
  18592. FirstHeartBeat = TRUE;
  18593. else
  18594. FirstHeartBeat = FALSE;
  18595. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  18596. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  18597. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18598. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18599. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18600. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18601. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18602. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18603. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18604. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18605. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18606. //Status && ConnectorPlugIn Setting
  18607. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18608. {
  18609. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18610. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18611. }
  18612. for (int index = 0; index < CCS_QUANTITY; index++)
  18613. {
  18614. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18615. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18616. }
  18617. for (int index = 0; index < GB_QUANTITY; index++)
  18618. {
  18619. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18620. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18621. }
  18622. for (int index = 0; index < AC_QUANTITY; index++)
  18623. {
  18624. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18625. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18626. }
  18627. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18628. {
  18629. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18630. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18631. }
  18632. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18633. {
  18634. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18635. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18636. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  18637. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18638. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  18639. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  18640. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  18641. }
  18642. refreshStartTimer(&clientTime.Heartbeat);
  18643. sleep(1);
  18644. }
  18645. void LWS_Send(char *str)
  18646. {
  18647. //=====================================================
  18648. // Check InternetConn 0: disconnected, 1: connected
  18649. //====================================================
  18650. if(GetOcppConnStatus() == 0)
  18651. {
  18652. DEBUG_INFO("offline now !!!\n");
  18653. return;
  18654. }
  18655. // Only disable isWebsocketSendable operation initiated by charger
  18656. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18657. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18658. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18659. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18660. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18661. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18662. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18663. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18664. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18665. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18666. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18667. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18668. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18669. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18670. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18671. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18672. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18673. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18674. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18675. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18676. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18677. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18678. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18679. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18680. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18681. {
  18682. isWebsocketSendable = OFF;
  18683. }
  18684. pthread_mutex_lock(&lock_send);
  18685. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18686. sprintf((char *)SendBuffer, "%s", str);
  18687. SendBufLen = strlen(str);
  18688. pthread_mutex_unlock(&lock_send);
  18689. lws_callback_on_writable(wsi_client);
  18690. //lws_service(context, 0);
  18691. //sleep(1);
  18692. }
  18693. void LWS_SendNow(char *str)
  18694. {
  18695. //=====================================================
  18696. // Check InternetConn 0: disconnected, 1: connected
  18697. //====================================================
  18698. if(GetOcppConnStatus() == 0)
  18699. {
  18700. DEBUG_INFO("offline now !!!\n");
  18701. return;
  18702. }
  18703. // Only disable isWebsocketSendable operation initiated by charger
  18704. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18705. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18706. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18707. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18708. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18709. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18710. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18711. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18712. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18713. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18714. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18715. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18716. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18717. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18718. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18719. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18720. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18721. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18722. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18723. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18724. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18725. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18726. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18727. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18728. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18729. {
  18730. isWebsocketSendable = OFF;
  18731. }
  18732. pthread_mutex_lock(&lock_send);
  18733. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18734. sprintf((char *)SendBuffer, "%s", str);
  18735. SendBufLen = strlen(str);
  18736. pthread_mutex_unlock(&lock_send);
  18737. lws_callback_on_writable(wsi_client);
  18738. lws_service(context, 0);
  18739. //sleep(1);
  18740. }